Skip to content

Commit 25bda74

Browse files
committed
Extract revision formatting logic into helper method
Move the commit hyperlink and branch/tag appending logic into a dedicated formatRevision() helper method for cleaner code. https://claude.ai/code/session_014AStcyMzd39iegXhfQL1yK Signed-off-by: Claude <noreply@anthropic.com>
1 parent de401c4 commit 25bda74

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

modules/nextflow/src/main/groovy/nextflow/cli/CmdRun.groovy

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,28 @@ class CmdRun extends CmdBase implements HubOptions {
526526
return "\033]8;;${url}\007${text}\033]8;;\007"
527527
}
528528

529+
/**
530+
* Formats the revision string with an optional hyperlink on the commit hash.
531+
* If commitUrl is available, the commit hash portion is hyperlinked and the
532+
* branch/tag name (e.g., " [master]") is appended as plain text.
533+
*
534+
* @param revision The full revision string (e.g., "2ce0b0e294 [master]")
535+
* @param commitId The full commit SHA
536+
* @param commitUrl The URL to link to, or null to skip hyperlinking
537+
* @return The formatted revision string
538+
*/
539+
protected static String formatRevision(String revision, String commitId, String commitUrl) {
540+
if( !commitUrl || !commitId )
541+
return revision ?: ''
542+
final shortCommit = commitId.substring(0, Math.min(10, commitId.length()))
543+
final linkedCommit = hyperlink(shortCommit, commitUrl)
544+
// Append the branch/tag name if revision contains more than just the commit
545+
if( revision && revision != shortCommit && revision.startsWith(shortCommit) ) {
546+
return linkedCommit + revision.substring(shortCommit.length())
547+
}
548+
return linkedCommit
549+
}
550+
529551
static void detectModuleBinaryFeature(ConfigMap config) {
530552
final moduleBinaries = config.navigate('nextflow.enable.moduleBinaries', false)
531553
if( moduleBinaries ) {
@@ -555,18 +577,7 @@ class CmdRun extends CmdBase implements HubOptions {
555577
fmt.bold().fg(Color.CYAN).a(runName).reset()
556578
fmt.a(Attribute.INTENSITY_FAINT).a("] ").reset()
557579
fmt.fg(Color.CYAN).a("revision: ").reset()
558-
// Make commit hash a hyperlink if commit URL is available
559-
if( commitUrl && commitId ) {
560-
final shortCommit = commitId.substring(0, Math.min(10, commitId.length()))
561-
fmt.fg(Color.CYAN).a(hyperlink(shortCommit, commitUrl)).reset()
562-
// Append the branch/tag name if revision contains more than just the commit
563-
if( revision && revision != shortCommit && revision.startsWith(shortCommit) ) {
564-
fmt.fg(Color.CYAN).a(revision.substring(shortCommit.length())).reset()
565-
}
566-
}
567-
else {
568-
fmt.fg(Color.CYAN).a(revision).reset()
569-
}
580+
fmt.fg(Color.CYAN).a(formatRevision(revision, commitId, commitUrl)).reset()
570581
fmt.a("\n")
571582
AnsiConsole.out().println(fmt.eraseLine())
572583
}

0 commit comments

Comments
 (0)