Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle synchronize events for pull requests in github #5141

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
32 changes: 20 additions & 12 deletions internal/providers/github/webhook/handlers_pull_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand All @@ -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
}
}
Loading