Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GitHub: migrate draft releases too #15884

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions modules/migrations/gitea_uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,16 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
rel.OriginalAuthorID = release.PublisherID
}

// calc NumCommits
commit, err := g.gitRepo.GetCommit(rel.TagName)
if err != nil {
return fmt.Errorf("GetCommit: %v", err)
}
rel.NumCommits, err = commit.CommitsCount()
if err != nil {
return fmt.Errorf("CommitsCount: %v", err)
// calc NumCommits if no draft
if !release.Draft {
commit, err := g.gitRepo.GetCommit(rel.TagName)
if err != nil {
return fmt.Errorf("GetCommit: %v", err)
}
rel.NumCommits, err = commit.CommitsCount()
if err != nil {
return fmt.Errorf("CommitsCount: %v", err)
}
}

for _, asset := range release.Assets {
Expand All @@ -270,9 +272,10 @@ func (g *GiteaLocalUploader) CreateReleases(releases ...*base.Release) error {
}

// download attachment
err = func() error {
err := func() error {
// asset.DownloadURL maybe a local file
var rc io.ReadCloser
var err error
if asset.DownloadURL == nil {
rc, err = asset.DownloadFunc()
if err != nil {
Expand Down
44 changes: 19 additions & 25 deletions modules/migrations/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,34 +264,29 @@ func (g *GithubDownloaderV3) GetLabels() ([]*base.Label, error) {
}

func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease) *base.Release {
var (
name string
desc string
)
if rel.Body != nil {
desc = *rel.Body
}
if rel.Name != nil {
name = *rel.Name
}

var email string
if rel.Author.Email != nil {
email = *rel.Author.Email
}

r := &base.Release{
TagName: *rel.TagName,
TargetCommitish: *rel.TargetCommitish,
Name: name,
Body: desc,
Draft: *rel.Draft,
Prerelease: *rel.Prerelease,
Created: rel.CreatedAt.Time,
PublisherID: *rel.Author.ID,
PublisherName: *rel.Author.Login,
PublisherEmail: email,
Published: rel.PublishedAt.Time,
}

if rel.Body != nil {
r.Body = *rel.Body
}
if rel.Name != nil {
r.Name = *rel.Name
}

if rel.Author.Email != nil {
r.PublisherEmail = *rel.Author.Email
}

if rel.PublishedAt != nil {
r.Published = rel.PublishedAt.Time
}

for _, asset := range rel.Assets {
Expand All @@ -306,18 +301,17 @@ func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease)
Updated: asset.UpdatedAt.Time,
DownloadFunc: func() (io.ReadCloser, error) {
g.sleep()
asset, redir, err := g.client.Repositories.DownloadReleaseAsset(g.ctx, g.repoOwner, g.repoName, assetID, nil)
asset, redirectURL, err := g.client.Repositories.DownloadReleaseAsset(g.ctx, g.repoOwner, g.repoName, assetID, nil)
if err != nil {
return nil, err
}
err = g.RefreshRate()
if err != nil {
if err := g.RefreshRate(); err != nil {
log.Error("g.client.RateLimits: %s", err)
}
if asset == nil {
if redir != "" {
if redirectURL != "" {
g.sleep()
req, err := http.NewRequestWithContext(g.ctx, "GET", redir, nil)
req, err := http.NewRequestWithContext(g.ctx, "GET", redirectURL, nil)
if err != nil {
return nil, err
}
Expand Down