...

Source file src/github.com/google/go-github/v45/github/issues_events.go

Documentation: github.com/google/go-github/v45/github

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

View as plain text