github.com/google/go-github/v49@v49.1.0/github/issues_timeline.go (about)

     1  // Copyright 2016 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  	"strings"
    12  	"time"
    13  )
    14  
    15  // Timeline represents an event that occurred around an Issue or Pull Request.
    16  //
    17  // It is similar to an IssueEvent but may contain more information.
    18  // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/events/issue-event-types
    19  type Timeline struct {
    20  	ID        *int64  `json:"id,omitempty"`
    21  	URL       *string `json:"url,omitempty"`
    22  	CommitURL *string `json:"commit_url,omitempty"`
    23  
    24  	// The User object that generated the event.
    25  	Actor *User `json:"actor,omitempty"`
    26  
    27  	// The person who commented on the issue.
    28  	User *User `json:"user,omitempty"`
    29  
    30  	// The person who authored the commit.
    31  	Author *CommitAuthor `json:"author,omitempty"`
    32  	// The person who committed the commit on behalf of the author.
    33  	Committer *CommitAuthor `json:"committer,omitempty"`
    34  	// The SHA of the commit in the pull request.
    35  	SHA *string `json:"sha,omitempty"`
    36  	// The commit message.
    37  	Message *string `json:"message,omitempty"`
    38  	// A list of parent commits.
    39  	Parents []*Commit `json:"parents,omitempty"`
    40  
    41  	// Event identifies the actual type of Event that occurred. Possible values
    42  	// are:
    43  	//
    44  	//     assigned
    45  	//       The issue was assigned to the assignee.
    46  	//
    47  	//     closed
    48  	//       The issue was closed by the actor. When the commit_id is present, it
    49  	//       identifies the commit that closed the issue using "closes / fixes #NN"
    50  	//       syntax.
    51  	//
    52  	//     commented
    53  	//       A comment was added to the issue.
    54  	//
    55  	//     committed
    56  	//       A commit was added to the pull request's 'HEAD' branch. Only provided
    57  	//       for pull requests.
    58  	//
    59  	//     cross-referenced
    60  	//       The issue was referenced from another issue. The 'source' attribute
    61  	//       contains the 'id', 'actor', and 'url' of the reference's source.
    62  	//
    63  	//     demilestoned
    64  	//       The issue was removed from a milestone.
    65  	//
    66  	//     head_ref_deleted
    67  	//       The pull request's branch was deleted.
    68  	//
    69  	//     head_ref_restored
    70  	//       The pull request's branch was restored.
    71  	//
    72  	//     labeled
    73  	//       A label was added to the issue.
    74  	//
    75  	//     locked
    76  	//       The issue was locked by the actor.
    77  	//
    78  	//     mentioned
    79  	//       The actor was @mentioned in an issue body.
    80  	//
    81  	//     merged
    82  	//       The issue was merged by the actor. The 'commit_id' attribute is the
    83  	//       SHA1 of the HEAD commit that was merged.
    84  	//
    85  	//     milestoned
    86  	//       The issue was added to a milestone.
    87  	//
    88  	//     referenced
    89  	//       The issue was referenced from a commit message. The 'commit_id'
    90  	//       attribute is the commit SHA1 of where that happened.
    91  	//
    92  	//     renamed
    93  	//       The issue title was changed.
    94  	//
    95  	//     reopened
    96  	//       The issue was reopened by the actor.
    97  	//
    98  	//     reviewed
    99  	//       The pull request was reviewed.
   100  	//
   101  	//     subscribed
   102  	//       The actor subscribed to receive notifications for an issue.
   103  	//
   104  	//     unassigned
   105  	//       The assignee was unassigned from the issue.
   106  	//
   107  	//     unlabeled
   108  	//       A label was removed from the issue.
   109  	//
   110  	//     unlocked
   111  	//       The issue was unlocked by the actor.
   112  	//
   113  	//     unsubscribed
   114  	//       The actor unsubscribed to stop receiving notifications for an issue.
   115  	//
   116  	Event *string `json:"event,omitempty"`
   117  
   118  	// The string SHA of a commit that referenced this Issue or Pull Request.
   119  	CommitID *string `json:"commit_id,omitempty"`
   120  	// The timestamp indicating when the event occurred.
   121  	CreatedAt *time.Time `json:"created_at,omitempty"`
   122  	// The Label object including `name` and `color` attributes. Only provided for
   123  	// 'labeled' and 'unlabeled' events.
   124  	Label *Label `json:"label,omitempty"`
   125  	// The User object which was assigned to (or unassigned from) this Issue or
   126  	// Pull Request. Only provided for 'assigned' and 'unassigned' events.
   127  	Assignee *User `json:"assignee,omitempty"`
   128  	Assigner *User `json:"assigner,omitempty"`
   129  
   130  	// The Milestone object including a 'title' attribute.
   131  	// Only provided for 'milestoned' and 'demilestoned' events.
   132  	Milestone *Milestone `json:"milestone,omitempty"`
   133  	// The 'id', 'actor', and 'url' for the source of a reference from another issue.
   134  	// Only provided for 'cross-referenced' events.
   135  	Source *Source `json:"source,omitempty"`
   136  	// An object containing rename details including 'from' and 'to' attributes.
   137  	// Only provided for 'renamed' events.
   138  	Rename      *Rename      `json:"rename,omitempty"`
   139  	ProjectCard *ProjectCard `json:"project_card,omitempty"`
   140  	// The state of a submitted review. Can be one of: 'commented',
   141  	// 'changes_requested' or 'approved'.
   142  	// Only provided for 'reviewed' events.
   143  	State *string `json:"state,omitempty"`
   144  
   145  	// The person requested to review the pull request.
   146  	Reviewer *User `json:"requested_reviewer,omitempty"`
   147  	// The person who requested a review.
   148  	Requester *User `json:"review_requester,omitempty"`
   149  
   150  	// The review summary text.
   151  	Body        *string    `json:"body,omitempty"`
   152  	SubmittedAt *time.Time `json:"submitted_at,omitempty"`
   153  }
   154  
   155  // Source represents a reference's source.
   156  type Source struct {
   157  	ID    *int64  `json:"id,omitempty"`
   158  	URL   *string `json:"url,omitempty"`
   159  	Actor *User   `json:"actor,omitempty"`
   160  	Type  *string `json:"type,omitempty"`
   161  	Issue *Issue  `json:"issue,omitempty"`
   162  }
   163  
   164  // ListIssueTimeline lists events for the specified issue.
   165  //
   166  // GitHub API docs: https://docs.github.com/en/rest/issues/timeline#list-timeline-events-for-an-issue
   167  func (s *IssuesService) ListIssueTimeline(ctx context.Context, owner, repo string, number int, opts *ListOptions) ([]*Timeline, *Response, error) {
   168  	u := fmt.Sprintf("repos/%v/%v/issues/%v/timeline", owner, repo, number)
   169  	u, err := addOptions(u, opts)
   170  	if err != nil {
   171  		return nil, nil, err
   172  	}
   173  
   174  	req, err := s.client.NewRequest("GET", u, nil)
   175  	if err != nil {
   176  		return nil, nil, err
   177  	}
   178  
   179  	// TODO: remove custom Accept header when this API fully launches.
   180  	acceptHeaders := []string{mediaTypeTimelinePreview, mediaTypeProjectCardDetailsPreview}
   181  	req.Header.Set("Accept", strings.Join(acceptHeaders, ", "))
   182  
   183  	var events []*Timeline
   184  	resp, err := s.client.Do(ctx, req, &events)
   185  	if err != nil {
   186  		return nil, resp, err
   187  	}
   188  
   189  	return events, resp, nil
   190  }