MCPcopy Create free account
hub / github.com/github/gh-aw / resolveLatestRef

Function resolveLatestRef

pkg/cli/update_workflows.go:257–295  ·  view source on GitHub ↗

resolveLatestRef resolves the latest ref for a workflow source

(ctx context.Context, repo, currentRef string, allowMajor, verbose bool, coolDown time.Duration)

Source from the content-addressed store, hash-verified

255
256// resolveLatestRef resolves the latest ref for a workflow source
257func resolveLatestRef(ctx context.Context, repo, currentRef string, allowMajor, verbose bool, coolDown time.Duration) (string, error) {
258 updateLog.Printf("Resolving latest ref: repo=%s, currentRef=%s, allowMajor=%v", repo, currentRef, allowMajor)
259
260 if verbose {
261 fmt.Fprintln(os.Stderr, console.FormatVerboseMessage(fmt.Sprintf("Resolving latest ref for %s (current: %s)", repo, currentRef)))
262 }
263
264 // Check if current ref is a tag (looks like a semantic version)
265 if isSemanticVersionTag(currentRef) {
266 updateLog.Print("Current ref is semantic version tag, resolving latest release")
267 return resolveLatestRelease(ctx, repo, currentRef, allowMajor, verbose, coolDown)
268 }
269
270 // Check if current ref is a commit SHA (40-character hex string)
271 if IsCommitSHA(currentRef) {
272 updateLog.Printf("Current ref is a commit SHA: %s, fetching latest from default branch", currentRef)
273 // The source field only contains a pinned SHA with no branch information.
274 // Fetch the latest commit from the default branch to check for updates.
275 return resolveLatestCommitFromDefaultBranch(ctx, repo, currentRef, verbose)
276 }
277
278 // Otherwise, treat as branch and get latest commit
279 if verbose {
280 fmt.Fprintln(os.Stderr, console.FormatVerboseMessage(fmt.Sprintf("Treating %s as branch, getting latest commit", currentRef)))
281 }
282
283 // Get the latest commit SHA for the branch
284 latestSHA, err := getLatestBranchCommitSHACached(ctx, repo, currentRef)
285 if err != nil {
286 return "", fmt.Errorf("failed to get latest commit for branch %s: %w", currentRef, err)
287 }
288
289 updateLog.Printf("Latest commit for branch %s: %s", currentRef, latestSHA)
290
291 // Return the SHA for comparison so we can detect upstream changes.
292 // The caller (updateWorkflow) preserves the branch name in the source
293 // field to avoid SHA-pinning — see isBranchRef() usage there.
294 return latestSHA, nil
295}
296
297// resolveLatestCommitFromDefaultBranch fetches the latest commit SHA from
298// the default branch of a repo. This is used when the source field is pinned

Calls 9

FormatVerboseMessageFunction · 0.92
isSemanticVersionTagFunction · 0.85
resolveLatestReleaseFunction · 0.85
IsCommitSHAFunction · 0.85
PrintMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45