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