issues_events.go 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. // Copyright 2014 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. "time"
  10. )
  11. // IssueEvent represents an event that occurred around an Issue or Pull Request.
  12. type IssueEvent struct {
  13. ID *int64 `json:"id,omitempty"`
  14. URL *string `json:"url,omitempty"`
  15. // The User that generated this event.
  16. Actor *User `json:"actor,omitempty"`
  17. // Event identifies the actual type of Event that occurred. Possible
  18. // values are:
  19. //
  20. // closed
  21. // The Actor closed the issue.
  22. // If the issue was closed by commit message, CommitID holds the SHA1 hash of the commit.
  23. //
  24. // merged
  25. // The Actor merged into master a branch containing a commit mentioning the issue.
  26. // CommitID holds the SHA1 of the merge commit.
  27. //
  28. // referenced
  29. // The Actor committed to master a commit mentioning the issue in its commit message.
  30. // CommitID holds the SHA1 of the commit.
  31. //
  32. // reopened, locked, unlocked
  33. // The Actor did that to the issue.
  34. //
  35. // renamed
  36. // The Actor changed the issue title from Rename.From to Rename.To.
  37. //
  38. // mentioned
  39. // Someone unspecified @mentioned the Actor [sic] in an issue comment body.
  40. //
  41. // assigned, unassigned
  42. // The Assigner assigned the issue to or removed the assignment from the Assignee.
  43. //
  44. // labeled, unlabeled
  45. // The Actor added or removed the Label from the issue.
  46. //
  47. // milestoned, demilestoned
  48. // The Actor added or removed the issue from the Milestone.
  49. //
  50. // subscribed, unsubscribed
  51. // The Actor subscribed to or unsubscribed from notifications for an issue.
  52. //
  53. // head_ref_deleted, head_ref_restored
  54. // The pull request’s branch was deleted or restored.
  55. //
  56. Event *string `json:"event,omitempty"`
  57. CreatedAt *time.Time `json:"created_at,omitempty"`
  58. Issue *Issue `json:"issue,omitempty"`
  59. // Only present on certain events; see above.
  60. Assignee *User `json:"assignee,omitempty"`
  61. Assigner *User `json:"assigner,omitempty"`
  62. CommitID *string `json:"commit_id,omitempty"`
  63. Milestone *Milestone `json:"milestone,omitempty"`
  64. Label *Label `json:"label,omitempty"`
  65. Rename *Rename `json:"rename,omitempty"`
  66. }
  67. // ListIssueEvents lists events for the specified issue.
  68. //
  69. // GitHub API docs: https://developer.github.com/v3/issues/events/#list-events-for-an-issue
  70. func (s *IssuesService) ListIssueEvents(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*IssueEvent, *Response, error) {
  71. u := fmt.Sprintf("repos/%v/%v/issues/%v/events", owner, repo, number)
  72. u, err := addOptions(u, opt)
  73. if err != nil {
  74. return nil, nil, err
  75. }
  76. req, err := s.client.NewRequest("GET", u, nil)
  77. if err != nil {
  78. return nil, nil, err
  79. }
  80. var events []*IssueEvent
  81. resp, err := s.client.Do(ctx, req, &events)
  82. if err != nil {
  83. return nil, resp, err
  84. }
  85. return events, resp, nil
  86. }
  87. // ListRepositoryEvents lists events for the specified repository.
  88. //
  89. // GitHub API docs: https://developer.github.com/v3/issues/events/#list-events-for-a-repository
  90. func (s *IssuesService) ListRepositoryEvents(ctx context.Context, owner, repo string, opt *ListOptions) ([]*IssueEvent, *Response, error) {
  91. u := fmt.Sprintf("repos/%v/%v/issues/events", owner, repo)
  92. u, err := addOptions(u, opt)
  93. if err != nil {
  94. return nil, nil, err
  95. }
  96. req, err := s.client.NewRequest("GET", u, nil)
  97. if err != nil {
  98. return nil, nil, err
  99. }
  100. var events []*IssueEvent
  101. resp, err := s.client.Do(ctx, req, &events)
  102. if err != nil {
  103. return nil, resp, err
  104. }
  105. return events, resp, nil
  106. }
  107. // GetEvent returns the specified issue event.
  108. //
  109. // GitHub API docs: https://developer.github.com/v3/issues/events/#get-a-single-event
  110. func (s *IssuesService) GetEvent(ctx context.Context, owner, repo string, id int64) (*IssueEvent, *Response, error) {
  111. u := fmt.Sprintf("repos/%v/%v/issues/events/%v", owner, repo, id)
  112. req, err := s.client.NewRequest("GET", u, nil)
  113. if err != nil {
  114. return nil, nil, err
  115. }
  116. event := new(IssueEvent)
  117. resp, err := s.client.Do(ctx, req, event)
  118. if err != nil {
  119. return nil, resp, err
  120. }
  121. return event, resp, nil
  122. }
  123. // Rename contains details for 'renamed' events.
  124. type Rename struct {
  125. From *string `json:"from,omitempty"`
  126. To *string `json:"to,omitempty"`
  127. }
  128. func (r Rename) String() string {
  129. return Stringify(r)
  130. }