Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

webhooks: Handle GitLab push events#45856

Merged
ryanslade merged 15 commits into
mainfrom
rs/handle-gitlab-push
Dec 21, 2022
Merged

webhooks: Handle GitLab push events#45856
ryanslade merged 15 commits into
mainfrom
rs/handle-gitlab-push

Conversation

@ryanslade

@ryanslade ryanslade commented Dec 20, 2022

Copy link
Copy Markdown
Contributor

This change adds support to handle incoming push webhooks from GitLab.

Closes #45762

Test plan

Tests added and manually tested the full flow of pushing to a repo and seeing it update locally.

@cla-bot cla-bot Bot added the cla-signed label Dec 20, 2022
@ryanslade ryanslade changed the title rs/handle gitlab push webhooks: Handle GitLab push events Dec 20, 2022
@ryanslade ryanslade marked this pull request as ready for review December 20, 2022 14:56
@ryanslade ryanslade requested review from a team and pjlast December 20, 2022 14:56
@sourcegraph-bot

sourcegraph-bot commented Dec 20, 2022

Copy link
Copy Markdown
Contributor

Codenotify: Notifying subscribers in CODENOTIFY files for diff 1d57a50...8fd469b.

Notify File(s)
@eseliger internal/extsvc/gitlab/webhooks/events.go
internal/extsvc/gitlab/webhooks/webhooks.go
@sourcegraph/delivery doc/admin/config/webhooks.md
doc/admin/repo/webhooks.md

}

func (g *GitHubWebhookHandler) handleGitHubWebhook(ctx context.Context, _ database.DB, _ extsvc.CodeHostBaseURL, payload any) error {
func (g *GitHubWebhookHandler) handle(ctx context.Context, payload any) error {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Simplified to not take unused params.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

giphy (1)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread enterprise/cmd/frontend/internal/repos/webhooks/github_webhook_handler.go Outdated

@pjlast pjlast left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good 🕸️ 🪝 🥳

Just wondering about the way we do URL parsing

@sashaostrikov sashaostrikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

Comment thread enterprise/cmd/frontend/internal/repos/webhooks/gitlab_webhook_handler_test.go Outdated
}

func (g *GitHubWebhookHandler) handleGitHubWebhook(ctx context.Context, _ database.DB, _ extsvc.CodeHostBaseURL, payload any) error {
func (g *GitHubWebhookHandler) handle(ctx context.Context, payload any) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This confused me in other parts of the code too: handle is awfully generic but inside it makes assumptions about the event type it's called for. So I think it's easier to understand when encoded in name

Suggested change
func (g *GitHubWebhookHandler) handle(ctx context.Context, payload any) error {
func (g *GitHubWebhookHandler) handlePush(ctx context.Context, payload any) error {

repoName, err := githubNameFromEvent(event)
if err != nil {
return errors.Wrap(err, "handleGitHubWebhook: get name failed")
return errors.Wrap(err, "handle: get name failed")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See above: handle doesn't add anything really useful, I think.

}
}

func (g *GitLabWebhookHandler) handle(ctx context.Context, payload any) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as above

Suggested change
func (g *GitLabWebhookHandler) handle(ctx context.Context, payload any) error {
func (g *GitLabWebhookHandler) handlePushEvent(ctx context.Context, payload any) error {

@sashaostrikov sashaostrikov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Added a typo fix and test name suggestions

Comment thread enterprise/cmd/frontend/internal/repos/webhooks/github_webhook_handler.go Outdated
Comment thread enterprise/cmd/frontend/internal/repos/webhooks/github_webhook_handler_test.go Outdated
Comment thread enterprise/cmd/frontend/internal/repos/webhooks/gitlab_webhook_handler_test.go Outdated
ryanslade and others added 4 commits December 21, 2022 10:38
…_handler_test.go

Co-authored-by: Alex Ostrikov <alex.ostrikov@sourcegraph.com>
…_handler_test.go

Co-authored-by: Alex Ostrikov <alex.ostrikov@sourcegraph.com>
…_handler.go

Co-authored-by: Alex Ostrikov <alex.ostrikov@sourcegraph.com>
@ryanslade ryanslade enabled auto-merge (squash) December 21, 2022 09:54
@ryanslade ryanslade merged commit 87de73f into main Dec 21, 2022
@ryanslade ryanslade deleted the rs/handle-gitlab-push branch December 21, 2022 09:55
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

webhooks: Handle push events for GitLab

5 participants