issues_timeline.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. // Copyright 2016 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. // Timeline represents an event that occurred around an Issue or Pull Request.
  12. //
  13. // It is similar to an IssueEvent but may contain more information.
  14. // GitHub API docs: https://developer.github.com/v3/issues/timeline/
  15. type Timeline struct {
  16. ID *int64 `json:"id,omitempty"`
  17. URL *string `json:"url,omitempty"`
  18. CommitURL *string `json:"commit_url,omitempty"`
  19. // The User object that generated the event.
  20. Actor *User `json:"actor,omitempty"`
  21. // Event identifies the actual type of Event that occurred. Possible values
  22. // are:
  23. //
  24. // assigned
  25. // The issue was assigned to the assignee.
  26. //
  27. // closed
  28. // The issue was closed by the actor. When the commit_id is present, it
  29. // identifies the commit that closed the issue using "closes / fixes #NN"
  30. // syntax.
  31. //
  32. // commented
  33. // A comment was added to the issue.
  34. //
  35. // committed
  36. // A commit was added to the pull request's 'HEAD' branch. Only provided
  37. // for pull requests.
  38. //
  39. // cross-referenced
  40. // The issue was referenced from another issue. The 'source' attribute
  41. // contains the 'id', 'actor', and 'url' of the reference's source.
  42. //
  43. // demilestoned
  44. // The issue was removed from a milestone.
  45. //
  46. // head_ref_deleted
  47. // The pull request's branch was deleted.
  48. //
  49. // head_ref_restored
  50. // The pull request's branch was restored.
  51. //
  52. // labeled
  53. // A label was added to the issue.
  54. //
  55. // locked
  56. // The issue was locked by the actor.
  57. //
  58. // mentioned
  59. // The actor was @mentioned in an issue body.
  60. //
  61. // merged
  62. // The issue was merged by the actor. The 'commit_id' attribute is the
  63. // SHA1 of the HEAD commit that was merged.
  64. //
  65. // milestoned
  66. // The issue was added to a milestone.
  67. //
  68. // referenced
  69. // The issue was referenced from a commit message. The 'commit_id'
  70. // attribute is the commit SHA1 of where that happened.
  71. //
  72. // renamed
  73. // The issue title was changed.
  74. //
  75. // reopened
  76. // The issue was reopened by the actor.
  77. //
  78. // subscribed
  79. // The actor subscribed to receive notifications for an issue.
  80. //
  81. // unassigned
  82. // The assignee was unassigned from the issue.
  83. //
  84. // unlabeled
  85. // A label was removed from the issue.
  86. //
  87. // unlocked
  88. // The issue was unlocked by the actor.
  89. //
  90. // unsubscribed
  91. // The actor unsubscribed to stop receiving notifications for an issue.
  92. //
  93. Event *string `json:"event,omitempty"`
  94. // The string SHA of a commit that referenced this Issue or Pull Request.
  95. CommitID *string `json:"commit_id,omitempty"`
  96. // The timestamp indicating when the event occurred.
  97. CreatedAt *time.Time `json:"created_at,omitempty"`
  98. // The Label object including `name` and `color` attributes. Only provided for
  99. // 'labeled' and 'unlabeled' events.
  100. Label *Label `json:"label,omitempty"`
  101. // The User object which was assigned to (or unassigned from) this Issue or
  102. // Pull Request. Only provided for 'assigned' and 'unassigned' events.
  103. Assignee *User `json:"assignee,omitempty"`
  104. // The Milestone object including a 'title' attribute.
  105. // Only provided for 'milestoned' and 'demilestoned' events.
  106. Milestone *Milestone `json:"milestone,omitempty"`
  107. // The 'id', 'actor', and 'url' for the source of a reference from another issue.
  108. // Only provided for 'cross-referenced' events.
  109. Source *Source `json:"source,omitempty"`
  110. // An object containing rename details including 'from' and 'to' attributes.
  111. // Only provided for 'renamed' events.
  112. Rename *Rename `json:"rename,omitempty"`
  113. }
  114. // Source represents a reference's source.
  115. type Source struct {
  116. ID *int64 `json:"id,omitempty"`
  117. URL *string `json:"url,omitempty"`
  118. Actor *User `json:"actor,omitempty"`
  119. }
  120. // ListIssueTimeline lists events for the specified issue.
  121. //
  122. // GitHub API docs: https://developer.github.com/v3/issues/timeline/#list-events-for-an-issue
  123. func (s *IssuesService) ListIssueTimeline(ctx context.Context, owner, repo string, number int, opt *ListOptions) ([]*Timeline, *Response, error) {
  124. u := fmt.Sprintf("repos/%v/%v/issues/%v/timeline", owner, repo, number)
  125. u, err := addOptions(u, opt)
  126. if err != nil {
  127. return nil, nil, err
  128. }
  129. req, err := s.client.NewRequest("GET", u, nil)
  130. if err != nil {
  131. return nil, nil, err
  132. }
  133. // TODO: remove custom Accept header when this API fully launches.
  134. req.Header.Set("Accept", mediaTypeTimelinePreview)
  135. var events []*Timeline
  136. resp, err := s.client.Do(ctx, req, &events)
  137. return events, resp, err
  138. }