Skip to content

Feat/normalize adapter behavior#108

Open
jaysomani wants to merge 11 commits into
utopia-php:mainfrom
jaysomani:feat/normalize-adapter-behavior
Open

Feat/normalize adapter behavior#108
jaysomani wants to merge 11 commits into
utopia-php:mainfrom
jaysomani:feat/normalize-adapter-behavior

Conversation

@jaysomani
Copy link
Copy Markdown
Contributor

@jaysomani jaysomani commented Jun 1, 2026

Normalizes adapter behavior to enable shared Base tests:
Adapter fixes:

GitLab::searchRepositories — was returning flat array, now returns {items, total} consistent with Gitea/GitHub
GitLab::searchRepositories — was returning [] for invalid owner, now returns {items: [], total: 0}
GitHub::searchRepositories — was throwing for invalid owner, now returns empty results
GitHub::updateCommitStatus — was silently ignoring API errors, now throws on failure

Tests moved to Base:

testUpdateCommitStatusWithInvalidCommit
testUpdateCommitStatusWithNonExistingRepository
testSearchRepositoriesNoResults
testSearchRepositoriesInvalidOwner

Depends on: feat/unified-base-tests

@jaysomani jaysomani marked this pull request as ready for review June 1, 2026 07:58
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: 6fb650bac0

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

$this->markTestSkipped('GitHub adapter does not support getUser by username');
}

public function testGetOwnerName(): void
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Remove duplicate GitHub owner-name test

This adds a second testGetOwnerName() method to GitHubTest while the same method already exists earlier in the class, so PHP cannot even load the test file (php -l tests/VCS/Adapter/GitHubTest.php reports Cannot redeclare Utopia\Tests\Adapter\GitHubTest::testGetOwnerName()). Any PHPUnit run that includes this file will fail before executing tests until one of the duplicate methods is removed or renamed.

Useful? React with 👍 / 👎.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Jun 1, 2026

Greptile Summary

This PR normalizes adapter behavior across GitHub and GitLab to enable shared base integration tests. It fixes GitLab::searchRepositories to return a {items, total} struct, fixes GitHub::updateCommitStatus to throw on HTTP errors instead of silently succeeding, and consolidates ~400 lines of duplicated per-adapter test code into a shared Base test class.

  • GitHub::updateCommitStatus now captures the HTTP response and throws on status ≥ 400, fixing a long-standing silent failure.
  • GitLab::searchRepositories now returns ['items' => ..., 'total' => ...] consistently; getOwnerName removes the /user endpoint fallback for null repositoryId, which is a behavioral breaking change not called out in the description.
  • Docker-compose default usernames changed from utopia to root for Gitea/Forgejo/Gogs to align with the base test's getUser('root') assertion.

Confidence Score: 4/5

The core adapter fixes are correct and the shared test infrastructure is well-structured; two localized inconsistencies in error handling are worth addressing before merge.

The updateCommitStatus and searchRepositories normalization changes are straightforward and well-tested. The main concerns are a missed third throw-site in GitHub's paginated search loop, and the removal of GitLab's /user fallback in getOwnerName without any mention in the PR description.

src/VCS/Adapter/Git/GitHub.php (paginated search path still throws on unexpected response) and src/VCS/Adapter/Git/GitLab.php (null-repositoryId path in getOwnerName silently removed).

Important Files Changed

Filename Overview
src/VCS/Adapter/Git/GitHub.php Fixes silent error swallowing in updateCommitStatus (now throws on HTTP ≥ 400) and normalizes two searchRepositories paths to return empty instead of throwing; the third paginated path still throws inconsistently.
src/VCS/Adapter/Git/GitLab.php Fixes searchRepositories to return {items, total} struct and normalizes error returns; getOwnerName removes the /user fallback when $repositoryId is null, which is a behavioural breaking change.
tests/VCS/Base.php New shared base test class consolidating common adapter tests including testUpdateCommitStatusWithInvalidCommit, testSearchRepositoriesNoResults, and testSearchRepositoriesInvalidOwner.
tests/VCS/Adapter/GitHubTest.php Refactored to extend Base; moves many tests to base class, adds adapter-specific skips for getUser/getOwnerName, removes previously redundant test methods.
tests/VCS/Adapter/GitLabTest.php Refactored to extend Base; removes many GitLab-specific tests now covered by the base class; updates testSearchRepositories assertions to reflect the new {items, total} shape.
tests/VCS/Adapter/GiteaTest.php Migrated to setupAdapter() pattern; removes duplicate tests now inherited from Base; Gitea-specific tests retained.
tests/VCS/Adapter/ForgejoTest.php Small migration to setupAdapter() pattern, removing createVCSAdapter().
tests/VCS/Adapter/GogsTest.php Large cleanup removing many per-adapter duplicate tests now covered by Base; migrates to setupAdapter() pattern.
docker-compose.yml Changes the default admin usernames for Gitea, Forgejo, and Gogs from utopia to root to align with shared base test expectations.

Comments Outside Diff (1)

  1. src/VCS/Adapter/Git/GitHub.php, line 277-279 (link)

    P2 Inconsistent error handling in paginated search path

    The PR normalizes two of the three searchRepositories code paths to return ['items' => [], 'total' => 0] instead of throwing when the expected key is missing, but the paginated loop (used when !hasAccessToAllRepositories() and !empty($search)) still throws "Repositories list missing in the response.". If a GitHub API error or unexpected response occurs during pagination, this path throws while the other two now silently return empty — making the behaviour dependent on which code path is exercised.

Reviews (1): Last reviewed commit: "Merge branch 'main' into feat/normalize-..." | Re-trigger Greptile

Comment on lines +561 to 563
if ($repositoryId === null || $repositoryId <= 0) {
throw new Exception("repositoryId is required for this adapter");
}
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.

P2 Silent breaking change: removal of the /user fallback in getOwnerName

The previous implementation fell back to GET /user when $repositoryId was null, allowing callers to resolve the current authenticated user's namespace without a repository ID. That code path is now replaced with an unconditional exception. Any existing call site that relied on getOwnerName($installationId) without a $repositoryId will fail at runtime with no compile-time warning. The change is intentional based on the test removal, but there is no deprecation notice or migration path in the PR description.

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.

This is intentional. The previous fallback to GET /user was returning the authenticated username rather than the repository owner/namespace — semantically incorrect behavior. All internal call sites within Appwrite pass a repositoryId. External callers relying on the old fallback should update to pass a valid repositoryId. The PR description has been updated to document this breaking change.

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