resolveVersionLabel returns a human-readable label for a git ref in the given source repo. If the ref is a semver tag or branch name it is returned as-is. For commit SHAs it tries to find a matching tag in the source repo (first page of tags). If no tag is found it falls back to shortRef. Results a
(ctx context.Context, sourceRepo, ref string)
| 33 | // Results are cached per source repo so that multiple workflows sharing a source |
| 34 | // only trigger one API call. |
| 35 | func resolveVersionLabel(ctx context.Context, sourceRepo, ref string) string { |
| 36 | if !IsCommitSHA(ref) { |
| 37 | // Already a tag or branch – just return as-is. |
| 38 | return ref |
| 39 | } |
| 40 | |
| 41 | if tagMap, ok := getVersionLabelCache(sourceRepo); ok { |
| 42 | if tag, ok := tagMap[ref]; ok { |
| 43 | return tag |
| 44 | } |
| 45 | return shortRef(ref) |
| 46 | } |
| 47 | |
| 48 | tagMap, ok := loadRepoTagMap(ctx, sourceRepo) |
| 49 | if !ok { |
| 50 | return shortRef(ref) |
| 51 | } |
| 52 | |
| 53 | setVersionLabelCache(sourceRepo, tagMap) |
| 54 | |
| 55 | if tag, ok := tagMap[ref]; ok { |
| 56 | return tag |
| 57 | } |
| 58 | return shortRef(ref) |
| 59 | } |
| 60 | |
| 61 | // clearVersionLabelCache clears per-run source-repo tag caches. |
| 62 | func clearVersionLabelCache() { |