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 6 package github 7 8 import ( 9 "context" 10 "fmt" 11 "strings" 12 "time" 13 ) 14 15 // Timeline represents an event that occurred around an Issue or Pull Request. 16 // 17 // It is similar to an IssueEvent but may contain more information. 18 // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/events/issue-event-types 19 type Timeline struct { 20 ID *int64 `json:"id,omitempty"` 21 URL *string `json:"url,omitempty"` 22 CommitURL *string `json:"commit_url,omitempty"` 23 24 // The User object that generated the event. 25 Actor *User `json:"actor,omitempty"` 26 27 // The person who commented on the issue. 28 User *User `json:"user,omitempty"` 29 30 // The person who authored the commit. 31 Author *CommitAuthor `json:"author,omitempty"` 32 // The person who committed the commit on behalf of the author. 33 Committer *CommitAuthor `json:"committer,omitempty"` 34 // The SHA of the commit in the pull request. 35 SHA *string `json:"sha,omitempty"` 36 // The commit message. 37 Message *string `json:"message,omitempty"` 38 39 // Event identifies the actual type of Event that occurred. Possible values 40 // are: 41 // 42 // assigned 43 // The issue was assigned to the assignee. 44 // 45 // closed 46 // The issue was closed by the actor. When the commit_id is present, it 47 // identifies the commit that closed the issue using "closes / fixes #NN" 48 // syntax. 49 // 50 // commented 51 // A comment was added to the issue. 52 // 53 // committed 54 // A commit was added to the pull request's 'HEAD' branch. Only provided 55 // for pull requests. 56 // 57 // cross-referenced 58 // The issue was referenced from another issue. The 'source' attribute 59 // contains the 'id', 'actor', and 'url' of the reference's source. 60 // 61 // demilestoned 62 // The issue was removed from a milestone. 63 // 64 // head_ref_deleted 65 // The pull request's branch was deleted. 66 // 67 // head_ref_restored 68 // The pull request's branch was restored. 69 // 70 // labeled 71 // A label was added to the issue. 72 // 73 // locked 74 // The issue was locked by the actor. 75 // 76 // mentioned 77 // The actor was @mentioned in an issue body. 78 // 79 // merged 80 // The issue was merged by the actor. The 'commit_id' attribute is the 81 // SHA1 of the HEAD commit that was merged. 82 // 83 // milestoned 84 // The issue was added to a milestone. 85 // 86 // referenced 87 // The issue was referenced from a commit message. The 'commit_id' 88 // attribute is the commit SHA1 of where that happened. 89 // 90 // renamed 91 // The issue title was changed. 92 // 93 // reopened 94 // The issue was reopened by the actor. 95 // 96 // reviewed 97 // The pull request was reviewed. 98 // 99 // subscribed 100 // The actor subscribed to receive notifications for an issue. 101 // 102 // unassigned 103 // The assignee was unassigned from the issue. 104 // 105 // unlabeled 106 // A label was removed from the issue. 107 // 108 // unlocked 109 // The issue was unlocked by the actor. 110 // 111 // unsubscribed 112 // The actor unsubscribed to stop receiving notifications for an issue. 113 // 114 Event *string `json:"event,omitempty"` 115 116 // The string SHA of a commit that referenced this Issue or Pull Request. 117 CommitID *string `json:"commit_id,omitempty"` 118 // The timestamp indicating when the event occurred. 119 CreatedAt *time.Time `json:"created_at,omitempty"` 120 // The Label object including `name` and `color` attributes. Only provided for 121 // 'labeled' and 'unlabeled' events. 122 Label *Label `json:"label,omitempty"` 123 // The User object which was assigned to (or unassigned from) this Issue or 124 // Pull Request. Only provided for 'assigned' and 'unassigned' events. 125 Assignee *User `json:"assignee,omitempty"` 126 Assigner *User `json:"assigner,omitempty"` 127 128 // The Milestone object including a 'title' attribute. 129 // Only provided for 'milestoned' and 'demilestoned' events. 130 Milestone *Milestone `json:"milestone,omitempty"` 131 // The 'id', 'actor', and 'url' for the source of a reference from another issue. 132 // Only provided for 'cross-referenced' events. 133 Source *Source `json:"source,omitempty"` 134 // An object containing rename details including 'from' and 'to' attributes. 135 // Only provided for 'renamed' events. 136 Rename *Rename `json:"rename,omitempty"` 137 ProjectCard *ProjectCard `json:"project_card,omitempty"` 138 // The state of a submitted review. Can be one of: 'commented', 139 // 'changes_requested' or 'approved'. 140 // Only provided for 'reviewed' events. 141 State *string `json:"state,omitempty"` 142 143 // The person requested to review the pull request. 144 Reviewer *User `json:"requested_reviewer,omitempty"` 145 // The person who requested a review. 146 Requester *User `json:"review_requester,omitempty"` 147 148 // The review summary text. 149 Body *string `json:"body,omitempty"` 150 SubmittedAt *time.Time `json:"submitted_at,omitempty"` 151 } 152 153 // Source represents a reference's source. 154 type Source struct { 155 ID *int64 `json:"id,omitempty"` 156 URL *string `json:"url,omitempty"` 157 Actor *User `json:"actor,omitempty"` 158 Type *string `json:"type,omitempty"` 159 Issue *Issue `json:"issue,omitempty"` 160 } 161 162 // ListIssueTimeline lists events for the specified issue. 163 // 164 // GitHub API docs: https://docs.github.com/en/rest/issues/timeline#list-timeline-events-for-an-issue 165 func (s *IssuesService) ListIssueTimeline(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*Timeline, *Response, error) { 166 u := fmt.Sprintf("repos/%v/%v/issues/%v/timeline", owner, repo, number) 167 u, err := addOptions(u, opts) 168 if err != nil { 169 return nil, nil, err 170 } 171 172 req, err := s.client.NewRequest("GET", u, nil) 173 if err != nil { 174 return nil, nil, err 175 } 176 177 // TODO: remove custom Accept header when this API fully launches. 178 acceptHeaders := []string{mediaTypeTimelinePreview, mediaTypeProjectCardDetailsPreview} 179 req.Header.Set("Accept", strings.Join(acceptHeaders, ", ")) 180 181 var events []*Timeline 182 resp, err := s.client.Do(ctx, req, &events) 183 if err != nil { 184 return nil, resp, err 185 } 186 187 return events, resp, nil 188 } 189