Fix migrate release from github (#19510)

* Fix migrate release from github

* Fix bug
This commit is contained in:
Lunny Xiao 2022-04-27 07:24:06 +08:00 committed by GitHub
parent 41fcf7b7de
commit 2728f0c213
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -7,6 +7,7 @@ package migrations
import (
"context"
"errors"
"fmt"
"io"
"os"
@ -253,7 +254,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,
@ -265,15 +265,18 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
return err
}
// 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)
}
}
}