Skip to content

Commit d86cffb

Browse files
committed
pin summary: suppress downgrade nudges, show info for bare SHA pins
Two fixes: - Version-ref nudge no longer suggests a full semver tag that is LOWER than the user's current partial ref (e.g. v3.4 → v2.4.1 was wrong). - Bare SHA pins now show 'pinned by SHA — no symbolic ref found' instead of being completely silent or showing the redundant full-sha (short).
1 parent c77ada8 commit d86cffb

1 file changed

Lines changed: 35 additions & 3 deletions

File tree

cmd/gh-actions-lock/pin_summary.go

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,24 @@ func renderPinnedEntries(console *ui.UI, pinned []pin.Entry) {
222222
if len(short) > 7 {
223223
short = short[:7]
224224
}
225-
label := g.NWO + "@" + g.Ref
226-
if short != "" {
227-
label = fmt.Sprintf("%s (%s)", label, short)
225+
var label string
226+
if looksLikeSHA(g.Ref) {
227+
// Bare SHA pin — show short form only
228+
label = g.NWO + "@" + short
229+
} else {
230+
label = g.NWO + "@" + g.Ref
231+
if short != "" {
232+
label = fmt.Sprintf("%s (%s)", label, short)
233+
}
228234
}
229235
console.TermDetail(" %s", console.TermYellow(label))
230236
for _, wf := range g.workflows {
231237
console.TermDetail(" └─ %s", console.TermDim(wf))
232238
}
239+
if looksLikeSHA(g.Ref) {
240+
console.TermDetail(" %s pinned by SHA — no symbolic ref found",
241+
console.TermDim("ℹ"))
242+
}
233243
if g.AutoFixedRef != "" {
234244
prev := g.AutoFixedRef
235245
if len(prev) > 7 {
@@ -575,6 +585,13 @@ func renderVersionRefNudge(ctx context.Context, console *ui.UI, record *pin.Reco
575585
if latest == "" {
576586
continue // no semver releases — nothing to suggest
577587
}
588+
// Don't suggest a downgrade: if the user is on v3.4, only nudge
589+
// if the latest full semver is v3.4.x or higher.
590+
if latestSV, latestOK := parserlock.ParseSemVer(latest); latestOK {
591+
if !latestSV.Greater(sv) {
592+
continue
593+
}
594+
}
578595
seen[key] = &nudgeEntry{key: key, latest: latest, workflows: e.Workflows}
579596
}
580597
if len(seen) == 0 {
@@ -633,3 +650,18 @@ func latestFullSemverTag(ctx context.Context, r *resolve.Resolver, nwo string) s
633650
}
634651
return bestTag
635652
}
653+
654+
// looksLikeSHA returns true when ref is a hex string of SHA-1 (40) or
655+
// SHA-256 (64) length.
656+
func looksLikeSHA(ref string) bool {
657+
n := len(ref)
658+
if n != 40 && n != 64 {
659+
return false
660+
}
661+
for _, c := range ref {
662+
if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F')) {
663+
return false
664+
}
665+
}
666+
return true
667+
}

0 commit comments

Comments
 (0)