feat(gitlab): add webhook support with getEvent, validateWebhookEvent, createWebhook and createPullRequest#93
Conversation
Greptile SummaryThis PR adds
Confidence Score: 4/5Safe to merge after resolving the env-var mismatch and reviewing the SSL default One P1 issue (env-var name mismatch means docker-compose config has no effect on tests) and two P2 issues (unconditional SSL bypass and silent 0 return) remain unaddressed tests/VCS/Base.php (env-var rename) and src/VCS/Adapter/Git/GitLab.php (SSL and ID handling in createWebhook) Important Files Changed
Reviews (3): Last reviewed commit: "updated with suggestions 1" | Re-trigger Greptile |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f8a0b54f18
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| $payload = [ | ||
| 'url' => $url, | ||
| 'token' => $secret, | ||
| 'enable_ssl_verification' => false, |
There was a problem hiding this comment.
Preserve TLS verification for GitLab webhooks
createWebhook() unconditionally sets enable_ssl_verification to false, which disables certificate validation for all HTTPS webhook deliveries. This introduces a production security regression (MITM-friendly delivery path) for any non-local webhook target; this should default to secure verification and only be disabled explicitly when needed.
Useful? React with 👍 / 👎.
| $commits = $payloadArray['commits'] ?? []; | ||
| $latestCommit = !empty($commits) ? $commits[0] : []; | ||
| $ref = $payloadArray['ref'] ?? ''; |
There was a problem hiding this comment.
Parse push head commit instead of first commit entry
In getEvent('Push Hook', ...), selecting $commits[0] can return an older commit on multi-commit pushes, while commitHash is taken from checkout_sha (the pushed head). That creates inconsistent event data where hash, author, message, and URL can refer to different commits, which can mislead downstream automation and notifications.
Useful? React with 👍 / 👎.
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
| protected function getLastWebhookRequest(): array | ||
| { | ||
| $catcherUrl = System::getEnv('TESTS_GITEA_REQUEST_CATCHER_URL', 'http://request-catcher:5000'); | ||
| $catcherUrl = System::getEnv('TESTS_REQUEST_CATCHER_URL', 'http://request-catcher:5000'); |
There was a problem hiding this comment.
Env-var name mismatch — defined config silently ignored
Base.php (both helper methods) now reads TESTS_REQUEST_CATCHER_URL, but docker-compose.yml only defines TESTS_GITLAB_REQUEST_CATCHER_URL (and the unchanged TESTS_GITEA_REQUEST_CATCHER_URL). No service sets TESTS_REQUEST_CATCHER_URL, so the helpers always fall back to the hardcoded default and any value set via TESTS_GITLAB_REQUEST_CATCHER_URL is silently ignored. Either add TESTS_REQUEST_CATCHER_URL to the tests service environment in docker-compose.yml, or revert to reading TESTS_GITLAB_REQUEST_CATCHER_URL for consistency with the per-adapter naming convention already used by Gitea.
Summary
Implements webhook support for the GitLab adapter, completing the event-driven integration layer.
Changes
New methods implemented
createWebhook— registers a webhook on a GitLab project with configurable events (push,pull_request/merge request), returning the webhook IDgetEvent— parses incoming GitLab webhook payloads forPush HookandMerge Request Hookevents into a normalized format consistent with other adaptersvalidateWebhookEvent— validates theX-Gitlab-Tokenheader against the configured secret usinghash_equalsto prevent timing attackscreatePullRequest— creates a GitLab merge request; implemented here as a dependency for the webhook E2E test setupTests added
testCreateWebhook— verifies webhook creation returns a valid IDtestWebhookPushEvent— E2E test that creates a repo, registers a webhook, triggers a push, and asserts the payload is received via request-catchertestWebhookPullRequestEvent— E2E test that creates a repo, opens a merge request, and asserts the merge request webhook payload is receivedtestValidateWebhookEvent— unit test for valid and invalid token scenariostestGetEventPush— unit test for push payload parsingtestGetEventPullRequest— unit test for merge request payload parsingtestGetEventUnknown— unit test for unknown event type returns empty arrayNotes
X-Gitlab-Token), not HMAC like Gitea/GitHubassertEventuallypattern with a request-catcher container, consistent with the Gitea adapter testscreatePullRequestfull test suite (along withgetPullRequest,getPullRequestFiles,createCommentetc.