Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
refactor: simplify GitHub/GitLab CI status detection (#730)
Maximilian Roosa8c5672eff69
diff --git a/src/commands/list/ci_status/gitlab.rs b/src/commands/list/ci_status/gitlab.rsindex 4947cf8ee..3fee6e20a 100644--- a/src/commands/list/ci_status/gitlab.rs+++ b/src/commands/list/ci_status/gitlab.rs@@ -4,11 +4,10 @@use serde::Deserialize;use worktrunk::git::Repository;-use worktrunk::shell_exec::Cmd;use super::{CiSource, CiStatus, MAX_PRS_TO_FETCH, PrStatus, is_retriable_error, non_interactive_cmd,- parse_json, tool_available,+ parse_json,};/// Get the GitLab project ID for a repository.@@ -16,14 +15,8 @@ use super::{/// Used for client-side filtering of MRs by source project./// This is the GitLab equivalent of `get_origin_owner` for GitHub.///-/// Returns None if glab is not available or not configured for this repo.-///-/// # Performance Note-///-/// This function is called during GitLab detection regardless of whether-/// the repo is actually GitLab-hosted. If glab is installed but the repo-/// is GitHub, this adds an unnecessary CLI call. A future optimization-/// could check the remote URL first and skip for non-GitLab remotes.+/// Returns None if glab is not configured for this repo (e.g., non-GitLab+/// remote, auth issues).fn get_gitlab_project_id(repo: &Repository) -> Option<u64> {let repo_root = repo.current_worktree().root().ok()?;@@ -63,10 +56,6 @@ fn get_gitlab_project_id(repo: &Repository) -> Option<u64> {/// 2. Fetch all open MRs with matching branch name (up to 20)/// 3. Filter client-side by comparing `source_project_id` to our project IDpub(super) fn detect_gitlab(repo: &Repository, branch: &str, local_head: &str) -> Option<PrStatus> {- if !tool_available("glab", &["--version"]) {- return None;- }-let repo_root = repo.current_worktree().root().ok()?;// Get current project ID for filtering@@ -77,7 +66,7 @@ pub(super) fn detect_gitlab(repo: &Repository, branch: &str, local_head: &str) -// Fetch MRs with matching source branch.// We filter client-side by source_project_id (numeric project ID comparison).- let output = match Cmd::new("glab")+ let output = match non_interactive_cmd("glab").args(["mr","list",@@ -163,12 +152,8 @@ pub(super) fn detect_gitlab(repo: &Repository, branch: &str, local_head: &str) -/// Detect GitLab pipeline status for a branch (when no MR exists).pub(super) fn detect_gitlab_pipeline(branch: &str, local_head: &str) -> Option<PrStatus> {- if !tool_available("glab", &["--version"]) {- return None;- }-// Get most recent pipeline for the branch using JSON output- let output = match Cmd::new("glab")+ let output = match non_interactive_cmd("glab").args(["ci", "list", "--per-page", "1", "--output", "json"]).env("BRANCH", branch) // glab ci list uses BRANCH env var.run()diff --git a/src/commands/list/ci_status/mod.rs b/src/commands/list/ci_status/mod.rsindex 29aab8455..bbd3d5f57 100644--- a/src/commands/list/ci_status/mod.rs+++ b/src/commands/list/ci_status/mod.rs@@ -140,12 +140,9 @@ pub enum CiStatus {Error,}-/// Source of CI status+/// Source of CI status (PR/MR vs branch workflow)///-/// Visual distinction: Currently both PR and branch CI use ● (filled circle).-/// The internal distinction (CiSource::PullRequest vs CiSource::Branch) is preserved-/// for potential future visual differentiation. We tried ◒ (half circle) for branch CI-/// but it renders narrower than ● in many terminal fonts, causing misalignment.+/// Serialized to JSON as "pr" or "branch" for programmatic consumers.#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, strum::IntoStaticStr)]#[strum(serialize_all = "kebab-case")]pub enum CiSource {@@ -201,18 +198,13 @@ impl PrStatus {/// Get the indicator symbol for this status///- /// - Error: ⚠ (overrides source indicator)- /// - PullRequest: ● (filled circle)- /// - Branch: ● (filled circle) — same as PR for now, see CiSource doc comment+ /// - Error: ⚠ (warning indicator)+ /// - All others: ● (filled circle)pub fn indicator(&self) -> &'static str {- match self.ci_status {- CiStatus::Error => "⚠",- _ => match self.source {- CiSource::PullRequest => "●",- // Using same indicator as PR for now due to font rendering issues.- // See CiSource doc comment for details.- CiSource::Branch => "●",- },+ if matches!(self.ci_status, CiStatus::Error) {+ "⚠"+ } else {+ "●"}}@@ -371,6 +363,9 @@ impl PrStatus {local_head: &str,has_upstream: bool,) -> Option<Self> {+ if !tool_available("glab", &["--version"]) {+ return None;+ }if let Some(status) = gitlab::detect_gitlab(repo, branch, local_head) {return Some(status);}