Skip to content

Feat: Git env variables suggestion#10795

Merged
Meldiron merged 5 commits into1.8.xfrom
feat-suggested-env-vars
Nov 14, 2025
Merged

Feat: Git env variables suggestion#10795
Meldiron merged 5 commits into1.8.xfrom
feat-suggested-env-vars

Conversation

@Meldiron
Copy link
Copy Markdown
Contributor

@Meldiron Meldiron commented Nov 10, 2025

What does this PR do?

Adds env variable names suggestions based on .env files in repository

Test Plan

Manual QA:

CleanShot 2025-11-14 at 15 47 10@2x CleanShot 2025-11-14 at 15 46 56@2x

Related PRs and Issues

x

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 10, 2025

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

This pull request adds detection and reporting of environment variables found in .env files, using Swoole coroutines (WaitGroup) to parallelize fetching and parsing in two code paths of app/controllers/api/vcs.php (framework/runtime detection and repository processing). It introduces a new Detection model hierarchy: a Detection abstract model with a variables rule, a DetectionVariable model, and updates Response to register the new model and constant. DetectionFramework and DetectionRuntime now extend Detection. ProviderRepository model gains a variables field. A DNS test value was also changed in tests/unit/Network/Validators/DNSTest.php.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • app/controllers/api/vcs.php: concurrent Swoole coroutine logic (WaitGroup) added in two places — verify concurrency correctness, WaitGroup usage, error handling, race conditions, and duplicate logic consistency.
  • src/Appwrite/Utopia/Response/*: new Detection abstract, DetectionVariable model, Response model registration and constant — verify model wiring, names/types, and examples are correct.
  • src/Appwrite/Utopia/Response/Model/DetectionFramework.php and DetectionRuntime.php: base-class change to Detection and constructor adjustments — ensure no behavioral regressions.
  • src/Appwrite/Utopia/Response/Model/ProviderRepository.php: new variables rule — check schema alignment with Detection/DetectionVariable.
  • tests/unit/Network/Validators/DNSTest.php: changed DNS value — confirm test intent and validity.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The pull request title 'Feat: Git env variables suggestion' clearly relates to the main change of adding environment variable suggestions from .env files in repositories.
Description check ✅ Passed The pull request description 'Adds env variable names suggestions based on .env files in repository' directly describes the changeset's core functionality and includes manual QA screenshots demonstrating the feature.

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.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 10, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
libxml2 2.13.8-r0 CVE-2025-49794 CRITICAL
libxml2 2.13.8-r0 CVE-2025-49796 CRITICAL
libxml2 2.13.8-r0 CVE-2025-49795 HIGH
libxml2 2.13.8-r0 CVE-2025-6021 HIGH
github.com/containerd/containerd/v2 v2.0.2 CVE-2024-25621 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-47907 HIGH
stdlib 1.22.10 CVE-2025-58183 HIGH
stdlib 1.22.10 CVE-2025-58186 HIGH
stdlib 1.22.10 CVE-2025-58187 HIGH
stdlib 1.22.10 CVE-2025-58188 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Copy Markdown
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

♻️ Duplicate comments (1)
app/controllers/api/vcs.php (1)

1183-1195: See earlier comment on Lines 976-988 about decoding the GitHub content before parsing; the same fix is required here.

📜 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 0bf8cea and c784cf9.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • app/controllers/api/vcs.php (3 hunks)
  • src/Appwrite/Utopia/Response/Model/DetectionFramework.php (1 hunks)
  • src/Appwrite/Utopia/Response/Model/DetectionRuntime.php (1 hunks)
  • src/Appwrite/Utopia/Response/Model/ProviderRepository.php (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/Appwrite/Utopia/Response/Model/ProviderRepository.php (1)
src/Appwrite/Utopia/Response/Model.php (1)
  • addRule (90-102)
src/Appwrite/Utopia/Response/Model/DetectionFramework.php (1)
src/Appwrite/Utopia/Response/Model.php (1)
  • addRule (90-102)
src/Appwrite/Utopia/Response/Model/DetectionRuntime.php (1)
src/Appwrite/Utopia/Response/Model.php (1)
  • addRule (90-102)
⏰ 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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Nov 10, 2025

✨ Benchmark results

  • Requests per second: 1,086
  • Requests with 200 status code: 195,458
  • P99 latency: 0.176921176

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 1,086 1,085
200 195,458 195,418
P99 0.176921176 0.189616296

@Meldiron
Copy link
Copy Markdown
Contributor Author

CleanShot 2025-11-10 at 17 19 38@2x Merging 😁

@Meldiron Meldiron marked this pull request as draft November 10, 2025 16:33
@Meldiron Meldiron marked this pull request as ready for review November 14, 2025 14:52
Copy link
Copy Markdown
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: 2

♻️ Duplicate comments (1)
app/controllers/api/vcs.php (1)

17-17: Decode GitHub .env file content before parsing (and treat it as text, not base64)

In both .env-scanning blocks you read the GitHub Contents API content field and split it directly:

$contentResponse = $github->getRepositoryContent(...);
$envFile = $contentResponse['content'] ?? '';
$envLines = \explode("\n", $envFile);

The GitHub Contents API returns content base64‑encoded, so this code parses base64 blobs instead of the actual .env text. That makes all suggested variable names effectively garbage and breaks the feature.

This is the same issue that was already raised in a previous review comment for this file; it still needs to be fixed. A robust pattern for both blocks would be:

-    $envFile = $contentResponse['content'] ?? '';
+    $envFileEncoded = $contentResponse['content'] ?? '';
+    if (empty($envFileEncoded)) {
+        return;
+    }
+
+    $envFile = \base64_decode($envFileEncoded, true);
+    if ($envFile === false) {
+        // Skip invalid content instead of trying to parse it
+        return;
+    }

Then continue with explode("\n", $envFile) on the decoded string. Please apply this in both the detection endpoint block and the repositories listing block.

Also applies to: 968-1005, 1182-1217

🧹 Nitpick comments (2)
src/Appwrite/Utopia/Response/Model/Detection.php (1)

8-21: Shared variables rule looks correct

The shared variables rule (array of MODEL_DETECTION_VARIABLE) is wired correctly for Detection-based models, and the subclasses’ parent::__construct() calls will ensure it’s always present. Note that with required => false the default value isn’t used by Response::output(), but that’s a harmless no-op.

app/controllers/api/vcs.php (1)

968-1005: Promote .env variables to proper DetectionVariable documents and de-duplicate parsing logic

Two smaller structural points:

  1. Use Document for variables to leverage model validation

    The Detection models define variables as type => MODEL_DETECTION_VARIABLE, array => true, but here you push plain arrays. If you instead wrap each variable as a Document before calling dynamic()/output(), you’ll get consistent filtering and defaults from the DetectionVariable model:

  •    $variables[] = [
    
  •        'name'  => $key,
    
  •        'value' => $value,
    
  •    ];
    
  •    $variables[] = new Document([
    
  •        'name'  => $key,
    
  •        'value' => $value,
    
  •    ]);
    
    
    Same idea for `$repo['variables']`.
    
    
  1. Extract shared .env parsing into a helper

    The two env blocks are almost identical. A small private helper (or even a closure above) that takes $github, repo coordinates, and returns the variables array would reduce duplication and keep behavior consistent if you tweak parsing later.

These are not blockers but would improve maintainability and data consistency.

Also applies to: 1182-1217

📜 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 831a261 and db1b87e.

📒 Files selected for processing (6)
  • app/controllers/api/vcs.php (3 hunks)
  • src/Appwrite/Utopia/Response.php (3 hunks)
  • src/Appwrite/Utopia/Response/Model/Detection.php (1 hunks)
  • src/Appwrite/Utopia/Response/Model/DetectionFramework.php (1 hunks)
  • src/Appwrite/Utopia/Response/Model/DetectionRuntime.php (1 hunks)
  • src/Appwrite/Utopia/Response/Model/DetectionVariable.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Appwrite/Utopia/Response/Model/DetectionRuntime.php
🧰 Additional context used
🧬 Code graph analysis (4)
src/Appwrite/Utopia/Response/Model/DetectionVariable.php (3)
src/Appwrite/Utopia/Response.php (2)
  • Response (159-983)
  • __construct (428-632)
src/Appwrite/Utopia/Response/Model.php (2)
  • Model (7-192)
  • addRule (90-102)
src/Appwrite/Utopia/Response/Model/Detection.php (1)
  • __construct (10-21)
src/Appwrite/Utopia/Response/Model/Detection.php (5)
src/Appwrite/Utopia/Response.php (2)
  • Response (159-983)
  • __construct (428-632)
src/Appwrite/Utopia/Response/Model.php (2)
  • Model (7-192)
  • addRule (90-102)
src/Appwrite/Utopia/Response/Model/DetectionFramework.php (1)
  • __construct (9-38)
src/Appwrite/Utopia/Response/Model/DetectionRuntime.php (1)
  • __construct (9-32)
src/Appwrite/Utopia/Response/Model/DetectionVariable.php (1)
  • __construct (10-25)
src/Appwrite/Utopia/Response/Model/DetectionFramework.php (2)
src/Appwrite/Utopia/Response/Model/Detection.php (2)
  • Detection (8-22)
  • __construct (10-21)
src/Appwrite/Utopia/Response/Model/DetectionRuntime.php (1)
  • __construct (9-32)
src/Appwrite/Utopia/Response.php (2)
src/Appwrite/Utopia/Response/Model.php (1)
  • Model (7-192)
src/Appwrite/Utopia/Response/Model/DetectionVariable.php (1)
  • DetectionVariable (8-46)
🔇 Additional comments (2)
src/Appwrite/Utopia/Response/Model/DetectionFramework.php (1)

7-12: Detection now correctly shares the common variables rule

Extending Detection and calling parent::__construct() cleanly reuses the shared variables rule without changing existing framework fields. Looks good.

src/Appwrite/Utopia/Response.php (1)

62-63: DetectionVariable model is correctly registered in the response registry

The import, MODEL_DETECTION_VARIABLE constant, and setModel(new DetectionVariable()) hook cleanly into the existing model registry and follow the established pattern for other VCS-related models.

Also applies to: 320-321, 568-569

@Meldiron Meldiron merged commit deb5039 into 1.8.x Nov 14, 2025
130 of 133 checks passed
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.

2 participants