Skip to content

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

Add clickable PR link to statusline CI indicator (#199)

Maximilian Roos5d261b7fa9cb
diff --git a/src/commands/list/ci_status.rs b/src/commands/list/ci_status.rs
index 82fd1d94d..da3e83fac 100644
--- a/src/commands/list/ci_status.rs
+++ b/src/commands/list/ci_status.rs
@@ -393,6 +393,43 @@ mod tests {
assert_eq!(error_status.indicator(), "⚠");
}
+ #[test]
+ fn test_format_indicator_with_url() {
+ let pr_with_url = PrStatus {
+ ci_status: CiStatus::Passed,
+ source: CiSource::PullRequest,
+ is_stale: false,
+ url: Some("https://github.com/owner/repo/pull/123".to_string()),
+ };
+
+ let formatted = pr_with_url.format_indicator();
+ // Should contain OSC 8 hyperlink escape sequences
+ assert!(formatted.contains("\x1b]8;;"), "Should contain OSC 8 start");
+ assert!(
+ formatted.contains("https://github.com/owner/repo/pull/123"),
+ "Should contain URL"
+ );
+ assert!(formatted.contains("●"), "Should contain indicator");
+ }
+
+ #[test]
+ fn test_format_indicator_without_url() {
+ let pr_no_url = PrStatus {
+ ci_status: CiStatus::Passed,
+ source: CiSource::PullRequest,
+ is_stale: false,
+ url: None,
+ };
+
+ let formatted = pr_no_url.format_indicator();
+ // Should NOT contain OSC 8 hyperlink
+ assert!(
+ !formatted.contains("\x1b]8;;"),
+ "Should not contain OSC 8 sequences"
+ );
+ assert!(formatted.contains("●"), "Should contain indicator");
+ }
+
#[test]
fn test_pr_status_error_constructor() {
let error = PrStatus::error();
@@ -1243,13 +1280,26 @@ impl PrStatus {
}
}
- /// Format CI status as a colored indicator for statusline output.
+ /// Format CI status as a colored indicator.
///
/// Returns a string like "●" with appropriate ANSI color.
+ /// If a PR URL is available, adds underline and wraps in an OSC 8 hyperlink.
pub fn format_indicator(&self) -> String {
- let style = self.style();
let indicator = self.indicator();
- format!("{style}{indicator}{style:#}")
+ if let Some(ref url) = self.url {
+ let style = self.style().underline();
+ format!(
+ "{}{}{}{}{}",
+ style,
+ osc8::Hyperlink::new(url),
+ indicator,
+ osc8::Hyperlink::END,
+ style.render_reset()
+ )
+ } else {
+ let style = self.style();
+ format!("{style}{indicator}{style:#}")
+ }
}
/// Create an error status for retriable failures (rate limit, network errors)
diff --git a/src/commands/list/render.rs b/src/commands/list/render.rs
index 745177d02..784f73352 100644
--- a/src/commands/list/render.rs
+++ b/src/commands/list/render.rs
@@ -89,34 +89,10 @@ impl ColumnKind {
}
impl PrStatus {
- /// Get indicator symbol and style for rendering (with URL underline)
- fn indicator_and_style(&self) -> (&'static str, Style) {
- let style = if self.url.is_some() {
- self.style().underline()
- } else {
- self.style()
- };
- (self.indicator(), style)
- }
-
+ /// Render indicator as a StyledLine for table column rendering.
fn render_indicator(&self) -> StyledLine {
let mut segment = StyledLine::new();
- let (indicator, style) = self.indicator_and_style();
-
- if let Some(ref url) = self.url {
- let styled_indicator = format!(
- "{}{}{}{}{}",
- style,
- osc8::Hyperlink::new(url),
- indicator,
- osc8::Hyperlink::END,
- style.render_reset()
- );
- segment.push_raw(styled_indicator);
- } else {
- segment.push_styled(indicator.to_string(), style);
- }
-
+ segment.push_raw(self.format_indicator());
segment
}
}