From e208e8fd46f539f7bf7b38b58c9ee39857b2711e Mon Sep 17 00:00:00 2001 From: Dan Lorenc Date: Thu, 7 Nov 2019 12:59:19 -0600 Subject: [PATCH] Reduce the number of github status updates. If the status for this is already exists and is set, don't set it again. This triggers unnecessary github eventst and API calls. . --- cmd/pullrequest-init/github.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/cmd/pullrequest-init/github.go b/cmd/pullrequest-init/github.go index 680cb2de6e9..1890f8fa889 100644 --- a/cmd/pullrequest-init/github.go +++ b/cmd/pullrequest-init/github.go @@ -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),