Skip to content

Commit

Permalink
Fix migrate release from github (#19510)
Browse files Browse the repository at this point in the history
* Fix migrate release from github

* Fix bug
  • Loading branch information
lunny authored Apr 26, 2022
1 parent 41fcf7b commit 2728f0c
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions services/migrations/gitea_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package migrations

import (
"context"
"errors"
"fmt"
"io"
"os"
Expand Down Expand Up @@ -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,
Expand All @@ -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)
}
}
}

Expand Down

0 comments on commit 2728f0c

Please sign in to comment.