github.com/google/go-github/v70@v70.0.0/github/admin_stats.go (about) 1 // Copyright 2017 The go-github AUTHORS. All rights reserved. 2 // 3 // Use of this source code is governed by a BSD-style 4 // license that can be found in the LICENSE file. 5 6 package github 7 8 import ( 9 "context" 10 ) 11 12 // AdminStats represents a variety of stats of a GitHub Enterprise 13 // installation. 14 type AdminStats struct { 15 Issues *IssueStats `json:"issues,omitempty"` 16 Hooks *HookStats `json:"hooks,omitempty"` 17 Milestones *MilestoneStats `json:"milestones,omitempty"` 18 Orgs *OrgStats `json:"orgs,omitempty"` 19 Comments *CommentStats `json:"comments,omitempty"` 20 Pages *PageStats `json:"pages,omitempty"` 21 Users *UserStats `json:"users,omitempty"` 22 Gists *GistStats `json:"gists,omitempty"` 23 Pulls *PullStats `json:"pulls,omitempty"` 24 Repos *RepoStats `json:"repos,omitempty"` 25 } 26 27 func (s AdminStats) String() string { 28 return Stringify(s) 29 } 30 31 // IssueStats represents the number of total, open and closed issues. 32 type IssueStats struct { 33 TotalIssues *int `json:"total_issues,omitempty"` 34 OpenIssues *int `json:"open_issues,omitempty"` 35 ClosedIssues *int `json:"closed_issues,omitempty"` 36 } 37 38 func (s IssueStats) String() string { 39 return Stringify(s) 40 } 41 42 // HookStats represents the number of total, active and inactive hooks. 43 type HookStats struct { 44 TotalHooks *int `json:"total_hooks,omitempty"` 45 ActiveHooks *int `json:"active_hooks,omitempty"` 46 InactiveHooks *int `json:"inactive_hooks,omitempty"` 47 } 48 49 func (s HookStats) String() string { 50 return Stringify(s) 51 } 52 53 // MilestoneStats represents the number of total, open and close milestones. 54 type MilestoneStats struct { 55 TotalMilestones *int `json:"total_milestones,omitempty"` 56 OpenMilestones *int `json:"open_milestones,omitempty"` 57 ClosedMilestones *int `json:"closed_milestones,omitempty"` 58 } 59 60 func (s MilestoneStats) String() string { 61 return Stringify(s) 62 } 63 64 // OrgStats represents the number of total, disabled organizations and the team 65 // and team member count. 66 type OrgStats struct { 67 TotalOrgs *int `json:"total_orgs,omitempty"` 68 DisabledOrgs *int `json:"disabled_orgs,omitempty"` 69 TotalTeams *int `json:"total_teams,omitempty"` 70 TotalTeamMembers *int `json:"total_team_members,omitempty"` 71 } 72 73 func (s OrgStats) String() string { 74 return Stringify(s) 75 } 76 77 // CommentStats represents the number of total comments on commits, gists, issues 78 // and pull requests. 79 type CommentStats struct { 80 TotalCommitComments *int `json:"total_commit_comments,omitempty"` 81 TotalGistComments *int `json:"total_gist_comments,omitempty"` 82 TotalIssueComments *int `json:"total_issue_comments,omitempty"` 83 TotalPullRequestComments *int `json:"total_pull_request_comments,omitempty"` 84 } 85 86 func (s CommentStats) String() string { 87 return Stringify(s) 88 } 89 90 // PageStats represents the total number of github pages. 91 type PageStats struct { 92 TotalPages *int `json:"total_pages,omitempty"` 93 } 94 95 func (s PageStats) String() string { 96 return Stringify(s) 97 } 98 99 // UserStats represents the number of total, admin and suspended users. 100 type UserStats struct { 101 TotalUsers *int `json:"total_users,omitempty"` 102 AdminUsers *int `json:"admin_users,omitempty"` 103 SuspendedUsers *int `json:"suspended_users,omitempty"` 104 } 105 106 func (s UserStats) String() string { 107 return Stringify(s) 108 } 109 110 // GistStats represents the number of total, private and public gists. 111 type GistStats struct { 112 TotalGists *int `json:"total_gists,omitempty"` 113 PrivateGists *int `json:"private_gists,omitempty"` 114 PublicGists *int `json:"public_gists,omitempty"` 115 } 116 117 func (s GistStats) String() string { 118 return Stringify(s) 119 } 120 121 // PullStats represents the number of total, merged, mergeable and unmergeable 122 // pull-requests. 123 type PullStats struct { 124 TotalPulls *int `json:"total_pulls,omitempty"` 125 MergedPulls *int `json:"merged_pulls,omitempty"` 126 MergeablePulls *int `json:"mergeable_pulls,omitempty"` 127 UnmergeablePulls *int `json:"unmergeable_pulls,omitempty"` 128 } 129 130 func (s PullStats) String() string { 131 return Stringify(s) 132 } 133 134 // RepoStats represents the number of total, root, fork, organization repositories 135 // together with the total number of pushes and wikis. 136 type RepoStats struct { 137 TotalRepos *int `json:"total_repos,omitempty"` 138 RootRepos *int `json:"root_repos,omitempty"` 139 ForkRepos *int `json:"fork_repos,omitempty"` 140 OrgRepos *int `json:"org_repos,omitempty"` 141 TotalPushes *int `json:"total_pushes,omitempty"` 142 TotalWikis *int `json:"total_wikis,omitempty"` 143 } 144 145 func (s RepoStats) String() string { 146 return Stringify(s) 147 } 148 149 // GetAdminStats returns a variety of metrics about a GitHub Enterprise 150 // installation. 151 // 152 // Please note that this is only available to site administrators, 153 // otherwise it will error with a 404 not found (instead of 401 or 403). 154 // 155 // GitHub API docs: https://docs.github.com/enterprise-server@3.15/rest/enterprise-admin/admin-stats#get-all-statistics 156 // 157 //meta:operation GET /enterprise/stats/all 158 func (s *AdminService) GetAdminStats(ctx context.Context) (*AdminStats, *Response, error) { 159 u := "enterprise/stats/all" 160 req, err := s.client.NewRequest("GET", u, nil) 161 if err != nil { 162 return nil, nil, err 163 } 164 165 m := new(AdminStats) 166 resp, err := s.client.Do(ctx, req, m) 167 if err != nil { 168 return nil, resp, err 169 } 170 171 return m, resp, nil 172 }