...

Source file src/github.com/google/go-github/v55/github/issues_timeline.go

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

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

View as plain text