summaryrefslogtreecommitdiffstats
path: root/services/migrations
diff options
context:
space:
mode:
authorChongyi Zheng <harry@harryzheng.com>2022-11-02 22:32:52 -0400
committerGitHub <noreply@github.com>2022-11-03 10:32:52 +0800
commit81ea4f95a0a82506ccc350ead38ec7d290fad3cc (patch)
tree9ac1c79cd4b99d27b2ae82ac9d979bd2e340d833 /services/migrations
parent44cc684a506389d5b4c890014c75c5d04d74c52b (diff)
downloadgitea-81ea4f95a0a82506ccc350ead38ec7d290fad3cc.tar.gz
gitea-81ea4f95a0a82506ccc350ead38ec7d290fad3cc.zip
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>
Diffstat (limited to 'services/migrations')
-rw-r--r--services/migrations/github.go7
1 files changed, 6 insertions, 1 deletions
diff --git a/services/migrations/github.go b/services/migrations/github.go
index 016d058865..e5683fb530 100644
--- a/services/migrations/github.go
+++ b/services/migrations/github.go
@@ -15,6 +15,7 @@ import (
"strings"
"time"
+ "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
base "code.gitea.io/gitea/modules/migration"
"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 {
+ // 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{
Name: rel.GetName(),
TagName: rel.GetTagName(),
- TargetCommitish: rel.GetTargetCommitish(),
+ TargetCommitish: targetCommitish,
Draft: rel.GetDraft(),
Prerelease: rel.GetPrerelease(),
Created: rel.GetCreatedAt().Time,