Skip to content

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

Open
jaysomani wants to merge 7 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 7 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 (with patch_id_sha async polling), getPullRequestFromBranch, createComment/getComment/updateComment (using a composite mrIid:noteId key), and getUser. It also widens the abstract updateComment signature from int to string across the base class and the GitHub/Gitea adapters.

  • Composite comment keycreateComment now returns \"mrIid:noteId\", and getComment/updateComment parse that prefix to go directly to the correct MR's notes endpoint, removing the need to scan all MRs and resolving the pagination gap noted in earlier reviews.
  • Integration tests — previously skipped test stubs are replaced with fully implemented tests, including testGetUser, testGetPullRequest, testGetPullRequestFiles, and the full comment lifecycle.
  • Signature changeupdateComment's $commentId widened from int to string to support composite keys; callers previously casting to int are updated to string.

Confidence Score: 4/5

Safe to merge with one minor fix recommended in the getPullRequestFiles polling loop.

The new methods are well-structured and the composite comment-key approach cleanly resolves the previous MR-scan pagination gap. The one open issue is the missing HTTP status check inside the getPullRequestFiles polling loop — a non-existent PR number causes the loop to exhaust all 10 attempts before an exception is finally raised from the diffs fetch, with a less informative error message. All previously skipped tests are now implemented.

src/VCS/Adapter/Git/GitLab.php — specifically the patch_id_sha polling loop in getPullRequestFiles

Important Files Changed

Filename Overview
src/VCS/Adapter/Git/GitLab.php Implements getPullRequest, getPullRequestFiles (with async poll), getPullRequestFromBranch, createComment (composite key), getComment, updateComment, and getUser; poll loop in getPullRequestFiles lacks an HTTP-status guard during polling
src/VCS/Adapter.php Abstract updateComment signature widened from int to string commentId to support GitLab composite key format
src/VCS/Adapter/Git/GitHub.php updateComment parameter type updated to string to match the new abstract signature; no logic change
src/VCS/Adapter/Git/Gitea.php updateComment parameter type updated to string to match the new abstract signature; no logic change
tests/VCS/Adapter/GitLabTest.php Full integration tests added for all new methods; previously skipped stubs are now properly implemented
tests/VCS/Adapter/GiteaTest.php Cast updated from (int)$commentId to (string)$commentId to align with the widened abstract signature

Reviews (6): Last reviewed commit: "updated the ID fix for comments" | 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
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