diff options
author | 6543 <6543@obermui.de> | 2021-05-16 00:37:17 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-16 00:37:17 +0200 |
commit | e0c93fed05f5863ebef2ff584734709c79d926f2 (patch) | |
tree | 64911d64b4f6049c88f69e728812de13c7f49033 /modules/migrations/github.go | |
parent | Hold the event source when there are no listeners (#15725) (diff) | |
download | forgejo-e0c93fed05f5863ebef2ff584734709c79d926f2.tar.xz forgejo-e0c93fed05f5863ebef2ff584734709c79d926f2.zip |
GitHub: migrate draft releases too (#15884)
* GitHub: migrate draft releases too
* refactor
Diffstat (limited to '')
-rw-r--r-- | modules/migrations/github.go | 44 |
1 files changed, 19 insertions, 25 deletions
diff --git a/modules/migrations/github.go b/modules/migrations/github.go index 282e3b4786..8a3f5d34c7 100644 --- a/modules/migrations/github.go +++ b/modules/migrations/github.go @@ -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 { @@ -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 } |