Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix(ci): dedup "invalid CI platform" warning across branches (#2686)

Maximilian Roosaf7db9c2975e
diff --git a/src/commands/list/ci_status/platform.rs b/src/commands/list/ci_status/platform.rs
index 4844b36ba..3a44dc7d4 100644
--- a/src/commands/list/ci_status/platform.rs
+++ b/src/commands/list/ci_status/platform.rs
@@ -12,6 +12,12 @@ use super::{CiBranchName, PrStatus, github, gitlab, tool_available};
/// Cached CI tool availability.
static CI_TOOLS: OnceLock<CiToolsAvailable> = OnceLock::new();
+/// CI platform from project config (`forge.platform` / `ci.platform`), cached.
+///
+/// Resolved once per process, so the warning for an unrecognized value fires
+/// once per `wt list` invocation rather than once per branch.
+static CONFIGURED_PLATFORM: OnceLock<Option<CiPlatform>> = OnceLock::new();
+
/// Cached availability of CI CLI tools (`gh`, `glab`).
///
/// Probed once on first access via `--version` check.
@@ -124,21 +130,9 @@ pub fn detect_platform_from_url(url: &str) -> Option<CiPlatform> {
/// For remote branches, pass the branch's remote as `remote_hint` to ensure
/// the correct platform is detected in mixed-remote repos (e.g., GitHub + GitLab).
pub fn platform_for_repo(repo: &Repository, remote_hint: Option<&str>) -> Option<CiPlatform> {
- // Config override takes precedence
- if let Some(platform_str) = repo
- .load_project_config()
- .ok()
- .flatten()
- .and_then(|c| c.forge_platform().map(str::to_string))
- {
- if let Ok(platform) = platform_str.parse::<CiPlatform>() {
- log::debug!("Using CI platform from config override: {}", platform);
- return Some(platform);
- }
- log::warn!(
- "Invalid CI platform in config: '{}'. Expected 'github' or 'gitlab'.",
- platform_str
- );
+ // Project config takes precedence.
+ if let Some(platform) = platform_from_config(repo) {
+ return Some(platform);
}
// If we have a specific remote hint (e.g., from a remote branch), use that first.
@@ -167,6 +161,38 @@ pub fn platform_for_repo(repo: &Repository, remote_hint: Option<&str>) -> Option
None
}
+/// Read the CI platform from project config (`forge.platform`, or the
+/// deprecated `ci.platform`), cached for the process.
+///
+/// Returns `None` when nothing is configured or the value is unrecognized. An
+/// unrecognized value logs a warning — and because the result is cached, that
+/// warning fires once per `wt list` invocation rather than once per branch.
+///
+/// The cache is process-wide and so assumes a single repository per process,
+/// which holds for the CLI: `platform_for_repo` is reached only from `wt list`
+/// (per branch) and `wt config show` (once).
+fn platform_from_config(repo: &Repository) -> Option<CiPlatform> {
+ *CONFIGURED_PLATFORM.get_or_init(|| {
+ let configured = repo
+ .load_project_config()
+ .ok()
+ .flatten()
+ .and_then(|c| c.forge_platform().map(str::to_string))?;
+ match configured.parse::<CiPlatform>() {
+ Ok(platform) => {
+ log::debug!("Using CI platform from config: {platform}");
+ Some(platform)
+ }
+ Err(_) => {
+ log::warn!(
+ "Invalid CI platform in config: '{configured}'. Expected 'github' or 'gitlab'."
+ );
+ None
+ }
+ }
+ })
+}
+
#[cfg(test)]
mod tests {
use super::*;
diff --git a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_invalid_platform_override.snap b/tests/snapshots/integration__integration_tests__ci_status__list_full_with_invalid_platform_override.snap
index 87ed7cd21..441f2c6a6 100644
--- a/tests/snapshots/integration__integration_tests__ci_status__list_full_with_invalid_platform_override.snap
+++ b/tests/snapshots/integration__integration_tests__ci_status__list_full_with_invalid_platform_override.snap
@@ -11,10 +11,15 @@ info:
COLUMNS: "500"
GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"
GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"
+ GIT_COMMON_DIR: ""
GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"
GIT_CONFIG_SYSTEM: /dev/null
+ GIT_DIR: ""
GIT_EDITOR: ""
+ GIT_INDEX_FILE: ""
+ GIT_OBJECT_DIRECTORY: ""
GIT_TERMINAL_PROMPT: "0"
+ GIT_WORK_TREE: ""
HOME: "[TEST_HOME]"
LANG: C
LC_ALL: C
@@ -30,13 +35,17 @@ info:
WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"
WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"
WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"
+ WORKTRUNK_TEST_BASH_INSTALLED: "0"
WORKTRUNK_TEST_CLAUDE_INSTALLED: "0"
WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"
WORKTRUNK_TEST_EPOCH: "1735776000"
+ WORKTRUNK_TEST_FISH_INSTALLED: "0"
WORKTRUNK_TEST_NUSHELL_ENV: "0"
WORKTRUNK_TEST_OPENCODE_INSTALLED: "0"
WORKTRUNK_TEST_POWERSHELL_ENV: "0"
+ WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"
WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"
+ WORKTRUNK_TEST_ZSH_INSTALLED: "0"
XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"
---
success: true
@@ -55,7 +64,3 @@ exit_code: 0
▲ Project config: [ci] is deprecated in favor of [forge]
↳ To see details, run wt config show; to apply updates, run wt config update
[W] Invalid CI platform in config: 'invalid_platform'. Expected 'github' or 'gitlab'.
-[W] Invalid CI platform in config: 'invalid_platform'. Expected 'github' or 'gitlab'.
-[W] Invalid CI platform in config: 'invalid_platform'. Expected 'github' or 'gitlab'.
-[W] Invalid CI platform in config: 'invalid_platform'. Expected 'github' or 'gitlab'.
-[W] Invalid CI platform in config: 'invalid_platform'. Expected 'github' or 'gitlab'.