From 2d331131a5526eea5b632371ee929fae2ba4b81a Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Thu, 5 Dec 2024 14:09:26 +0200 Subject: [PATCH 1/2] Handle synchronize events for pull requests in github We should just try to re-evaluate the PR instead of creating a new entry. Signed-off-by: Juan Antonio Osorio --- .../github/webhook/handlers_pull_requests.go | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/internal/providers/github/webhook/handlers_pull_requests.go b/internal/providers/github/webhook/handlers_pull_requests.go index a4061ef0a5..59fa2e9823 100644 --- a/internal/providers/github/webhook/handlers_pull_requests.go +++ b/internal/providers/github/webhook/handlers_pull_requests.go @@ -137,18 +137,12 @@ func processPullRequestEvent( } pullProps.SetProperty(properties.PropertyName, nameProp) - var topic string - switch pullProps.GetProperty(ghprop.PullPropertyAction).GetString() { - case webhookActionEventOpened, - webhookActionEventReopened, - webhookActionEventSynchronize: - topic = constants.TopicQueueOriginatingEntityAdd - case webhookActionEventClosed: - topic = constants.TopicQueueOriginatingEntityDelete - default: - zerolog.Ctx(ctx).Info().Msgf("action %s is not handled for pull requests", - pullProps.GetProperty(ghprop.PullPropertyAction).GetString()) - return nil, errNotHandled + topic, err := getPREventHandlingTopic(pullProps) + if err != nil { + zerolog.Ctx(ctx).Error().Err(err). + Str("action", event.GetAction()). + Msg("error getting PR event handling topic") + return nil, err } prMsg := entityMessage.NewEntityRefreshAndDoMessage(). @@ -160,3 +154,17 @@ func processPullRequestEvent( return &processingResult{topic: topic, wrapper: prMsg}, nil } + +func getPREventHandlingTopic(pullProps *properties.Properties) (string, error) { + switch pullProps.GetProperty(ghprop.PullPropertyAction).GetString() { + case webhookActionEventOpened, + webhookActionEventReopened: + return constants.TopicQueueOriginatingEntityAdd, nil + case webhookActionEventSynchronize: + return constants.TopicQueueRefreshEntityAndEvaluate, nil + case webhookActionEventClosed: + return constants.TopicQueueOriginatingEntityDelete, nil + default: + return "", errNotHandled + } +} From 1ed8112f3038444e40489ec58f6ffc8f4fa4fa44 Mon Sep 17 00:00:00 2001 From: Juan Antonio Osorio Date: Thu, 5 Dec 2024 15:06:33 +0200 Subject: [PATCH 2/2] Fix unit tests Signed-off-by: Juan Antonio Osorio --- .../providers/github/webhook/handlers_githubwebhooks_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/providers/github/webhook/handlers_githubwebhooks_test.go b/internal/providers/github/webhook/handlers_githubwebhooks_test.go index 3894a5f487..6f3a7cbad6 100644 --- a/internal/providers/github/webhook/handlers_githubwebhooks_test.go +++ b/internal/providers/github/webhook/handlers_githubwebhooks_test.go @@ -2514,7 +2514,7 @@ func (s *UnitTestSuite) TestHandleGitHubWebHook() { ghMocks: []func(hubMock gf.GitHubMock){ gf.WithSuccessfulGetEntityName("mindersec/minder/42"), }, - topic: constants.TopicQueueOriginatingEntityAdd, + topic: constants.TopicQueueRefreshEntityAndEvaluate, statusCode: http.StatusOK, queued: func(t *testing.T, event string, ch <-chan *message.Message) { t.Helper()