diff --git a/server/handler/pull_request.go b/server/handler/pull_request.go index e100190de..df452422f 100644 --- a/server/handler/pull_request.go +++ b/server/handler/pull_request.go @@ -17,6 +17,7 @@ package handler import ( "context" "encoding/json" + "fmt" "github.com/google/go-github/v32/github" "github.com/palantir/go-githubapp/githubapp" @@ -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 }