github.com/google/go-github/v53@v53.2.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 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 ReviewRequester *User `json:"review_requester,omitempty"` 88 } 89 90 // DismissedReview represents details for 'dismissed_review' events. 91 type DismissedReview struct { 92 // State represents the state of the dismissed review. 93 // Possible values are: "commented", "approved", and "changes_requested". 94 State *string `json:"state,omitempty"` 95 ReviewID *int64 `json:"review_id,omitempty"` 96 DismissalMessage *string `json:"dismissal_message,omitempty"` 97 DismissalCommitID *string `json:"dismissal_commit_id,omitempty"` 98 } 99 100 // ListIssueEvents lists events for the specified issue. 101 // 102 // GitHub API docs: https://docs.github.com/en/rest/issues/events#list-issue-events 103 func (s *IssuesService) ListIssueEvents(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*IssueEvent, *Response, error) { 104 u := fmt.Sprintf("repos/%v/%v/issues/%v/events", owner, repo, number) 105 u, err := addOptions(u, opts) 106 if err != nil { 107 return nil, nil, err 108 } 109 110 req, err := s.client.NewRequest("GET", u, nil) 111 if err != nil { 112 return nil, nil, err 113 } 114 115 req.Header.Set("Accept", mediaTypeProjectCardDetailsPreview) 116 117 var events []*IssueEvent 118 resp, err := s.client.Do(ctx, req, &events) 119 if err != nil { 120 return nil, resp, err 121 } 122 123 return events, resp, nil 124 } 125 126 // ListRepositoryEvents lists events for the specified repository. 127 // 128 // GitHub API docs: https://docs.github.com/en/rest/issues/events#list-issue-events-for-a-repository 129 func (s *IssuesService) ListRepositoryEvents(ctx context.Context, owner, repo string, opts *ListOptions) ([]*IssueEvent, *Response, error) { 130 u := fmt.Sprintf("repos/%v/%v/issues/events", owner, repo) 131 u, err := addOptions(u, opts) 132 if err != nil { 133 return nil, nil, err 134 } 135 136 req, err := s.client.NewRequest("GET", u, nil) 137 if err != nil { 138 return nil, nil, err 139 } 140 141 var events []*IssueEvent 142 resp, err := s.client.Do(ctx, req, &events) 143 if err != nil { 144 return nil, resp, err 145 } 146 147 return events, resp, nil 148 } 149 150 // GetEvent returns the specified issue event. 151 // 152 // GitHub API docs: https://docs.github.com/en/rest/issues/events#get-an-issue-event 153 func (s *IssuesService) GetEvent(ctx context.Context, owner, repo string, id int64) (*IssueEvent, *Response, error) { 154 u := fmt.Sprintf("repos/%v/%v/issues/events/%v", owner, repo, id) 155 156 req, err := s.client.NewRequest("GET", u, nil) 157 if err != nil { 158 return nil, nil, err 159 } 160 161 event := new(IssueEvent) 162 resp, err := s.client.Do(ctx, req, event) 163 if err != nil { 164 return nil, resp, err 165 } 166 167 return event, resp, nil 168 } 169 170 // Rename contains details for 'renamed' events. 171 type Rename struct { 172 From *string `json:"from,omitempty"` 173 To *string `json:"to,omitempty"` 174 } 175 176 func (r Rename) String() string { 177 return Stringify(r) 178 }