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.

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