From 8a978b09e57e3c9a34fe05adc1b94e2dd70b4d36 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 27 Apr 2022 07:24:06 +0800 Subject: [PATCH] Fix migrate release from github (#19510) * Fix migrate release from github * Fix bug --- services/migrations/gitea_uploader.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index e78d0c382eb75..debe172414770 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -7,6 +7,7 @@ package migrations import ( "context" + "errors" "fmt" "io" "os" @@ -246,7 +247,6 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error { LowerTagName: strings.ToLower(release.TagName), Target: release.TargetCommitish, Title: release.Name, - Sha1: release.TargetCommitish, Note: release.Body, IsDraft: release.Draft, IsPrerelease: release.Prerelease, @@ -275,15 +275,18 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error { rel.OriginalAuthorID = release.PublisherID } - // calc NumCommits if no draft - if !release.Draft { + // calc NumCommits if possible + if rel.TagName != "" { commit, err := g.gitRepo.GetTagCommit(rel.TagName) - if err != nil { - return fmt.Errorf("GetTagCommit[%v]: %v", rel.TagName, err) - } - rel.NumCommits, err = commit.CommitsCount() - if err != nil { - return fmt.Errorf("CommitsCount: %v", err) + if !errors.Is(err, git.ErrNotExist{}) { + if err != nil { + return fmt.Errorf("GetTagCommit[%v]: %v", rel.TagName, err) + } + rel.Sha1 = commit.ID.String() + rel.NumCommits, err = commit.CommitsCount() + if err != nil { + return fmt.Errorf("CommitsCount: %v", err) + } } }