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

Events of type "repository" now avoid checking hook id. #3463

Merged
merged 1 commit into from
May 31, 2024
Merged

Conversation

blkt
Copy link
Contributor

@blkt blkt commented May 30, 2024

Summary

Events of type "repository" having "action" delete must trigger the deletion of registered repositories. Given we use the same deserialization struct for both "repository" and "meta" events, we erroneously checked the received hook id against the one stored in the database, thus consistently failing.

Added fix, test case, and improved logs.

Fixes #3461

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

  • reproduced issue locally
  • added test case

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@blkt blkt self-assigned this May 30, 2024
@blkt blkt requested a review from a team as a code owner May 30, 2024 11:59
@coveralls
Copy link

coveralls commented May 30, 2024

Coverage Status

coverage: 52.398% (+0.02%) from 52.376%
when pulling f866e6b on issue-3461
into 16e3ca0 on main.

Events of type "repository" having "action" delete must trigger the
deletion of registered repositories. Given we use the same
deserialization struct for both "repository" and "meta" events, we
erroneously checked the received hook id against the one stored in the
database, thus consistently failing.

Added fix, test case, and improved logs.
Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, one more comment

@@ -678,7 +694,7 @@ func (s *Server) processRelevantRepositoryEvent(
}

// This only makes sense for "meta" event type
if dbrepo.WebhookID.Valid {
if event.GetHookID() != 0 && dbrepo.WebhookID.Valid {
// Check if the payload webhook ID matches the one we
// have stored in the DB for this repository
if event.GetHookID() != dbrepo.WebhookID.Int64 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the comment on line 701-703 still make sense?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it does.

This routine is called only on meta and repository events, and this fix ensures that we check the hook id only when available, which is the case solely for the meta event.

The comment per sé is still valid, but can be removed if it's not useful.
I lean towards leaving it there for posterity, maybe rewriting it at the top of the if, but let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it's valid and useful

@blkt blkt merged commit bce7d4b into main May 31, 2024
20 checks passed
@blkt blkt deleted the issue-3461 branch May 31, 2024 06:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GitHub webhook events of type "repository" action "deleted" are not handled properly
4 participants