Skip to content

Commit

Permalink
Fix webhook event on repository deletion. (#4216)
Browse files Browse the repository at this point in the history
Repository deletion events coming from repository webhooks (not app
webhooks) were encoded in the wrong way, making downstream deletion
handler fail on validation.

This change fixes the logic by encoding a different payload in case of
deletion. Further changes will be necessary to encapsulate
entity-specific messages in a more general envelope in order to handle
deletions of other entities as well without introducing additional
infrastructure (i.e. watermill topics).
  • Loading branch information
blkt committed Aug 21, 2024
1 parent 9a3fc94 commit 71af872
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 103 deletions.
30 changes: 21 additions & 9 deletions internal/controlplane/handlers_githubwebhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,23 @@ func (s *Server) processRelevantRepositoryEvent(
}
}

// For webhook deletions, repository deletions, and repository
// transfers, we issue a delete event with the correct message
// type.
if event.GetAction() == webhookActionEventDeleted ||
event.GetAction() == webhookActionEventTransferred {
repoEvent := messages.NewRepoEvent().
WithProjectID(dbrepo.ProjectID).
WithProviderID(dbrepo.ProviderID).
WithRepoID(dbrepo.ID)

return &processingResult{
topic: events.TopicQueueReconcileEntityDelete,
wrapper: repoEvent,
}, nil
}

// For all other actions, we trigger an evaluation.
// protobufs are our API, so we always execute on these instead of the DB directly.
pbRepo := repositories.PBRepositoryFromDB(*dbrepo)
eiw := entities.NewEntityInfoWrapper().
Expand All @@ -838,15 +855,10 @@ func (s *Server) processRelevantRepositoryEvent(
WithRepository(pbRepo).
WithRepositoryID(dbrepo.ID)

topic := events.TopicQueueEntityEvaluate
if event.GetAction() == webhookActionEventDeleted {
topic = events.TopicQueueReconcileEntityDelete
}
if event.GetAction() == webhookActionEventTransferred {
topic = events.TopicQueueReconcileEntityDelete
}

return &processingResult{topic: topic, wrapper: eiw}, nil
return &processingResult{
topic: events.TopicQueueEntityEvaluate,
wrapper: eiw,
}, nil
}

func (s *Server) processRepositoryEvent(
Expand Down
Loading

0 comments on commit 71af872

Please sign in to comment.