Skip to content

Commit

Permalink
Update PR when labeled/opened
Browse files Browse the repository at this point in the history
This will conditionally update a PR whenever the PR is labeled or opened, which
will partially fulfill [this
suggestion](palantir#145 (comment))
for palantir#145.

It doesn't seem possible to determine which label was added via the
Github webhook payload, so this will update the PR regardless of whether
the label added is what is configured in `bulldozer.yml`.
  • Loading branch information
f1sherman committed Apr 6, 2021
1 parent 7a3e3cd commit 6459590
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/handler/pull_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package handler
import (
"context"
"encoding/json"
"fmt"

"github.com/google/go-github/v32/github"
"github.com/palantir/go-githubapp/githubapp"
Expand Down Expand Up @@ -66,6 +67,21 @@ func (h *PullRequest) Handle(ctx context.Context, eventType, deliveryID string,
logger.Error().Err(errors.WithStack(err)).Msg("Error processing pull request")
}

if event.GetAction() == "labeled" || event.GetAction() == "opened" {
logger.Debug().Msgf("received pull_request %s event", event.GetAction())

base, _ := pullCtx.Branches()
ref, _, err := client.Git.GetRef(ctx, pullCtx.Owner(), pullCtx.Repo(), fmt.Sprintf("refs/heads/%s", base))
if err != nil {
return errors.Wrap(err, "could not get git reference of PR base branch")
}

baseRef := ref.GetObject().GetSHA()
if err := h.UpdatePullRequest(logger.WithContext(ctx), pullCtx, client, pr, baseRef); err != nil {
logger.Error().Err(errors.WithStack(err)).Msg("Error updating pull request")
}
}

return nil
}

Expand Down

0 comments on commit 6459590

Please sign in to comment.