Skip to content

Commit d0c74dd

Browse files
authored
Prepend refs/heads/ to issue template refs (#20461) (#22427)
Backport #20461 Signed-off-by: Andrew Thornton <[email protected]>
1 parent 2f91a12 commit d0c74dd

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

modules/context/repo.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,9 @@ func (ctx *Context) IssueTemplatesErrorsFromDefaultBranch() ([]*api.IssueTemplat
10871087
if it, err := template.UnmarshalFromEntry(entry, dirName); err != nil {
10881088
invalidFiles[fullName] = err
10891089
} else {
1090+
if !strings.HasPrefix(it.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/<ref>
1091+
it.Ref = git.BranchPrefix + it.Ref
1092+
}
10901093
issueTemplates = append(issueTemplates, it)
10911094
}
10921095
}

modules/git/utils.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ func RefURL(repoURL, ref string) string {
100100
return repoURL + "/src/branch/" + refName
101101
case strings.HasPrefix(ref, TagPrefix):
102102
return repoURL + "/src/tag/" + refName
103+
case !IsValidSHAPattern(ref):
104+
// assume they mean a branch
105+
return repoURL + "/src/branch/" + refName
103106
default:
104107
return repoURL + "/src/commit/" + refName
105108
}

routers/web/repo/issue.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,10 @@ func setTemplateIfExists(ctx *context.Context, ctxDataKey string, possibleFiles
784784
}
785785
}
786786
}
787+
788+
}
789+
if !strings.HasPrefix(template.Ref, "refs/") { // Assume that the ref intended is always a branch - for tags users should use refs/tags/<ref>
790+
template.Ref = git.BranchPrefix + template.Ref
787791
}
788792
ctx.Data["HasSelectedLabel"] = len(labelIDs) > 0
789793
ctx.Data["label_ids"] = strings.Join(labelIDs, ",")

services/issue/issue.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"code.gitea.io/gitea/modules/git"
1919
"code.gitea.io/gitea/modules/notification"
2020
"code.gitea.io/gitea/modules/storage"
21-
"code.gitea.io/gitea/modules/util"
2221
)
2322

2423
// NewIssue creates new issue with labels for repository.
@@ -201,7 +200,7 @@ func GetRefEndNamesAndURLs(issues []*issues_model.Issue, repoLink string) (map[i
201200
for _, issue := range issues {
202201
if issue.Ref != "" {
203202
issueRefEndNames[issue.ID] = git.RefEndName(issue.Ref)
204-
issueRefURLs[issue.ID] = git.RefURL(repoLink, util.PathEscapeSegments(issue.Ref))
203+
issueRefURLs[issue.ID] = git.RefURL(repoLink, issue.Ref)
205204
}
206205
}
207206
return issueRefEndNames, issueRefURLs

0 commit comments

Comments
 (0)