本站源代码
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.

216 lines
5.8KB

  1. // Copyright 2013 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. // ListEvents drinks from the firehose of all public events across GitHub.
  11. //
  12. // GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events
  13. func (s *ActivityService) ListEvents(ctx context.Context, opt *ListOptions) ([]*Event, *Response, error) {
  14. u, err := addOptions("events", opt)
  15. if err != nil {
  16. return nil, nil, err
  17. }
  18. req, err := s.client.NewRequest("GET", u, nil)
  19. if err != nil {
  20. return nil, nil, err
  21. }
  22. var events []*Event
  23. resp, err := s.client.Do(ctx, req, &events)
  24. if err != nil {
  25. return nil, resp, err
  26. }
  27. return events, resp, nil
  28. }
  29. // ListRepositoryEvents lists events for a repository.
  30. //
  31. // GitHub API docs: https://developer.github.com/v3/activity/events/#list-repository-events
  32. func (s *ActivityService) ListRepositoryEvents(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Event, *Response, error) {
  33. u := fmt.Sprintf("repos/%v/%v/events", owner, repo)
  34. u, err := addOptions(u, opt)
  35. if err != nil {
  36. return nil, nil, err
  37. }
  38. req, err := s.client.NewRequest("GET", u, nil)
  39. if err != nil {
  40. return nil, nil, err
  41. }
  42. var events []*Event
  43. resp, err := s.client.Do(ctx, req, &events)
  44. if err != nil {
  45. return nil, resp, err
  46. }
  47. return events, resp, nil
  48. }
  49. // ListIssueEventsForRepository lists issue events for a repository.
  50. //
  51. // GitHub API docs: https://developer.github.com/v3/activity/events/#list-issue-events-for-a-repository
  52. func (s *ActivityService) ListIssueEventsForRepository(ctx context.Context, owner, repo string, opt *ListOptions) ([]*IssueEvent, *Response, error) {
  53. u := fmt.Sprintf("repos/%v/%v/issues/events", owner, repo)
  54. u, err := addOptions(u, opt)
  55. if err != nil {
  56. return nil, nil, err
  57. }
  58. req, err := s.client.NewRequest("GET", u, nil)
  59. if err != nil {
  60. return nil, nil, err
  61. }
  62. var events []*IssueEvent
  63. resp, err := s.client.Do(ctx, req, &events)
  64. if err != nil {
  65. return nil, resp, err
  66. }
  67. return events, resp, nil
  68. }
  69. // ListEventsForRepoNetwork lists public events for a network of repositories.
  70. //
  71. // GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events-for-a-network-of-repositories
  72. func (s *ActivityService) ListEventsForRepoNetwork(ctx context.Context, owner, repo string, opt *ListOptions) ([]*Event, *Response, error) {
  73. u := fmt.Sprintf("networks/%v/%v/events", owner, repo)
  74. u, err := addOptions(u, opt)
  75. if err != nil {
  76. return nil, nil, err
  77. }
  78. req, err := s.client.NewRequest("GET", u, nil)
  79. if err != nil {
  80. return nil, nil, err
  81. }
  82. var events []*Event
  83. resp, err := s.client.Do(ctx, req, &events)
  84. if err != nil {
  85. return nil, resp, err
  86. }
  87. return events, resp, nil
  88. }
  89. // ListEventsForOrganization lists public events for an organization.
  90. //
  91. // GitHub API docs: https://developer.github.com/v3/activity/events/#list-public-events-for-an-organization
  92. func (s *ActivityService) ListEventsForOrganization(ctx context.Context, org string, opt *ListOptions) ([]*Event, *Response, error) {
  93. u := fmt.Sprintf("orgs/%v/events", org)
  94. u, err := addOptions(u, opt)
  95. if err != nil {
  96. return nil, nil, err
  97. }
  98. req, err := s.client.NewRequest("GET", u, nil)
  99. if err != nil {
  100. return nil, nil, err
  101. }
  102. var events []*Event
  103. resp, err := s.client.Do(ctx, req, &events)
  104. if err != nil {
  105. return nil, resp, err
  106. }
  107. return events, resp, nil
  108. }
  109. // ListEventsPerformedByUser lists the events performed by a user. If publicOnly is
  110. // true, only public events will be returned.
  111. //
  112. // GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-performed-by-a-user
  113. func (s *ActivityService) ListEventsPerformedByUser(ctx context.Context, user string, publicOnly bool, opt *ListOptions) ([]*Event, *Response, error) {
  114. var u string
  115. if publicOnly {
  116. u = fmt.Sprintf("users/%v/events/public", user)
  117. } else {
  118. u = fmt.Sprintf("users/%v/events", user)
  119. }
  120. u, err := addOptions(u, opt)
  121. if err != nil {
  122. return nil, nil, err
  123. }
  124. req, err := s.client.NewRequest("GET", u, nil)
  125. if err != nil {
  126. return nil, nil, err
  127. }
  128. var events []*Event
  129. resp, err := s.client.Do(ctx, req, &events)
  130. if err != nil {
  131. return nil, resp, err
  132. }
  133. return events, resp, nil
  134. }
  135. // ListEventsReceivedByUser lists the events received by a user. If publicOnly is
  136. // true, only public events will be returned.
  137. //
  138. // GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-that-a-user-has-received
  139. func (s *ActivityService) ListEventsReceivedByUser(ctx context.Context, user string, publicOnly bool, opt *ListOptions) ([]*Event, *Response, error) {
  140. var u string
  141. if publicOnly {
  142. u = fmt.Sprintf("users/%v/received_events/public", user)
  143. } else {
  144. u = fmt.Sprintf("users/%v/received_events", user)
  145. }
  146. u, err := addOptions(u, opt)
  147. if err != nil {
  148. return nil, nil, err
  149. }
  150. req, err := s.client.NewRequest("GET", u, nil)
  151. if err != nil {
  152. return nil, nil, err
  153. }
  154. var events []*Event
  155. resp, err := s.client.Do(ctx, req, &events)
  156. if err != nil {
  157. return nil, resp, err
  158. }
  159. return events, resp, nil
  160. }
  161. // ListUserEventsForOrganization provides the user’s organization dashboard. You
  162. // must be authenticated as the user to view this.
  163. //
  164. // GitHub API docs: https://developer.github.com/v3/activity/events/#list-events-for-an-organization
  165. func (s *ActivityService) ListUserEventsForOrganization(ctx context.Context, org, user string, opt *ListOptions) ([]*Event, *Response, error) {
  166. u := fmt.Sprintf("users/%v/events/orgs/%v", user, org)
  167. u, err := addOptions(u, opt)
  168. if err != nil {
  169. return nil, nil, err
  170. }
  171. req, err := s.client.NewRequest("GET", u, nil)
  172. if err != nil {
  173. return nil, nil, err
  174. }
  175. var events []*Event
  176. resp, err := s.client.Do(ctx, req, &events)
  177. if err != nil {
  178. return nil, resp, err
  179. }
  180. return events, resp, nil
  181. }
上海开阖软件有限公司 沪ICP备12045867号-1