Skip to content

Derive digest algorithm from ref length in release verify commands#13430

Merged
bdehamer merged 2 commits into
cli:trunkfrom
bdehamer:fix-release-verify-digest-algorithm
May 15, 2026
Merged

Derive digest algorithm from ref length in release verify commands#13430
bdehamer merged 2 commits into
cli:trunkfrom
bdehamer:fix-release-verify-digest-algorithm

Conversation

@bdehamer

Copy link
Copy Markdown
Contributor

Fixes #13429

Summary

The gh release verify and gh release verify-asset commands hard-coded a sha1: prefix when constructing the digest identifier for a release tag's commit SHA. Once GitHub repositories using SHA-256 commit digests are supported, that ref will be a 64-character SHA-256 hash and labeling it as sha1: is both misleading in user-facing output and incorrect for the attestation lookup.

Changes

  • Added a small shared helper DigestAlgForRef(digest string) string in pkg/cmd/release/shared/fetch.go that returns "sha256" for 64-character digests and "sha1" otherwise (preserving existing behavior).
  • Replaced the hard-coded "sha1" argument in pkg/cmd/release/verify/verify.go and pkg/cmd/release/verify-asset/verify_asset.go with a call to the new helper.
  • Added unit tests for DigestAlgForRef covering SHA-1, SHA-256, empty, and unexpected lengths.
  • Added *_SHA256 variants of the existing FailedNoAttestations tests in both commands that assert the error message includes sha256:<digest>.

Verification

  • go test ./pkg/cmd/release/shared/... ./pkg/cmd/release/verify/... ./pkg/cmd/release/verify-asset/... passes.
  • go build ./... passes.
  • Existing SHA-1 tests continue to pass (no regression).

The 'gh release verify' and 'gh release verify-asset' commands hard-coded
a 'sha1:' prefix when constructing the digest identifier for a release
tag's commit SHA. Once GitHub repositories using SHA-256 commit digests
are supported, that ref will be a 64-character SHA-256 hash and labeling
it as 'sha1:' is both misleading in user output and incorrect for the
attestation lookup.

Add a shared 'DigestAlgForRef' helper that returns 'sha256' for 64-char
digests and 'sha1' otherwise (preserving existing behavior for SHA-1
repositories), and use it at both call sites. Add test coverage for the
helper and for the SHA-256 error path in both commands.

Fixes cli#13429

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 14, 2026 17:32
@bdehamer bdehamer requested review from a team as code owners May 14, 2026 17:32
@bdehamer bdehamer requested a review from BagToad May 14, 2026 17:32
@github-actions github-actions Bot added external pull request originating outside of the CLI core team needs-triage needs to be reviewed unmet-requirements and removed needs-triage needs to be reviewed labels May 14, 2026
@github-actions

Copy link
Copy Markdown

Thanks for your pull request! Unfortunately, it doesn't meet the requirements for review:

  • None of the referenced issues have the help wanted label

Please update your PR to address the above. This PR will be automatically closed in 4 days if these requirements are not met.

Full contribution requirements
  1. Include a detailed description of what this PR does
  2. Link to an issue with the help wanted label (use Fixes #123 or Closes #123)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates release verification to derive the release ref digest algorithm from the ref length so SHA-256 repository refs are labeled and queried correctly.

Changes:

  • Added DigestAlgForRef to choose sha256 for 64-character refs and sha1 otherwise.
  • Updated release verify and release verify-asset to use the derived algorithm.
  • Added SHA-256-focused regression tests and helper unit tests.
Show a summary per file
File Description
pkg/cmd/release/verify/verify.go Uses the shared helper when constructing the release ref digest.
pkg/cmd/release/verify/verify_test.go Adds SHA-256 no-attestations coverage for release verify.
pkg/cmd/release/verify-asset/verify_asset.go Uses the shared helper when constructing the release ref digest.
pkg/cmd/release/verify-asset/verify_asset_test.go Adds SHA-256 no-attestations coverage for release verify-asset.
pkg/cmd/release/shared/fetch.go Adds the shared digest algorithm helper.
pkg/cmd/release/shared/fetch_test.go Adds unit tests for digest algorithm selection.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 6/6 changed files
  • Comments generated: 2

Comment thread pkg/cmd/release/verify/verify_test.go Outdated
Comment thread pkg/cmd/release/verify-asset/verify_asset_test.go Outdated

@babakks babakks left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Also, I think :copilot: comments are valid.

Comment thread pkg/cmd/release/verify/verify_test.go
Comment thread pkg/cmd/release/verify-asset/verify_asset_test.go
Address PR review feedback:
- Rename SHA1 tests to make the algorithm explicit
- Assert the sha1:/sha256: prefix appears in the error
- Use a capturing MockClient so we verify the actual digest sent to
  GetByDigest, not just the wrapped error message

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@ejahnGithub ejahnGithub left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@bdehamer bdehamer merged commit f1c10e0 into cli:trunk May 15, 2026
11 checks passed
@bullpowerhubgit

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external pull request originating outside of the CLI core team ready-for-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hard-coded sha1: prefix in gh release verify and gh release verify-asset

5 participants