Skip to content

but-forge: Improve forge determination#12564

Merged
estib-vega merged 2 commits into
masterfrom
improve-forge-detection
Feb 24, 2026
Merged

but-forge: Improve forge determination#12564
estib-vega merged 2 commits into
masterfrom
improve-forge-detection

Conversation

@estib-vega

Copy link
Copy Markdown
Contributor

Try to determine the forge type for a given URL, by matching it naively
(as we were always doing) and fallback to matching it to the custom
hosts for the self-hosted or enterprise accounts.

Copilot AI review requested due to automatic review settings February 24, 2026 11:54
@vercel

vercel Bot commented Feb 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
gitbutler-web Ignored Ignored Preview Feb 24, 2026 0:44am

Request Review

@github-actions github-actions Bot added the rust Pull requests that update Rust code label Feb 24, 2026
@estib-vega
estib-vega force-pushed the improve-forge-detection branch from d343be2 to abb2b46 Compare February 24, 2026 11:56
@estib-vega
estib-vega enabled auto-merge February 24, 2026 11:56
@estib-vega
estib-vega disabled auto-merge February 24, 2026 11:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves forge type determination in but-forge by adding a fallback mechanism that matches repository hosts against custom hosts from configured forge accounts. Previously, the system only used naive string matching against well-known forge domains (github.com, gitlab.com, etc.). Now, if that fails, it checks if any configured GitHub Enterprise or GitLab Self-Hosted account has a custom host that matches the repository URL.

Changes:

  • Added custom_host() methods to GitHub and GitLab account identifiers to retrieve custom forge hosts
  • Implemented host normalization and matching logic to compare repository hosts with account custom hosts, including subdomain matching
  • Added comprehensive test coverage for the new matching behavior

Reviewed changes

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

Show a summary per file
File Description
crates/but-github/src/token.rs Added custom_host() method to retrieve the host for GitHub Enterprise accounts
crates/but-gitlab/src/token.rs Added custom_host() method to retrieve the host for GitLab Self-Hosted accounts
crates/but-forge/src/lib.rs Implemented forge determination fallback with host matching logic, normalization, and account loading; added comprehensive tests
crates/but-forge/Cargo.toml Added but-path dependency for accessing app data directory
Cargo.lock Updated to include the new but-path dependency

Comment thread crates/but-forge/src/lib.rs Outdated
Comment thread crates/but-forge/src/lib.rs
Comment thread crates/but-forge/src/lib.rs Outdated
Comment thread crates/but-forge/src/lib.rs

Copilot AI commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

@estib-vega I've opened a new pull request, #12567, to work on those changes. Once the pull request is ready, I'll request review from you.

@estib-vega
estib-vega force-pushed the improve-forge-detection branch from abb2b46 to 8152867 Compare February 24, 2026 12:12
@estib-vega
estib-vega enabled auto-merge February 24, 2026 12:12
Copilot AI review requested due to automatic review settings February 24, 2026 12:15
@estib-vega
estib-vega force-pushed the improve-forge-detection branch from 8152867 to 9c1df49 Compare February 24, 2026 12:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

};

let forge_repo_info = but_forge::derive_forge_repo_info(&remote_url);
let forge_accounts = but_forge::get_all_forge_accounts()?;

Copilot AI Feb 24, 2026

Copy link

Choose a reason for hiding this comment

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

The new implementation introduces error-prone behavior. If get_all_forge_accounts() fails (due to storage issues, permissions, or other errors), the entire target_to_base_branch function will fail, which breaks get_base_branch_data and all its callers (20+ locations). Previously, derive_forge_repo_info would simply return None if forge detection failed, allowing operations to continue. Consider wrapping the call in .unwrap_or_default() or logging and continuing with an empty accounts list to maintain backward compatibility.

Suggested change
let forge_accounts = but_forge::get_all_forge_accounts()?;
let forge_accounts = but_forge::get_all_forge_accounts().unwrap_or_default();

Copilot uses AI. Check for mistakes.
Comment on lines +123 to +132
pub fn get_all_forge_accounts() -> anyhow::Result<Vec<ForgeUser>> {
if let Ok(handle) = tokio::runtime::Handle::try_current() {
tokio::task::block_in_place(|| handle.block_on(get_all_forge_accounts_async()))
} else {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()?;
runtime.block_on(get_all_forge_accounts_async())
}
}

Copilot AI Feb 24, 2026

Copy link

Choose a reason for hiding this comment

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

This function is called on every invocation of target_to_base_branch, which is used in multiple hot paths including get_base_branch_data (20+ call sites). Each call creates/blocks on a tokio runtime and performs storage I/O to load accounts. Consider caching the accounts list or passing it as a parameter from callers that already have it, to avoid repeated storage access overhead.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is actually true.

A better fix would be to completely separate the base branch data from the forge information.
I'll create a third function that simply takes the base branch data and returns the forge information.

This will require changes in the FE.

Comment thread crates/but-forge/src/lib.rs
Comment on lines +140 to +147
for gh_account in gh_accounts {
forge_users.push(ForgeUser::GitHub(gh_account));
}

for gl_account in gl_accounts {
forge_users.push(ForgeUser::GitLab(gl_account));
}

Copilot AI Feb 24, 2026

Copy link

Choose a reason for hiding this comment

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

The vector construction can be simplified using extend. Replace the explicit loops with: forge_users.extend(gh_accounts.into_iter().map(ForgeUser::GitHub)); and forge_users.extend(gl_accounts.into_iter().map(ForgeUser::GitLab)); for more idiomatic Rust.

Suggested change
for gh_account in gh_accounts {
forge_users.push(ForgeUser::GitHub(gh_account));
}
for gl_account in gl_accounts {
forge_users.push(ForgeUser::GitLab(gl_account));
}
forge_users.extend(gh_accounts.into_iter().map(ForgeUser::GitHub));
forge_users.extend(gl_accounts.into_iter().map(ForgeUser::GitLab));

Copilot uses AI. Check for mistakes.
@estib-vega
estib-vega force-pushed the improve-forge-detection branch from 9c1df49 to 6beb6b0 Compare February 24, 2026 12:38
Old GitHub secrets can now stop being migrated.
Try to determine the forge type for a given URL, by matching it naively
(as we were always doing) and fallback to matching it to the custom
hosts for the self-hosted or enterprise accounts.
Copilot AI review requested due to automatic review settings February 24, 2026 12:44
@estib-vega
estib-vega force-pushed the improve-forge-detection branch from 6beb6b0 to 2dd3a38 Compare February 24, 2026 12:44
@estib-vega
estib-vega merged commit 29ca196 into master Feb 24, 2026
41 checks passed
@estib-vega
estib-vega deleted the improve-forge-detection branch February 24, 2026 12:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 8 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants