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

155 lines
5.0KB

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