dmitri.shuralyov.com/service/change/...

Fetch Closer in Closed event.

Similar to https://github.com/shurcooL/issues/commit/697ee8e877735feed6151525cad859327bfe40c4.

Follows https://dmitri.shuralyov.com/state/...$commit/28bcc343414c6adcd7b6911f9d0ef1ad6fbf30ae
and https://github.com/shurcooL/events/commit/25a0212309664cda69930a58f8369f24b9029812.
dmitshur committed 6 years ago commit 5b675ebb0b2bc6dd93ba2cedf6b4c7c9e0271de1
Collapse all
githubapi/githubapi.go
@@ -286,10 +286,26 @@ func (s service) ListTimeline(ctx context.Context, rs string, id uint64, opt *ch
							ReactionGroups  reactionGroups
							ViewerCanUpdate bool
						} `graphql:"...on IssueComment"`
						ClosedEvent struct {
							event
							Closer struct {
								Typename    string `graphql:"__typename"`
								PullRequest struct {
									State githubql.PullRequestState
									Title string
									URL   string
								} `graphql:"...on PullRequest"`
								Commit struct {
									OID     string
									Message string
									Author  struct {
										AvatarURL string `graphql:"avatarUrl(size:96)"`
									}
									URL string
								} `graphql:"...on Commit"`
							}
						} `graphql:"...on ClosedEvent"`
						ReopenedEvent struct {
							event
						} `graphql:"...on ReopenedEvent"`
						RenamedTitleEvent struct {
@@ -460,11 +476,33 @@ func (s service) ListTimeline(ctx context.Context, rs string, id uint64, opt *ch
		}
		switch event.Typename {
		case "ClosedEvent":
			e.Actor = ghActor(event.ClosedEvent.Actor)
			e.CreatedAt = event.ClosedEvent.CreatedAt.Time
			e.Payload = change.ClosedEvent{}
			switch event.ClosedEvent.Closer.Typename {
			case "PullRequest":
				pr := event.ClosedEvent.Closer.PullRequest
				e.Payload = change.ClosedEvent{
					Closer: change.Change{
						State: ghPRState(pr.State),
						Title: pr.Title,
					},
					CloserHTMLURL: pr.URL,
				}
			case "Commit":
				c := event.ClosedEvent.Closer.Commit
				e.Payload = change.ClosedEvent{
					Closer: change.Commit{
						SHA:     c.OID,
						Message: c.Message,
						Author:  users.User{AvatarURL: c.Author.AvatarURL},
					},
					CloserHTMLURL: c.URL,
				}
			default:
				e.Payload = change.ClosedEvent{}
			}
		case "ReopenedEvent":
			e.Actor = ghActor(event.ReopenedEvent.Actor)
			e.CreatedAt = event.ReopenedEvent.CreatedAt.Time
			e.Payload = change.ReopenedEvent{}
		case "RenamedTitleEvent":
timeline.go
@@ -68,12 +68,12 @@ type TimelineItem struct {
}

type (
	// ClosedEvent is when a change is closed.
	ClosedEvent struct {
		CommitID      string // CommitID is SHA of commit that closed the change, or empty string if there's no associated commit.
		CommitHTMLURL string // Optional.
		Closer        interface{} // Change (with State, Title), Commit (with SHA, Message, Author.AvatarURL), nil.
		CloserHTMLURL string      // If Closer is not nil.
	}

	// ReopenedEvent is when a change is reopened.
	ReopenedEvent struct{}