Skip to content

fix: handle lightweight tags in get_tag tool#2137

Open
fidesit wants to merge 2 commits intogithub:mainfrom
fidesit:fix/get-tag-lightweight-tags
Open

fix: handle lightweight tags in get_tag tool#2137
fidesit wants to merge 2 commits intogithub:mainfrom
fidesit:fix/get-tag-lightweight-tags

Conversation

@fidesit
Copy link

@fidesit fidesit commented Mar 4, 2026

Summary

The get_tag tool returns a 404 error when used with lightweight tags because it unconditionally calls the Git Tag Object API, which only works for annotated tags.

  • Adds ref.Object.Type check after resolving the tag reference
  • Lightweight tags ("commit" type): resolves via Git.GetCommit() and returns a github.Tag-compatible structure
  • Annotated tags ("tag" type): unchanged behavior via Git.GetTag()

Bug

In pkg/github/repositories.go, the GetTag handler resolves a tag reference via client.Git.GetRef(), then always calls client.Git.GetTag() with the ref's SHA. This works for annotated tags (where the SHA points to a tag object), but fails for lightweight tags (where the SHA points directly to a commit — the Git Tag Object API returns 404).

Reproduce: Create a lightweight tag (git tag v1.0.0 && git push --tags), then call get_tag → 404.

Changes

pkg/github/repositories.go

  • After getting the tag reference, check ref.Object.Type
  • If "commit" (lightweight): call client.Git.GetCommit(), return a github.Tag struct with commit message and author mapped to tagger
  • If "tag" (annotated): proceed with existing client.Git.GetTag() call (no behavior change)

pkg/github/repositories_test.go

  • Added mockLightweightTagRef and mockCommit fixtures
  • Added "successful lightweight tag retrieval" test case
  • Updated existing mockTagRef to include Type: github.Ptr("tag") for accuracy

Notes

  • No schema change — the tool returns the same github.Tag JSON structure for both tag types
  • Backward compatible — annotated tag responses are identical to before
  • No toolsnap update needed (schema unchanged)

Lightweight tags point directly to commits, not tag objects. The get_tag
tool previously always called the Git Tag API which returns 404 for
lightweight tags since their SHA references a commit, not a tag object.

Now checks ref.Object.Type: if "commit" (lightweight), resolves the
commit directly and returns a tag-like structure for consistency. If
"tag" (annotated), proceeds with the existing tag object fetch.
@fidesit fidesit requested a review from a team as a code owner March 4, 2026 19:58
Copilot AI review requested due to automatic review settings March 4, 2026 19:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes get_tag so it works with both annotated and lightweight Git tags by avoiding the Git Tag Object API for lightweight tags (which point directly to commits and otherwise 404).

Changes:

  • Branch on ref.Object.Type after Git.GetRef() to distinguish annotated ("tag") vs lightweight ("commit") tags.
  • For lightweight tags, fetch the commit via Git.GetCommit() and return a github.Tag-compatible payload.
  • Extend Test_GetTag with fixtures and a new “successful lightweight tag retrieval” test case.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/github/repositories.go Adds lightweight-tag handling by resolving commit refs and returning a tag-like JSON payload.
pkg/github/repositories_test.go Adds mocks and a new test case covering lightweight tag retrieval.

Address Copilot review comments:
- Use distinct variable names (refResp, commitResp, tagResp) for each
  API response to avoid defer closure capturing issues with shared resp.
- Add 'lightweight tag commit not found' error test case for GetCommit
  returning 404.
- Assert Tagger field mapping (author -> tagger) in the lightweight tag
  success test case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants