@@ -53,6 +53,7 @@ func (h *Push) Handle(ctx context.Context, eventType, deliveryID string, payload
5353 }
5454
5555 ctx , logger := githubapp .PrepareRepoContext (ctx , installationID , ghRepo )
56+ logger .Debug ().Msgf ("Received push event with base ref %s" , baseRef )
5657
5758 client , err := h .ClientCreator .NewInstallationClient (installationID )
5859 if err != nil {
@@ -63,24 +64,22 @@ func (h *Push) Handle(ctx context.Context, eventType, deliveryID string, payload
6364 if err != nil {
6465 return errors .Wrap (err , "failed to determine open pull requests matching the push change" )
6566 }
66-
67- logger .Debug ().Msgf ("received push event with base ref %s" , baseRef )
68-
6967 if len (prs ) == 0 {
70- logger .Debug ().Msg ("Doing nothing since push event affects no open pull requests" )
68+ logger .Debug ().Msgf ("Doing nothing since push to %s affects no open pull requests" , baseRef )
7169 return nil
7270 }
7371
72+ // Fetch configuration once, since we know all PRs target the same ref
73+ config , err := h .FetchConfig (ctx , client , owner , repoName , baseRef )
74+ if err != nil {
75+ return err
76+ }
77+
7478 for _ , pr := range prs {
75- pullCtx := pull .NewGithubContext (client , pr )
7679 logger := logger .With ().Int (githubapp .LogKeyPRNum , pr .GetNumber ()).Logger ()
80+ logger .Debug ().Msgf ("Considering pull request for update" )
7781
78- config , err := h .FetchConfig (ctx , client , pr )
79- if err != nil {
80- return errors .Wrap (err , "failed to fetch configuration" )
81- }
82-
83- logger .Debug ().Msgf ("checking status for updated sha %s" , baseRef )
82+ pullCtx := pull .NewGithubContext (client , pr )
8483 if _ , err := h .UpdatePullRequest (logger .WithContext (ctx ), pullCtx , client , config , pr , baseRef ); err != nil {
8584 logger .Error ().Err (errors .WithStack (err )).Msg ("Error updating pull request" )
8685 }
0 commit comments