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

githubapi: Add support for deleted branch events.
dmitshur committed 6 years ago commit 16ed602056cd739ef4821610dbf7c44b097a9e94
Collapse all
githubapi/githubapi.go
@@ -308,14 +308,10 @@ func (s service) ListTimeline(ctx context.Context, rs string, id uint64, opt *ch
							Label struct {
								Name  string
								Color string
							}
						} `graphql:"...on UnlabeledEvent"`
						// TODO: Wait for GitHub to add support.
						//CommentDeletedEvent struct {
						//	event
						//} `graphql:"...on CommentDeletedEvent"`
						ReviewRequestedEvent struct {
							event
							RequestedReviewer struct {
								githubqlActor `graphql:"...on Actor"`
							}
@@ -332,10 +328,18 @@ func (s service) ListTimeline(ctx context.Context, rs string, id uint64, opt *ch
								OID string
								URL string
							}
							MergeRefName string
						} `graphql:"...on MergedEvent"`
						HeadRefDeletedEvent struct {
							event
							HeadRefName string
						} `graphql:"...on HeadRefDeletedEvent"`
						// TODO: Wait for GitHub to add support.
						//CommentDeletedEvent struct {
						//	event
						//} `graphql:"...on CommentDeletedEvent"`
					}
				} `graphql:"timeline(first:100)"` // TODO: Pagination...

				// Need to use PullRequest.Reviews rather than PullRequest.Timeline.PullRequestReview,
				// because the latter is missing single-inline-reply reviews (as of 2018-02-08).
@@ -489,14 +493,10 @@ func (s service) ListTimeline(ctx context.Context, rs string, id uint64, opt *ch
				Label: issues.Label{
					Name:  event.UnlabeledEvent.Label.Name,
					Color: ghColor(event.UnlabeledEvent.Label.Color),
				},
			}
		// TODO: Wait for GitHub to add support.
		//case "CommentDeletedEvent":
		//	e.Actor = ghActor(event.CommentDeletedEvent.Actor)
		//	e.CreatedAt = event.CommentDeletedEvent.CreatedAt.Time
		case "ReviewRequestedEvent":
			e.Actor = ghActor(event.ReviewRequestedEvent.Actor)
			e.CreatedAt = event.ReviewRequestedEvent.CreatedAt.Time
			e.Payload = changes.ReviewRequestedEvent{
				RequestedReviewer: ghActor(event.ReviewRequestedEvent.RequestedReviewer.githubqlActor),
@@ -513,10 +513,21 @@ func (s service) ListTimeline(ctx context.Context, rs string, id uint64, opt *ch
			e.Payload = changes.MergedEvent{
				CommitID:      event.MergedEvent.Commit.OID,
				CommitHTMLURL: event.MergedEvent.Commit.URL,
				RefName:       event.MergedEvent.MergeRefName,
			}
		case "HeadRefDeletedEvent":
			e.Actor = ghActor(event.HeadRefDeletedEvent.Actor)
			e.CreatedAt = event.HeadRefDeletedEvent.CreatedAt.Time
			e.Payload = changes.DeletedEvent{
				Type: "branch",
				Name: event.HeadRefDeletedEvent.HeadRefName,
			}
		// TODO: Wait for GitHub to add support.
		//case "CommentDeletedEvent":
		//	e.Actor = ghActor(event.CommentDeletedEvent.Actor)
		//	e.CreatedAt = event.CommentDeletedEvent.CreatedAt.Time
		default:
			continue
		}
		timeline = append(timeline, e)
	}
timeline.go
@@ -88,13 +88,10 @@ type (
	// UnlabeledEvent is when a change is unlabeled.
	UnlabeledEvent struct {
		Label issues.Label
	}

	// CommentDeletedEvent is when a comment is deleted.
	CommentDeletedEvent struct{}

	ReviewRequestedEvent struct {
		RequestedReviewer users.User
	}
	ReviewRequestRemovedEvent struct {
		RequestedReviewer users.User
@@ -104,9 +101,16 @@ type (
		CommitID      string
		CommitHTMLURL string // Optional.
		RefName       string
	}

	// DeletedEvent is a delete event.
	// THINK: Merge with "github.com/shurcooL/events/event".Delete?
	DeletedEvent struct {
		Type string // "branch", "comment".
		Name string
	}

	// TODO: Remove, now that these have been merged into Review.
	ApprovedEvent         struct{}
	ChangesRequestedEvent struct{}
)