Skip to content

feat: implement getOwnerName for Gitea using repositoryId#72

Merged
Meldiron merged 2 commits intoutopia-php:mainfrom
jaysomani:feat/gitea-owner-name-fix
Mar 20, 2026
Merged

feat: implement getOwnerName for Gitea using repositoryId#72
Meldiron merged 2 commits intoutopia-php:mainfrom
jaysomani:feat/gitea-owner-name-fix

Conversation

@jaysomani
Copy link
Contributor

Overview

Implements getOwnerName() for Gitea adapter to support OAuth tokens that can access multiple organizations.

Changes

Core Implementation

  • Updated abstract method signature in Adapter.php to accept optional repositoryId parameter
  • Implemented Gitea adapter to use /repositories/{id} endpoint to retrieve owner information
  • Updated GitHub adapter to accept (but ignore) the new optional parameter for interface compatibility

Error Handling

  • Returns RepositoryNotFound exception for 404 responses
  • Validates repositoryId parameter (required for Gitea)
  • Proper HTTP status code handling

Tests Added

  • testGetOwnerName() - Success case with valid repository ID
  • testGetOwnerNameWithoutRepositoryId() - Missing parameter validation
  • testGetOwnerNameWithInvalidRepositoryId() - Invalid ID returns RepositoryNotFound
  • testGetOwnerNameWithNullRepositoryId() - Explicit null parameter handling

Why These Changes?

GitHub vs Gitea Architecture:

  • GitHub: Uses installationId to identify a specific GitHub App installation with single owner
  • Gitea: OAuth tokens can access multiple organizations - requires repositoryId to determine owner

All tests passing ✅

- Add optional repositoryId parameter to abstract getOwnerName method
- Update GitHub adapter to accept (but ignore) repositoryId parameter
- Implement Gitea getOwnerName using /repositories/{id} endpoint
- Add comprehensive tests for success and failure cases
- Handle 404 errors with RepositoryNotFound exception
- Resolves Gitea OAuth multi-organization access issue
@greptile-apps
Copy link

greptile-apps bot commented Mar 20, 2026

Greptile Summary

This PR implements getOwnerName() for the Gitea adapter by querying the /repositories/{id} endpoint, replacing the previous throw new Exception("not applicable") stub. The abstract signature in Adapter.php is updated with an optional ?int $repositoryId parameter, and the GitHub adapter is updated for interface compatibility while leaving its existing behavior unchanged.

Key changes:

  • Adapter.php: Abstract getOwnerName gains an optional ?int $repositoryId = null parameter — fully backward-compatible.
  • Gitea.php: New implementation fetches the repo by ID, validates the response, and returns owner.login; handles 404 as RepositoryNotFound and other 4xx errors generically.
  • GitHub.php: Signature updated to accept (and silently ignore) the new $repositoryId parameter.
  • GiteaTest.php: Four new integration tests covering the happy path, missing/null parameter validation, and invalid repository ID.

Minor issues to address:

  • return $owner['login'] ?? '' after an array_key_exists guard is redundant; if the API ever returns "login": null the function silently returns '' rather than throwing.
  • $repositoryId = 0 passes the === null check and would result in an uninformative RepositoryNotFound instead of the explicit validation error.
  • testGetOwnerName is missing a try/finally block, so the created repository will leak if any mid-test assertion fails.

Confidence Score: 4/5

  • This PR is safe to merge; the issues found are style/robustness concerns rather than correctness bugs.
  • The core logic is correct and follows existing patterns in the codebase. The three flagged items (redundant null-coalescing, missing zero-ID guard, and test cleanup gap) are non-critical and do not affect the happy path or any existing functionality.
  • src/VCS/Adapter/Git/Gitea.php (minor robustness issues) and tests/VCS/Adapter/GiteaTest.php (missing cleanup guard)

Important Files Changed

Filename Overview
src/VCS/Adapter.php Abstract method signature updated to add optional ?int $repositoryId = null parameter with improved phpdoc; backward-compatible change.
src/VCS/Adapter/Git/GitHub.php Adds the new optional ?int $repositoryId = null parameter to satisfy the updated abstract signature; parameter is explicitly ignored and behavior is unchanged.
src/VCS/Adapter/Git/Gitea.php Core implementation using Gitea's /repositories/{id} endpoint; minor issues include a redundant ?? '' after an array_key_exists guard (could silently return empty string for a null login), and repositoryId = 0 is not rejected despite being an invalid ID.
tests/VCS/Adapter/GiteaTest.php Four new tests covering success, missing param, invalid ID, and explicit null; testGetOwnerName lacks a try/finally guard so the test repository leaks if any assertion fails before cleanup.

Last reviewed commit: "feat: implement getO..."

Copy link

@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: 4f907fe1ee

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

@Meldiron Meldiron added the test Enables E2E tests in CI/CD label Mar 20, 2026
@Meldiron Meldiron merged commit 2f18162 into utopia-php:main Mar 20, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

test Enables E2E tests in CI/CD

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants