E54A fix external VCS deployment flow by hmacr · Pull Request #10555 · appwrite/appwrite · GitHub
[go: up one dir, main page]

Skip to content

Conversation

hmacr
Copy link
@hmacr hmacr commented Sep 26, 2025
  • Fix the E2E flow
  • Change the commit status from "failed" to "waiting/pending" until authorization is accepted.

Related task: https://linear.app/appwrite/issue/SER-355/fix-external-vcs-deployments

Copy link
Contributor
coderabbitai bot commented Sep 26, 2025
📝 Walkthrough

Walkthrough

  • Sets commentStatus to 'waiting' unconditionally.
  • Changes external/unauthorized commit status from 'failure' to 'pending'.
  • Removes retrieval of PR details when external is true and removes repository fetch filtered by projectInternalId; now uses getDocument('repositories', $repositoryId).
  • On PR flow, derives repository owner/name, branch URL, commit hash, and fetches commit details (message, URL, author name, author URL) from provider APIs.
  • Expands createGitDeployments to accept additional metadata: branch URL, repository name/URL/owner, commit hash/author/author URL/message/URL, and PR ID.
  • Populates deployment data with enriched PR and commit details.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • Meldiron

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly describes the primary objective of the changes by indicating a fix to the external VCS deployment flow, which aligns directly with the code modifications to the external/unauthorized path and commit status handling described in the PR.
Description Check ✅ Passed The description clearly references the updates to the end-to-end flow and the change of commit status from failure to pending, which directly corresponds to the modifications in the pull request and is therefore on topic.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch hmacr/ser-355

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
libexpat 2.7.1-r0 CVE-2025-59375 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH
golang.org/x/oauth2 v0.24.0 CVE-2025-22868 HIGH
stdlib 1.22.10 CVE-2025-47906 HIGH
stdlib 1.22.10 CVE-2025-47907 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
app/controllers/api/vcs.php (2)

1621-1626: Repository scoping check removed — reintroduce project/installation guard.

Fetching the repository by ID without verifying it belongs to the current project/installation (and using Authorization::skip) is an authorization footgun. A caller with a valid repo ID could affect another project’s repo.

Apply this diff to enforce scoping:

-        $repository = Authorization::skip(fn () => $dbForPlatform->getDocument('repositories', $repositoryId));
-
-        if ($repository->isEmpty()) {
-            throw new Exception(Exception::REPOSITORY_NOT_FOUND);
-        }
+        $repository = Authorization::skip(fn () => $dbForPlatform->getDocument('repositories', $repositoryId));
+
+        if (
+            $repository->isEmpty()
+            || $repository->getAttribute('projectInternalId') !== $project->getSequence()
+            || $repository->getAttribute('installationInternalId') !== $installation->getSequence()
+        ) {
+            throw new Exception(Exception::REPOSITORY_NOT_FOUND);
+        }

1396-1399: Gracefully handle commit fetch failures in PR webhook path.

A missing commit (e.g., forked PR) will throw and fail the webhook. Degrade to empty details.

Apply this diff:

-                    $commitDetails = $github->getCommit($providerRepositoryOwner, $providerRepositoryName, $providerCommitHash);
+                    try {
+                        $commitDetails = $github->getCommit($providerRepositoryOwner, $providerRepositoryName, $providerCommitHash);
+                    } catch (\Throwable $e) {
+                        $commitDetails = [];
+                    }
🧹 Nitpick comments (2)
app/controllers/api/vcs.php (2)

1659-1661: Avoid Undefined offset notices when parsing branch; use head.ref and URL-encode.

Parsing label via explode risks notices; GitHub payload includes head.ref.

Apply this diff:

-        $providerBranch = \explode(':', $pullRequestResponse['head']['label'])[1] ?? '';
-        $providerBranchUrl = "$providerRepositoryUrl/tree/$providerBranch";
+        $providerBranch = $pullRequestResponse['head']['ref'] ?? '';
+        $providerBranchUrl = sprintf('%s/tree/%s', $providerRepositoryUrl, \rawurlencode($providerBranch));

160-171: Don’t mutate the lock key used for cleanup.

After updateComment, $latestCommentId is reassigned; deleting the lock with a mutated value risks leaving stale locks. Keep a stable $lockId.

Apply this diff in both lock sections:

-                    if ($lockAcquired) {
+                    if ($lockAcquired) {
+                        $lockId = $latestCommentId;
                         // Wrap in try/finally to ensure lock file gets deleted
                         try {
                             $comment = new Comment();
                             $comment->parseComment($github->getComment($owner, $repositoryName, $latestCommentId));
                             $comment->addBuild($project, $resource, $resourceType, $commentStatus, $deploymentId, $action, '');
 
                             $latestCommentId = \strval($github->updateComment($owner, $repositoryName, $latestCommentId, $comment->generateComment()));
                         } finally {
-                            $dbForPlatform->deleteDocument('vcsCommentLocks', $latestCommentId);
+                            $dbForPlatform->deleteDocument('vcsCommentLocks', $lockId);
                         }
                     }

And similarly for the branch comments block.

Also applies to: 231-242

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf92c25 and 1a0b1da.

📒 Files selected for processing (1)
  • app/controllers/api/vcs.php (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
app/controllers/api/vcs.php (2)
src/Appwrite/Extend/Exception.php (1)
  • Exception (7-447)
app/realtime.php (1)
  • getProjectDB (76-122)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (3)
app/controllers/api/vcs.php (3)

119-119: Setting comment status to 'waiting' is aligned with PR goal.

This keeps PR comments in a pending state until authorization completes. LGTM.


262-263: Change commit status to 'pending' for unauthorized externals — good fix.

Switching from failure to pending prevents false negatives before authorization. LGTM.


1349-1349: All createGitDeployments calls updated to new signature Verified three call sites in app/controllers/api/vcs.php (lines 1349, 1405, 1669); no other references found.

Copy link

✨ Benchmark results

  • Requests per second: 1,243
  • Requests with 200 status code: 223,815
  • P99 latency: 0.157507526

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,243 973
200 223,815 175,199
P99 0.157507526 0.199915154

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
0