feat(gitlab): add getPullRequest, getPullRequestFiles, getPullRequestFromBranch, createComment, getComment, updateComment and getUser#94
Conversation
Greptile SummaryThis PR completes the GitLab adapter by implementing
Confidence Score: 3/5The 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
Reviews (7): Last reviewed commit: "Merge branch 'utopia-php:main' into feat..." | Re-trigger Greptile |
There was a problem hiding this comment.
💡 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".
There was a problem hiding this comment.
💡 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".
…lab-adapter-pullrequest
| // 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'] ?? '', | ||
| ], | ||
| ]; |
There was a problem hiding this comment.
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.
| // 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'] ?? '', | |
| ], | |
| ]; |
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 shapegetPullRequestFiles— fetches changed files using/diffsendpoint withpatch_id_shapolling to handle GitLab's async diff processinggetPullRequestFromBranch— finds an open merge request by source branchcreateComment— creates a note on a merge request via GitLab notes APIgetComment— retrieves a note by ID, searching across all MRs in the repositoryupdateComment— updates an existing note by IDgetUser— fetches a user by username via GitLab users search APITests added
testGetEventPushMatchesCheckoutSha,testValidateWebhookEventUsesPlainToken,testCreateOrganizationtestGetUser,testGetUserWithInvalidUsername,testCreatePrivateRepository,testGetRepositoryWithNonExistingOwner,testCreateRepositoryWithInvalidName,testDeleteRepositoryTwiceFails,testDeleteNonExistingRepositoryFails,testGetPullRequestFromBranchNoPR,testCreateCommentInvalidPR,testGetCommentInvalidIdNotes
getCommentandupdateCommentsearch across all MRs to find the note by ID since the MR iid is not stored with the comment IDgetPullRequestFilesusespatch_id_shapolling per GitLab's official documentation recommendation for async diff processinggetUserreturnsusernamefield (notloginlike Gitea/GitHub) — this is a GitLab API differencefeat/gitlab-adapter-webhooksand will need a rebase once that PR merges