]> source.dussan.org Git - gitea.git/commitdiff
Prepend refs/heads/ to issue template refs (#20461) (#22427)
authorzeripath <art27@cantab.net>
Fri, 13 Jan 2023 22:33:35 +0000 (22:33 +0000)
committerGitHub <noreply@github.com>
Fri, 13 Jan 2023 22:33:35 +0000 (16:33 -0600)
Backport #20461

Signed-off-by: Andrew Thornton <art27@cantab.net>
modules/context/repo.go
modules/git/utils.go
routers/web/repo/issue.go
services/issue/issue.go

index 3e2f794303dd3916541574972cff4ce3d54a7ea8..3bf6431e2c19c2fc9dbd58ce6b34296d9ef53aa9 100644 (file)
@@ -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/<ref>
+                                       it.Ref = git.BranchPrefix + it.Ref
+                               }
                                issueTemplates = append(issueTemplates, it)
                        }
                }
index d6bf9f4413cd5cb16ca5f6fb465c79302a05d459..a439dabae18ef3077ef811b409385b2f24482d87 100644 (file)
@@ -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
        }
index 38ad593c17ad2ba010d3bcb6e883b4d952f4b460..2af3d9c430b28bfdd852ab7557ba0275abb4e648 100644 (file)
@@ -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/<ref>
+                       template.Ref = git.BranchPrefix + template.Ref
                }
                ctx.Data["HasSelectedLabel"] = len(labelIDs) > 0
                ctx.Data["label_ids"] = strings.Join(labelIDs, ",")
index 42548d9d9dfd31908fecaed69fd110e0bff76406..c522c0083f22f27689206b6340bbdb37911535c5 100644 (file)
@@ -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