Skip to content

Commit 81ea4f9

Browse files
harryzcywxiaoguang
andauthored
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 <[email protected]>
1 parent 44cc684 commit 81ea4f9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

services/migrations/github.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"strings"
1616
"time"
1717

18+
"code.gitea.io/gitea/modules/git"
1819
"code.gitea.io/gitea/modules/log"
1920
base "code.gitea.io/gitea/modules/migration"
2021
"code.gitea.io/gitea/modules/proxy"
@@ -307,10 +308,14 @@ func (g *GithubDownloaderV3) GetLabels() ([]*base.Label, error) {
307308
}
308309

309310
func (g *GithubDownloaderV3) convertGithubRelease(rel *github.RepositoryRelease) *base.Release {
311+
// GitHub allows commitish to be a reference.
312+
// In this case, we need to remove the prefix, i.e. convert "refs/heads/main" to "main".
313+
targetCommitish := strings.TrimPrefix(rel.GetTargetCommitish(), git.BranchPrefix)
314+
310315
r := &base.Release{
311316
Name: rel.GetName(),
312317
TagName: rel.GetTagName(),
313-
TargetCommitish: rel.GetTargetCommitish(),
318+
TargetCommitish: targetCommitish,
314319
Draft: rel.GetDraft(),
315320
Prerelease: rel.GetPrerelease(),
316321
Created: rel.GetCreatedAt().Time,

0 commit comments

Comments
 (0)