0
0
Fork 0
mirror of https://github.com/go-gitea/gitea synced 2024-11-16 15:01:07 +01:00

Handle branch name with prefix in GitHub migration (#20357)

GitHub allows releases with target commitish `refs/heads/BRANCH`, which
then causes issues in Gitea after migration. This fix handles cases that
a branch already has a prefix.

Fixes #20317

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Chongyi Zheng 2022-11-02 22:32:52 -04:00 committed by GitHub
parent 44cc684a50
commit 81ea4f95a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -15,6 +15,7 @@ import (
"strings" "strings"
"time" "time"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
base "code.gitea.io/gitea/modules/migration" base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/proxy" "code.gitea.io/gitea/modules/proxy"
@ -307,10 +308,14 @@ func (g *GithubDownloaderV3) GetLabels() ([]*base.Label, error) {
} }
func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease) *base.Release { func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease) *base.Release {
// GitHub allows commitish to be a reference.
// In this case, we need to remove the prefix, i.e. convert "refs/heads/main" to "main".
targetCommitish := strings.TrimPrefix(rel.GetTargetCommitish(), git.BranchPrefix)
r := &base.Release{ r := &base.Release{
Name: rel.GetName(), Name: rel.GetName(),
TagName: rel.GetTagName(), TagName: rel.GetTagName(),
TargetCommitish: rel.GetTargetCommitish(), TargetCommitish: targetCommitish,
Draft: rel.GetDraft(), Draft: rel.GetDraft(),
Prerelease: rel.GetPrerelease(), Prerelease: rel.GetPrerelease(),
Created: rel.GetCreatedAt().Time, Created: rel.GetCreatedAt().Time,