diff options
author | 6543 <6543@obermui.de> | 2021-03-08 20:00:19 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-08 20:00:19 +0100 |
commit | 14d8cb781911ebb5a44fbcf02738e8e02f492e04 (patch) | |
tree | f51be37143945650ee3b28f5600f9e99985ba24b /modules | |
parent | f4ce10c6a35b90b8e3943bbb66fa63e731d56e08 (diff) | |
download | gitea-14d8cb781911ebb5a44fbcf02738e8e02f492e04.tar.gz gitea-14d8cb781911ebb5a44fbcf02738e8e02f492e04.zip |
Move Workaround for #12675 into it's own function (#14922)
* Move Workatround for #12675 into it's own function
* use more reliable solution (as tea do)
Diffstat (limited to 'modules')
-rw-r--r-- | modules/migrations/gitea_downloader.go | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/modules/migrations/gitea_downloader.go b/modules/migrations/gitea_downloader.go index 70daf8d5a3..87ec9c102a 100644 --- a/modules/migrations/gitea_downloader.go +++ b/modules/migrations/gitea_downloader.go @@ -525,15 +525,11 @@ func (g *GiteaDownloader) GetPullRequests(page, perPage int) ([]*base.PullReques headRepoName = pr.Head.Repository.Name headCloneURL = pr.Head.Repository.CloneURL } + if err := fixPullHeadSha(g.client, pr); err != nil { + return nil, false, fmt.Errorf("error while resolving head git ref: %s for pull #%d. Error: %v", pr.Head.Ref, pr.Index, err) + } headSHA = pr.Head.Sha headRef = pr.Head.Ref - if headSHA == "" { - headCommit, _, err := g.client.GetSingleCommit(g.repoOwner, g.repoName, url.PathEscape(pr.Head.Ref)) - if err != nil { - return nil, false, fmt.Errorf("error while resolving head git ref: %s for pull #%d. Error: %v", pr.Head.Ref, pr.Index, err) - } - headSHA = headCommit.SHA - } } var mergeCommitSHA string @@ -683,3 +679,22 @@ func (g *GiteaDownloader) GetReviews(index int64) ([]*base.Review, error) { } return allReviews, nil } + +// fixPullHeadSha is a workaround for https://github.com/go-gitea/gitea/issues/12675 +// When no head sha is available, this is because the branch got deleted in the base repo. +// pr.Head.Ref points in this case not to the head repo branch name, but the base repo ref, +// which stays available to resolve the commit sha. +func fixPullHeadSha(client *gitea_sdk.Client, pr *gitea_sdk.PullRequest) error { + owner := pr.Base.Repository.Owner.UserName + repo := pr.Base.Repository.Name + if pr.Head != nil && pr.Head.Sha == "" { + refs, _, err := client.GetRepoRefs(owner, repo, pr.Head.Ref) + if err != nil { + return err + } else if len(refs) == 0 { + return fmt.Errorf("unable to resolve PR ref '%s'", pr.Head.Ref) + } + pr.Head.Sha = refs[0].Object.SHA + } + return nil +} |