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