本站源代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
5.1KB

  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. package github
  6. import (
  7. "context"
  8. "fmt"
  9. )
  10. // AdminStats represents a variety of stats of a Github Enterprise
  11. // installation.
  12. type AdminStats struct {
  13. Issues *IssueStats `json:"issues,omitempty"`
  14. Hooks *HookStats `json:"hooks,omitempty"`
  15. Milestones *MilestoneStats `json:"milestones,omitempty"`
  16. Orgs *OrgStats `json:"orgs,omitempty"`
  17. Comments *CommentStats `json:"comments,omitempty"`
  18. Pages *PageStats `json:"pages,omitempty"`
  19. Users *UserStats `json:"users,omitempty"`
  20. Gists *GistStats `json:"gists,omitempty"`
  21. Pulls *PullStats `json:"pulls,omitempty"`
  22. Repos *RepoStats `json:"repos,omitempty"`
  23. }
  24. func (s AdminStats) String() string {
  25. return Stringify(s)
  26. }
  27. // IssueStats represents the number of total, open and closed issues.
  28. type IssueStats struct {
  29. TotalIssues *int `json:"total_issues,omitempty"`
  30. OpenIssues *int `json:"open_issues,omitempty"`
  31. ClosedIssues *int `json:"closed_issues,omitempty"`
  32. }
  33. func (s IssueStats) String() string {
  34. return Stringify(s)
  35. }
  36. // HookStats represents the number of total, active and inactive hooks.
  37. type HookStats struct {
  38. TotalHooks *int `json:"total_hooks,omitempty"`
  39. ActiveHooks *int `json:"active_hooks,omitempty"`
  40. InactiveHooks *int `json:"inactive_hooks,omitempty"`
  41. }
  42. func (s HookStats) String() string {
  43. return Stringify(s)
  44. }
  45. // MilestoneStats represents the number of total, open and close milestones.
  46. type MilestoneStats struct {
  47. TotalMilestones *int `json:"total_milestones,omitempty"`
  48. OpenMilestones *int `json:"open_milestones,omitempty"`
  49. ClosedMilestones *int `json:"closed_milestones,omitempty"`
  50. }
  51. func (s MilestoneStats) String() string {
  52. return Stringify(s)
  53. }
  54. // OrgStats represents the number of total, disabled organizations and the team
  55. // and team member count.
  56. type OrgStats struct {
  57. TotalOrgs *int `json:"total_orgs,omitempty"`
  58. DisabledOrgs *int `json:"disabled_orgs,omitempty"`
  59. TotalTeams *int `json:"total_teams,omitempty"`
  60. TotalTeamMembers *int `json:"total_team_members,omitempty"`
  61. }
  62. func (s OrgStats) String() string {
  63. return Stringify(s)
  64. }
  65. // CommentStats represents the number of total comments on commits, gists, issues
  66. // and pull requests.
  67. type CommentStats struct {
  68. TotalCommitComments *int `json:"total_commit_comments,omitempty"`
  69. TotalGistComments *int `json:"total_gist_comments,omitempty"`
  70. TotalIssueComments *int `json:"total_issue_comments,omitempty"`
  71. TotalPullRequestComments *int `json:"total_pull_request_comments,omitempty"`
  72. }
  73. func (s CommentStats) String() string {
  74. return Stringify(s)
  75. }
  76. // PageStats represents the total number of github pages.
  77. type PageStats struct {
  78. TotalPages *int `json:"total_pages,omitempty"`
  79. }
  80. func (s PageStats) String() string {
  81. return Stringify(s)
  82. }
  83. // UserStats represents the number of total, admin and suspended users.
  84. type UserStats struct {
  85. TotalUsers *int `json:"total_users,omitempty"`
  86. AdminUsers *int `json:"admin_users,omitempty"`
  87. SuspendedUsers *int `json:"suspended_users,omitempty"`
  88. }
  89. func (s UserStats) String() string {
  90. return Stringify(s)
  91. }
  92. // GistStats represents the number of total, private and public gists.
  93. type GistStats struct {
  94. TotalGists *int `json:"total_gists,omitempty"`
  95. PrivateGists *int `json:"private_gists,omitempty"`
  96. PublicGists *int `json:"public_gists,omitempty"`
  97. }
  98. func (s GistStats) String() string {
  99. return Stringify(s)
  100. }
  101. // PullStats represents the number of total, merged, mergable and unmergeable
  102. // pull-requests.
  103. type PullStats struct {
  104. TotalPulls *int `json:"total_pulls,omitempty"`
  105. MergedPulls *int `json:"merged_pulls,omitempty"`
  106. MergablePulls *int `json:"mergeable_pulls,omitempty"`
  107. UnmergablePulls *int `json:"unmergeable_pulls,omitempty"`
  108. }
  109. func (s PullStats) String() string {
  110. return Stringify(s)
  111. }
  112. // RepoStats represents the number of total, root, fork, organization repositories
  113. // together with the total number of pushes and wikis.
  114. type RepoStats struct {
  115. TotalRepos *int `json:"total_repos,omitempty"`
  116. RootRepos *int `json:"root_repos,omitempty"`
  117. ForkRepos *int `json:"fork_repos,omitempty"`
  118. OrgRepos *int `json:"org_repos,omitempty"`
  119. TotalPushes *int `json:"total_pushes,omitempty"`
  120. TotalWikis *int `json:"total_wikis,omitempty"`
  121. }
  122. func (s RepoStats) String() string {
  123. return Stringify(s)
  124. }
  125. // GetAdminStats returns a variety of metrics about a Github Enterprise
  126. // installation.
  127. //
  128. // Please note that this is only available to site administrators,
  129. // otherwise it will error with a 404 not found (instead of 401 or 403).
  130. //
  131. // GitHub API docs: https://developer.github.com/v3/enterprise-admin/admin_stats/
  132. func (s *AdminService) GetAdminStats(ctx context.Context) (*AdminStats, *Response, error) {
  133. u := fmt.Sprintf("enterprise/stats/all")
  134. req, err := s.client.NewRequest("GET", u, nil)
  135. if err != nil {
  136. return nil, nil, err
  137. }
  138. m := new(AdminStats)
  139. resp, err := s.client.Do(ctx, req, m)
  140. if err != nil {
  141. return nil, resp, err
  142. }
  143. return m, resp, nil
  144. }
上海开阖软件有限公司 沪ICP备12045867号-1