Skip to content

Commit

Permalink
Reduce the number of github status updates.
Browse files Browse the repository at this point in the history
If the status for this is already exists and is set, don't set it again.
This triggers unnecessary github eventst and API calls.
.
  • Loading branch information
dlorenc committed Nov 7, 2019
1 parent 6d2fbac commit e208e8f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion cmd/pullrequest-init/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,13 +425,26 @@ func (h *GitHubHandler) getStatuses(ctx context.Context, sha string, path string
func (h *GitHubHandler) uploadStatuses(ctx context.Context, sha string, statuses []*Status) error {
var merr error

cs, _, err := h.Client.Repositories.GetCombinedStatus(ctx, h.owner, h.repo, sha, nil)
if err != nil {
return err
}

// Index the statuses so we can avoid sending them if they already exist.
csMap := map[string]string{}
for _, status := range cs.Statuses {
csMap[*status.Context] = *status.State
}

for _, s := range statuses {
state, ok := toGitHub[s.Code]
if !ok {
merr = multierror.Append(merr, fmt.Errorf("unknown status code %s", s.Code))
continue
}

if csMap[s.ID] == state {
continue
}
rs := &github.RepoStatus{
Context: github.String(s.ID),
State: github.String(state),
Expand Down

0 comments on commit e208e8f

Please sign in to comment.