Skip to content

Detect the default branch#306

Merged
5ouma merged 3 commits intomainfrom
feat-libs-default-branch
Sep 27, 2025
Merged

Detect the default branch#306
5ouma merged 3 commits intomainfrom
feat-libs-default-branch

Conversation

@5ouma
Copy link
Owner

@5ouma 5ouma commented Sep 27, 2025

⚠️ Issue

close #301


✏️ Description

The default branch isn't always "master".


Default branch isn't always "master".
If ref is not provided, it will get the default branch.
master should not be hardcoded.
Copilot AI review requested due to automatic review settings September 27, 2025 10:19
@github-actions github-actions bot added 🎉 New Feature A new feature 🧹 Refactoring A code change that neither fixes a bug nor adds a feature labels Sep 27, 2025
@codecov
Copy link

codecov bot commented Sep 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (6e03b89) to head (39f0ec4).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #306   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         6           
  Lines           97       115   +18     
  Branches         6         9    +3     
=========================================
+ Hits            97       115   +18     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This pull request implements dynamic detection of the default branch for GitHub repositories instead of hardcoding "master". It introduces a new getDefaultBranch() function that uses the GitHub API to fetch the actual default branch name, with "master" as a fallback.

  • Adds GitHub API integration to dynamically determine repository default branches
  • Updates redirect logic to be async and use the detected default branch when no ref is specified
  • Removes hardcoded "master" default from getGitHubUrl() function signature

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/libs/utils.ts Adds getDefaultBranch() function and removes default "master" parameter from getGitHubUrl()
src/libs/redirect.ts Updates checkRedirect() to be async and use dynamic default branch detection
src/libs/redirect.test.ts Updates test functions to handle async redirect checking
src/server.test.ts Updates test to use async default branch detection
src/server.ts Makes checkRedirect() call async

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@coderabbitai
Copy link

coderabbitai bot commented Sep 27, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Converted redirect flow to be asynchronous. Added getDefaultBranch utility using Octokit, removed default ref from getGitHubUrl, and updated checkRedirect to resolve ref via provided value or default branch (with optional token). Adjusted server and tests to await async functions and construct URLs with resolved branches.

Changes

Cohort / File(s) Summary of Changes
Libs: Redirect and Utils
src/libs/redirect.ts, src/libs/utils.ts
Made checkRedirect async with signature `(userAgent, repository, ref?, token?) => Promise<URL
Tests
src/libs/redirect.test.ts, src/server.test.ts
Updated tests to await async checkRedirect. Introduced getDefaultBranch in assertions; expected URLs now use getGitHubUrl with resolved default branch. Adjusted parameters (e.g., testRepo.normal/testRef.normal).
Server
src/server.ts
Added await when calling checkRedirect to handle new async behavior; control flow waits for URL resolution before redirect/content handling.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title Check ✅ Passed The title “Detect the default branch” is concise and directly reflects the primary change of replacing the hardcoded “master” branch with logic to detect and use the repository’s actual default branch. It clearly communicates the core purpose of the PR in a single sentence without unnecessary detail.
Linked Issues Check ✅ Passed The PR implements fetching the repository’s actual default branch via getDefaultBranch and updates checkRedirect and tests to use that value instead of the hardcoded “master,” fully satisfying the objectives of issue #301 to detect and use the real default branch.
Out of Scope Changes Check ✅ Passed All modifications—including the new getDefaultBranch function, updates to checkRedirect, and corresponding test adjustments—are directly related to detecting and using the default branch and do not introduce unrelated functionality.
Description Check ✅ Passed The description clearly states that the PR closes issue #301 and that it addresses the incorrect assumption that the default branch is always “master,” which aligns with the changes made. It is directly related to the changeset and explains why the update was necessary.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-libs-default-branch

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 49e9c6a and 39f0ec4.

📒 Files selected for processing (5)
  • src/libs/redirect.test.ts (2 hunks)
  • src/libs/redirect.ts (5 hunks)
  • src/libs/utils.ts (2 hunks)
  • src/server.test.ts (2 hunks)
  • src/server.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (5)
src/libs/redirect.test.ts (3)
src/libs/redirect.ts (2)
  • checkRedirect (70-82)
  • UserAgent (2-2)
src/libs/test_utils.ts (2)
  • testRepo (18-29)
  • testUserAgent (57-57)
src/libs/utils.ts (2)
  • getGitHubUrl (61-75)
  • getDefaultBranch (24-40)
src/libs/utils.ts (3)
src/libs/types.ts (1)
  • Repository (17-21)
src/libs/test_utils.ts (1)
  • exportRepo (76-80)
src/libs/content.ts (1)
  • getContent (63-87)
src/server.ts (1)
src/libs/redirect.ts (1)
  • checkRedirect (70-82)
src/libs/redirect.ts (2)
src/libs/types.ts (1)
  • Repository (17-21)
src/libs/utils.ts (2)
  • getGitHubUrl (61-75)
  • getDefaultBranch (24-40)
src/server.test.ts (2)
src/libs/utils.ts (2)
  • getGitHubUrl (61-75)
  • getDefaultBranch (24-40)
src/libs/test_utils.ts (1)
  • testRepo (18-29)

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.

@5ouma 5ouma merged commit 53ccc00 into main Sep 27, 2025
17 checks passed
@5ouma 5ouma deleted the feat-libs-default-branch branch September 27, 2025 11:24
@5ouma 5ouma bot mentioned this pull request Sep 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🎉 New Feature A new feature 🧹 Refactoring A code change that neither fixes a bug nor adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detect default branch

2 participants