Skip to content

Commit

Permalink
Only run deletion reconciler on repo deleted events (#3036)
Browse files Browse the repository at this point in the history
* Only run deletion reconciler on repo deleted events

Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>

* React to webhook deletions as well

Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>

---------

Signed-off-by: Juan Antonio Osorio <ozz@stacklok.com>
  • Loading branch information
JAORMX committed Apr 11, 2024
1 parent e1dc5e7 commit c13a861
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions internal/controlplane/handlers_githubwebhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,9 @@ func (s *Server) HandleGitHubWebHook() http.HandlerFunc {

// Channel the event based on the webhook action
var watermillTopic string
switch m.Metadata.Get(entities.ActionEventKey) {
case WebhookActionEventDeleted:
// We got an entity delete event, so we need to reconcile and delete the entity from the DB
if shouldIssueDeletionEvent(m) {
watermillTopic = events.TopicQueueReconcileEntityDelete
default:
// Default to evaluating the entity
} else {
watermillTopic = events.TopicQueueEntityEvaluate
}

Expand Down Expand Up @@ -919,3 +916,13 @@ func parseRepoID(repoID any) (int64, error) {
return 0, fmt.Errorf("unknown type for repoID: %T", v)
}
}

func shouldIssueDeletionEvent(m *message.Message) bool {
return m.Metadata.Get(entities.ActionEventKey) == WebhookActionEventDeleted &&
deletionOfRelevantType(m)
}

func deletionOfRelevantType(m *message.Message) bool {
return m.Metadata.Get(events.GithubWebhookEventTypeKey) == "repository" ||
m.Metadata.Get(events.GithubWebhookEventTypeKey) == "meta"
}

0 comments on commit c13a861

Please sign in to comment.