Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Shorten commit url and branch url #9919

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 28, 2025
Merged

Shorten commit url and branch url #9919

merged 5 commits into from
May 28, 2025

Conversation

vermakhushboo
Copy link
Member

@vermakhushboo vermakhushboo commented May 28, 2025

What does this PR do?

Shorten commit url by truncating commit hash to 16 chars

Shorten the branch url by following this rule:

  1. Take first 16 chars of branch name
  2. If longer, hash the remaining chars and take first 7 chars of hash
  3. Hash concatenation of resourceId and projectId and take first 7 chars
  4. Append site domain

Test Plan

(Write your test plan here. If you changed any code, please provide us with clear instructions on how you verified your changes work. Screenshots may also be helpful.)

Related PRs and Issues

  • (Related PR or issue)

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?

Summary by CodeRabbit

  • Refactor
    • Updated domain naming for VCS branch and commit previews in site deployments to use shortened and partially hashed formats, enhancing domain uniqueness and consistency while preserving existing functionality.

@vermakhushboo vermakhushboo requested a review from Meldiron May 28, 2025 07:22
Copy link

coderabbitai bot commented May 28, 2025

"""

Walkthrough

The logic for generating domain names for VCS branch and commit previews in site deployments was updated. Branch names are truncated to 16 characters with a hash suffix if longer, and a hash of resource and project IDs is appended. Commit hashes are truncated to 16 characters. Domain formats and rule ID calculations were revised accordingly.

Changes

File(s) Change Summary
app/controllers/api/vcs.php
src/Appwrite/Platform/Modules/Functions/Workers/Builds.php
Updated domain name generation for VCS branch and commit previews: truncates branch and commit hashes, appends short hashes, changes domain format, and adjusts rule ID calculation.

Suggested reviewers

  • christyjacob4

Poem

In the warren, code hops anew,
Branch names trimmed, with hashes too.
Commits shortened, domains refined,
Clever names that are well-defined.
No more long tails in the breeze—
Just clever names that hop with ease.
🐇✨
"""


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 707ef16 and 814abdd.

📒 Files selected for processing (1)
  • app/controllers/api/vcs.php (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/controllers/api/vcs.php
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

github-actions bot commented May 28, 2025

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
binutils 2.42-r0 CVE-2025-0840 HIGH
libexpat 2.6.4-r0 CVE-2024-8176 HIGH
libxml2 2.12.7-r0 CVE-2024-56171 HIGH
libxml2 2.12.7-r0 CVE-2025-24928 HIGH
libxml2 2.12.7-r0 CVE-2025-27113 HIGH
libxml2 2.12.7-r0 CVE-2025-32414 HIGH
libxml2 2.12.7-r0 CVE-2025-32415 HIGH
sqlite-libs 3.45.3-r1 CVE-2025-29087 HIGH
xz 5.6.2-r0 CVE-2025-31115 HIGH
xz-libs 5.6.2-r0 CVE-2025-31115 HIGH
golang.org/x/crypto v0.31.0 CVE-2025-22869 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link

@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

🧹 Nitpick comments (1)
app/controllers/api/vcs.php (1)

296-302: LGTM! Implementation correctly follows the PR requirements.

The URL shortening logic is properly implemented according to the specifications:

  • Truncates branch names to 16 characters
  • Hashes excess characters and appends 7-character prefix
  • Creates separate 7-character hash from resource/project IDs
  • Constructs the final domain correctly

Consider adding validation to ensure branch names are domain-safe:

 $branchPrefix = substr($providerBranch, 0, 16);
+// Sanitize branch name for domain compatibility
+$branchPrefix = preg_replace('/[^a-z0-9-]/', '-', strtolower($branchPrefix));
 if (strlen($providerBranch) > 16) {
     $remainingChars = substr($providerBranch, 16);
     $branchPrefix .= substr(hash('sha256', $remainingChars), 0, 7);
 }

Also consider documenting the 7-character hash length choice, as it provides ~268M combinations which should be sufficient but could theoretically lead to collisions in very large deployments.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 340211e and 320bf69.

⛔ Files ignored due to path filters (1)
  • composer.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • app/controllers/api/vcs.php (1 hunks)
  • src/Appwrite/Platform/Modules/Functions/Workers/Builds.php (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: Setup & Build Appwrite Image
  • GitHub Check: scan
🔇 Additional comments (2)
src/Appwrite/Platform/Modules/Functions/Workers/Builds.php (2)

1137-1139: The hash concatenation logic is correct.

The conditional logic properly handles branch names longer than 16 characters by hashing the remainder and appending a 7-character suffix. This maintains deterministic behavior while keeping domain lengths manageable.


1135-1141:

✅ Verification successful

Verify consistency with parallel changes in the codebase.

The AI summary mentions a parallel update in app/controllers/api/vcs.php for VCS branch preview domain generation. Ensure both implementations use identical logic to prevent inconsistencies.


🏁 Script executed:

#!/bin/bash
# Description: Search for domain generation logic in VCS-related files to ensure consistency
# Expected: Find similar domain generation patterns that should match this implementation

# Search for domain generation patterns in VCS files
ast-grep --pattern 'branch-$_.$_'

# Search for branch prefix generation patterns
rg -A 10 -B 5 "branchPrefix|branch.*substr|substr.*branch"

# Search for resourceProjectHash patterns
rg -A 5 -B 5 "resourceProjectHash|resource.*project.*hash"

Length of output: 7070


Branch preview domain logic is consistent across both modules

I’ve confirmed that both src/Appwrite/Platform/Modules/Functions/Workers/Builds.php and app/controllers/api/vcs.php use identical substring and SHA-256 hashing steps for branchPrefix, resourceProjectHash, and the final "branch-{$branchPrefix}{$resourceProjectHash}.{$sitesDomain}" domain format. No further changes are needed.

Comment on lines 1135 to 1141
$branchPrefix = substr($branchName, 0, 16);
if (strlen($branchName) > 16) {
$remainingChars = substr($branchName, 16);
$branchPrefix .= substr(hash('sha256', $remainingChars), 0, 7);
}
$resourceProjectHash = substr(hash('sha256', $resource->getId() . $project->getId()), 0, 7);
$domain = "branch-{$branchPrefix}{$resourceProjectHash}.{$sitesDomain}";
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider domain name validation and character sanitization.

The new domain generation logic correctly implements the shortening mechanism, but there are several considerations:

  1. Domain character validation: Branch names may contain characters not valid in domain names (underscores, special characters, spaces, etc.)
  2. Collision risk: 7-character hashes have a small but non-zero collision probability
  3. Edge cases: No handling for empty branch names or very short names

Consider adding validation and sanitization:

 $sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
+// Sanitize branch name for domain usage
+$sanitizedBranchName = preg_replace('/[^a-z0-9-]/', '-', strtolower($branchName));
+$sanitizedBranchName = trim($sanitizedBranchName, '-');
+
+if (empty($sanitizedBranchName)) {
+    throw new \Exception('Invalid branch name for domain generation');
+}
+
-$branchPrefix = substr($branchName, 0, 16);
+$branchPrefix = substr($sanitizedBranchName, 0, 16);
 if (strlen($branchName) > 16) {
     $remainingChars = substr($branchName, 16);
     $branchPrefix .= substr(hash('sha256', $remainingChars), 0, 7);
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
$branchPrefix = substr($branchName, 0, 16);
if (strlen($branchName) > 16) {
$remainingChars = substr($branchName, 16);
$branchPrefix .= substr(hash('sha256', $remainingChars), 0, 7);
}
$resourceProjectHash = substr(hash('sha256', $resource->getId() . $project->getId()), 0, 7);
$domain = "branch-{$branchPrefix}{$resourceProjectHash}.{$sitesDomain}";
// Fetch the sites domain
$sitesDomain = System::getEnv('_APP_DOMAIN_SITES', '');
// Sanitize branch name for domain usage
$sanitizedBranchName = preg_replace('/[^a-z0-9-]/', '-', strtolower($branchName));
$sanitizedBranchName = trim($sanitizedBranchName, '-');
if (empty($sanitizedBranchName)) {
throw new \Exception('Invalid branch name for domain generation');
}
// Build the branch prefix (truncate and hash remainder if too long)
$branchPrefix = substr($sanitizedBranchName, 0, 16);
if (strlen($branchName) > 16) {
$remainingChars = substr($branchName, 16);
$branchPrefix .= substr(hash('sha256', $remainingChars), 0, 7);
}
$resourceProjectHash = substr(hash('sha256', $resource->getId() . $project->getId()), 0, 7);
$domain = "branch-{$branchPrefix}{$resourceProjectHash}.{$sitesDomain}";
🤖 Prompt for AI Agents
In src/Appwrite/Platform/Modules/Functions/Workers/Builds.php around lines 1135
to 1141, the domain name generation uses branch names directly without
sanitizing invalid domain characters or handling empty/short branch names. To
fix this, sanitize the branchName by removing or replacing characters not
allowed in domain names (e.g., spaces, underscores, special characters), add
validation to handle empty or very short branch names by providing a default or
fallback value, and consider increasing hash length or adding a collision check
to reduce collision risk. Implement these checks before constructing the final
domain string.

Copy link

github-actions bot commented May 28, 2025

✨ Benchmark results

  • Requests per second: 849
  • Requests with 200 status code: 152,878
  • P99 latency: 0.223001914

⚡ Benchmark Comparison

Metric This PR Latest version
RPS 849 1,025
200 152,878 184,621
P99 0.223001914 0.184896398

app/controllers/api/vcs.php Outdated Show resolved Hide resolved
src/Appwrite/Platform/Modules/Functions/Workers/Builds.php Outdated Show resolved Hide resolved
vermakhushboo and others added 3 commits May 28, 2025 14:01
Co-authored-by: Matej Bačo <matejbacocom@gmail.com>
Co-authored-by: Matej Bačo <matejbacocom@gmail.com>
@vermakhushboo vermakhushboo changed the title Shorten commit url Shorten commit url and branch url May 28, 2025
@Meldiron Meldiron merged commit af6499b into 1.7.x May 28, 2025
38 checks passed
This was referenced May 29, 2025
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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.