Skip to content

feat(gitlab): add getPullRequest, getPullRequestFiles, getPullRequestFromBranch, createComment, getComment, updateComment and getUser#94

Open
jaysomani wants to merge 8 commits into
utopia-php:mainfrom
jaysomani:feat/gitlab-adapter-pullrequest
Open

feat(gitlab): add getPullRequest, getPullRequestFiles, getPullRequestFromBranch, createComment, getComment, updateComment and getUser#94
jaysomani wants to merge 8 commits into
utopia-php:mainfrom
jaysomani:feat/gitlab-adapter-pullrequest

Conversation

@jaysomani
Copy link
Copy Markdown
Contributor

Summary

Implements the remaining pull request, comment, and user methods for the GitLab adapter, completing the full adapter implementation.

Changes

New methods implemented

  • getPullRequest — fetches a merge request by iid, normalized to match Gitea/GitHub shape
  • getPullRequestFiles — fetches changed files using /diffs endpoint with patch_id_sha polling to handle GitLab's async diff processing
  • getPullRequestFromBranch — finds an open merge request by source branch
  • createComment — creates a note on a merge request via GitLab notes API
  • getComment — retrieves a note by ID, searching across all MRs in the repository
  • updateComment — updates an existing note by ID
  • getUser — fetches a user by username via GitLab users search API

Tests added

  • Full test coverage for all new methods including invalid/edge case scenarios
  • GitLab-specific tests: testGetEventPushMatchesCheckoutSha, testValidateWebhookEventUsesPlainToken, testCreateOrganization
  • Parity tests matching Gitea: testGetUser, testGetUserWithInvalidUsername, testCreatePrivateRepository, testGetRepositoryWithNonExistingOwner, testCreateRepositoryWithInvalidName, testDeleteRepositoryTwiceFails, testDeleteNonExistingRepositoryFails, testGetPullRequestFromBranchNoPR, testCreateCommentInvalidPR, testGetCommentInvalidId

Notes

  • GitLab notes (comments) are scoped to merge requests — getComment and updateComment search across all MRs to find the note by ID since the MR iid is not stored with the comment ID
  • getPullRequestFiles uses patch_id_sha polling per GitLab's official documentation recommendation for async diff processing
  • getUser returns username field (not login like Gitea/GitHub) — this is a GitLab API difference
  • This PR is based on feat/gitlab-adapter-webhooks and will need a rebase once that PR merges

@jaysomani jaysomani marked this pull request as ready for review April 27, 2026 06:06
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 27, 2026

Greptile Summary

This PR completes the GitLab adapter by implementing getPullRequest, getPullRequestFiles, getPullRequestFromBranch, createComment, getComment, updateComment, and getUser. It also changes the updateComment signature from int to string across the base class, GitHub, and Gitea adapters to accommodate GitLab's composite mrIid:noteId comment identifier.

  • getPullRequest and getPullRequestFromBranch correctly normalize the GitLab API shape (mapping iidnumber, source_branchhead.ref, etc.) but pass through the raw state value (opened) instead of mapping it to the cross-adapter convention (open); the Gitea adapter's equivalent test asserts open, so this discrepancy will break polymorphic callers.
  • getPullRequestFiles uses a patch_id_sha polling loop and proper pagination, matching the recommended GitLab async diff approach.
  • Several previously skipped tests are now implemented; the testGetPullRequest assertion for 'opened' state will need updating if the normalization fix is applied.

Confidence Score: 3/5

The adapter interface contract for pull request state is broken: GitLab returns 'opened' while all other adapters return 'open', causing silent mismatches for any code that uses the adapters interchangeably.

Both getPullRequest and getPullRequestFromBranch expose GitLab's raw 'opened' state instead of normalizing it to match the 'open' value returned by GitHub and Gitea. Code that swaps between adapters and checks the state field will behave incorrectly for GitLab.

src/VCS/Adapter/Git/GitLab.php — state normalization in both getPullRequest and getPullRequestFromBranch; tests/VCS/Adapter/GitLabTest.php — testGetPullRequest assertion will need updating after the fix.

Important Files Changed

Filename Overview
src/VCS/Adapter/Git/GitLab.php Implements 7 new methods; state normalization bug in getPullRequest and getPullRequestFromBranch returns 'opened' instead of 'open', breaking cross-adapter callers
src/VCS/Adapter.php updateComment signature changed from int to string commentId to accommodate GitLab's composite ID format
src/VCS/Adapter/Git/GitHub.php updateComment signature updated to match the new string commentId in the abstract base — no behavioral change
src/VCS/Adapter/Git/Gitea.php updateComment signature updated to string; test cast from (int) to (string) updated accordingly
tests/VCS/Adapter/GitLabTest.php Previously skipped tests now implemented; testGetPullRequest asserts 'opened' state which won't match if state normalization is fixed
tests/VCS/Adapter/GiteaTest.php Cast from (int) to (string) for commentId in updateComment test calls; no logic changes

Reviews (7): Last reviewed commit: "Merge branch 'utopia-php:main' into feat..." | Re-trigger Greptile

Comment thread src/VCS/Adapter/Git/GitLab.php Outdated
Comment thread src/VCS/Adapter/Git/GitLab.php Outdated
Comment thread src/VCS/Adapter/Git/GitLab.php Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 76df5e76dd

ℹ️ 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".

Comment thread src/VCS/Adapter/Git/GitLab.php Outdated
Comment thread src/VCS/Adapter/Git/GitLab.php
Comment thread src/VCS/Adapter/Git/GitLab.php
@jaysomani jaysomani marked this pull request as draft April 27, 2026 06:53
@jaysomani jaysomani marked this pull request as ready for review April 27, 2026 08:41
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8a688e865e

ℹ️ 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".

Comment thread src/VCS/Adapter/Git/GitLab.php Outdated
Comment thread src/VCS/Adapter/Git/GitLab.php
Comment on lines +591 to +603
// Normalize to match expected shape (consistent with Gitea/GitHub)
return [
'number' => $mr['iid'] ?? 0,
'title' => $mr['title'] ?? '',
'state' => $mr['state'] ?? '',
'head' => [
'ref' => $mr['source_branch'] ?? '',
'sha' => $mr['sha'] ?? '',
],
'base' => [
'ref' => $mr['target_branch'] ?? '',
],
];
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.

P1 The state field is not normalized: GitLab returns opened/closed/merged, while both GitHub and Gitea return open/closed. Any polymorphic caller checking $result['state'] === 'open' will get a mismatch for every GitLab-backed open MR. The Gitea test for the same method explicitly asserts 'open' (GiteaTest.php line 482). Both getPullRequest and getPullRequestFromBranch have this defect.

Suggested change
// Normalize to match expected shape (consistent with Gitea/GitHub)
return [
'number' => $mr['iid'] ?? 0,
'title' => $mr['title'] ?? '',
'state' => $mr['state'] ?? '',
'head' => [
'ref' => $mr['source_branch'] ?? '',
'sha' => $mr['sha'] ?? '',
],
'base' => [
'ref' => $mr['target_branch'] ?? '',
],
];
// Normalize to match expected shape (consistent with Gitea/GitHub)
$stateMap = ['opened' => 'open', 'closed' => 'closed', 'merged' => 'closed'];
$rawState = $mr['state'] ?? '';
return [
'number' => $mr['iid'] ?? 0,
'title' => $mr['title'] ?? '',
'state' => $stateMap[$rawState] ?? $rawState,
'head' => [
'ref' => $mr['source_branch'] ?? '',
'sha' => $mr['sha'] ?? '',
],
'base' => [
'ref' => $mr['target_branch'] ?? '',
],
];

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.

1 participant