Debian Codegraph @

github/issues_events.go

raw
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
6 package github
7
8 import (
9 "context"
10 "fmt"
11 )
12
13 // IssueEvent represents an event that occurred around an Issue or Pull Request.
14 type IssueEvent struct {
15 ID *int64 `json:"id,omitempty"`
16 URL *string `json:"url,omitempty"`
17
18 // The User that generated this event.
19 Actor *User `json:"actor,omitempty"`
20
21 // The action corresponding to the event.
22 Action string `json:"action,omitempty"`
23
24 // Event identifies the actual type of Event that occurred. Possible
25 // values are:
26 //
27 // closed
28 // The Actor closed the issue.
29 // If the issue was closed by commit message, CommitID holds the SHA1 hash of the commit.
30 //
31 // merged
32 // The Actor merged into master a branch containing a commit mentioning the issue.
33 // CommitID holds the SHA1 of the merge commit.
34 //
35 // referenced
36 // The Actor committed to master a commit mentioning the issue in its commit message.
37 // CommitID holds the SHA1 of the commit.
38 //
39 // reopened, unlocked
40 // The Actor did that to the issue.
41 //
42 // locked
43 // The Actor locked the issue.
44 // LockReason holds the reason of locking the issue (if provided while locking).
45 //
46 // renamed
47 // The Actor changed the issue title from Rename.From to Rename.To.
48 //
49 // mentioned
50 // Someone unspecified @mentioned the Actor [sic] in an issue comment body.
51 //
52 // assigned, unassigned
53 // The Assigner assigned the issue to or removed the assignment from the Assignee.
54 //
55 // labeled, unlabeled
56 // The Actor added or removed the Label from the issue.
57 //
58 // milestoned, demilestoned
59 // The Actor added or removed the issue from the Milestone.
60 //
61 // subscribed, unsubscribed
62 // The Actor subscribed to or unsubscribed from notifications for an issue.
63 //
64 // head_ref_deleted, head_ref_restored
65 // The pull request’s branch was deleted or restored.
66 //
67 // review_dismissed
68 // The review was dismissed and `DismissedReview` will be populated below.
69 //
70 // review_requested, review_request_removed
71 // The Actor requested or removed the request for a review.
72 // RequestedReviewer or RequestedTeam, and ReviewRequester will be populated below.
73 //
74 Event *string `json:"event,omitempty"`
75
76 CreatedAt *Timestamp `json:"created_at,omitempty"`
77 Issue *Issue `json:"issue,omitempty"`
78
79 // Only present on certain events; see above.
80 Repository *Repository `json:"repository,omitempty"`
81 Assignee *User `json:"assignee,omitempty"`
82 Assigner *User `json:"assigner,omitempty"`
83 CommitID *string `json:"commit_id,omitempty"`
84 Milestone *Milestone `json:"milestone,omitempty"`
85 Label *Label `json:"label,omitempty"`
86 Rename *Rename `json:"rename,omitempty"`
87 LockReason *string `json:"lock_reason,omitempty"`
88 ProjectCard *ProjectCard `json:"project_card,omitempty"`
89 DismissedReview *DismissedReview `json:"dismissed_review,omitempty"`
90 RequestedReviewer *User `json:"requested_reviewer,omitempty"`
91 RequestedTeam *Team `json:"requested_team,omitempty"`
92 ReviewRequester *User `json:"review_requester,omitempty"`
93 PerformedViaGithubApp *App `json:"performed_via_github_app,omitempty"`
94 }
95
96 // DismissedReview represents details for 'dismissed_review' events.
97 type DismissedReview struct {
98 // State represents the state of the dismissed review.
99 // Possible values are: "commented", "approved", and "changes_requested".
100 State *string `json:"state,omitempty"`
101 ReviewID *int64 `json:"review_id,omitempty"`
102 DismissalMessage *string `json:"dismissal_message,omitempty"`
103 DismissalCommitID *string `json:"dismissal_commit_id,omitempty"`
104 }
105
106 // ListIssueEvents lists events for the specified issue.
107 //
108 // GitHub API docs: https://docs.github.com/rest/issues/events#list-issue-events
109 //
110 //meta:operation GET /repos/{owner}/{repo}/issues/{issue_number}/events
111 func (s *IssuesService) ListIssueEvents(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*IssueEvent, *Response, error) {
112 u := fmt.Sprintf("repos/%v/%v/issues/%v/events", owner, repo, number)
113 u, err := addOptions(u, opts)
114 if err != nil {
115 return nil, nil, err
116 }
117
118 req, err := s.client.NewRequest("GET", u, nil)
119 if err != nil {
120 return nil, nil, err
121 }
122
123 req.Header.Set("Accept", mediaTypeProjectCardDetailsPreview)
124
125 var events []*IssueEvent
126 resp, err := s.client.Do(ctx, req, &events)
127 if err != nil {
128 return nil, resp, err
129 }
130
131 return events, resp, nil
132 }
133
134 // ListRepositoryEvents lists events for the specified repository.
135 //
136 // GitHub API docs: https://docs.github.com/rest/issues/events#list-issue-events-for-a-repository
137 //
138 //meta:operation GET /repos/{owner}/{repo}/issues/events
139 func (s *IssuesService) ListRepositoryEvents(ctx context.Context, owner, repo string, opts *ListOptions) ([]*IssueEvent, *Response, error) {
140 u := fmt.Sprintf("repos/%v/%v/issues/events", owner, repo)
141 u, err := addOptions(u, opts)
142 if err != nil {
143 return nil, nil, err
144 }
145
146 req, err := s.client.NewRequest("GET", u, nil)
147 if err != nil {
148 return nil, nil, err
149 }
150
151 var events []*IssueEvent
152 resp, err := s.client.Do(ctx, req, &events)
153 if err != nil {
154 return nil, resp, err
155 }
156
157 return events, resp, nil
158 }
159
160 // GetEvent returns the specified issue event.
161 //
162 // GitHub API docs: https://docs.github.com/rest/issues/events#get-an-issue-event
163 //
164 //meta:operation GET /repos/{owner}/{repo}/issues/events/{event_id}
165 func (s *IssuesService) GetEvent(ctx context.Context, owner, repo string, id int64) (*IssueEvent, *Response, error) {
166 u := fmt.Sprintf("repos/%v/%v/issues/events/%v", owner, repo, id)
167
168 req, err := s.client.NewRequest("GET", u, nil)
169 if err != nil {
170 return nil, nil, err
171 }
172
173 event := new(IssueEvent)
174 resp, err := s.client.Do(ctx, req, event)
175 if err != nil {
176 return nil, resp, err
177 }
178
179 return event, resp, nil
180 }
181
182 // Rename contains details for 'renamed' events.
183 type Rename struct {
184 From *string `json:"from,omitempty"`
185 To *string `json:"to,omitempty"`
186 }
187
188 func (r Rename) String() string {
189 return Stringify(r)
190 }