From d0c74dd2d23cf3f473fcf4bc784242334c714faa Mon Sep 17 00:00:00 2001 From: zeripath Date: Fri, 13 Jan 2023 22:33:35 +0000 Subject: [PATCH] Prepend refs/heads/ to issue template refs (#20461) (#22427) Backport #20461 Signed-off-by: Andrew Thornton --- modules/context/repo.go | 3 +++ modules/git/utils.go | 3 +++ routers/web/repo/issue.go | 4 ++++ services/issue/issue.go | 3 +-- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/context/repo.go b/modules/context/repo.go index 3e2f79430..3bf6431e2 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -1087,6 +1087,9 @@ func (ctx *Context) IssueTemplatesErrorsFromDefaultBranch() ([]*api.IssueTemplat if it, err := template.UnmarshalFromEntry(entry, dirName); err != nil { invalidFiles[fullName] = err } else { + if !strings.HasPrefix(it.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/ + it.Ref = git.BranchPrefix + it.Ref + } issueTemplates = append(issueTemplates, it) } } diff --git a/modules/git/utils.go b/modules/git/utils.go index d6bf9f441..a439dabae 100644 --- a/modules/git/utils.go +++ b/modules/git/utils.go @@ -100,6 +100,9 @@ func RefURL(repoURL, ref string) string { return repoURL + "/src/branch/" + refName case strings.HasPrefix(ref, TagPrefix): return repoURL + "/src/tag/" + refName + case !IsValidSHAPattern(ref): + // assume they mean a branch + return repoURL + "/src/branch/" + refName default: return repoURL + "/src/commit/" + refName } diff --git a/routers/web/repo/issue.go b/routers/web/repo/issue.go index 38ad593c1..2af3d9c43 100644 --- a/routers/web/repo/issue.go +++ b/routers/web/repo/issue.go @@ -784,6 +784,10 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles } } } + + } + if !strings.HasPrefix(template.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/ + template.Ref = git.BranchPrefix + template.Ref } ctx.Data["HasSelectedLabel"] = len(labelIDs) > 0 ctx.Data["label_ids"] = strings.Join(labelIDs, ",") diff --git a/services/issue/issue.go b/services/issue/issue.go index 42548d9d9..c522c0083 100644 --- a/services/issue/issue.go +++ b/services/issue/issue.go @@ -18,7 +18,6 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/storage" - "code.gitea.io/gitea/modules/util" ) // NewIssue creates new issue with labels for repository. @@ -201,7 +200,7 @@ func GetRefEndNamesAndURLs(issues []*issues_model.Issue, repoLink string) (map[i for _, issue := range issues { if issue.Ref != "" { issueRefEndNames[issue.ID] = git.RefEndName(issue.Ref) - issueRefURLs[issue.ID] = git.RefURL(repoLink, util.PathEscapeSegments(issue.Ref)) + issueRefURLs[issue.ID] = git.RefURL(repoLink, issue.Ref) } } return issueRefEndNames, issueRefURLs