From 567e117df894c6d0307f4a026cafabb3220ac3d6 Mon Sep 17 00:00:00 2001 From: Richard Mahn Date: Sat, 29 Jun 2019 06:44:17 -0400 Subject: [PATCH] Fixes #7238 - Annotated tag commit ID incorrect (#7321) * Fixes #7238 - Annotated tag commit ID incorrect * Fixes #7238 - Annotated tag commit ID incorrect --- modules/git/repo_tag.go | 7 ++++--- routers/api/v1/convert/convert.go | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go index df49e9acd6..6d490af9b5 100644 --- a/modules/git/repo_tag.go +++ b/modules/git/repo_tag.go @@ -141,9 +141,10 @@ func (repo *Repository) GetTagNameBySHA(sha string) (string, error) { fields := strings.Fields(tagRef) if strings.HasPrefix(fields[0], sha) && strings.HasPrefix(fields[1], TagPrefix) { name := fields[1][len(TagPrefix):] - // annotated tags show up twice, their name for commit ID is suffixed with ^{} - name = strings.TrimSuffix(name, "^{}") - return name, nil + // annotated tags show up twice, we should only return if is not the ^{} ref + if !strings.HasSuffix(name, "^{}") { + return name, nil + } } } } diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go index 80c0811aed..f1cb23de43 100644 --- a/routers/api/v1/convert/convert.go +++ b/routers/api/v1/convert/convert.go @@ -281,7 +281,7 @@ func ToCommitUser(sig *git.Signature) *api.CommitUser { // ToCommitMeta convert a git.Tag to an api.CommitMeta func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta { return &api.CommitMeta{ - SHA: tag.ID.String(), + SHA: tag.Object.String(), // TODO: Add the /commits API endpoint and use it here (https://developer.github.com/v3/repos/commits/#get-a-single-commit) URL: util.URLJoin(repo.APIURL(), "git/commits", tag.ID.String()), }