Do not show issue context popup on external issues (#17050) (#17054)

Backport #17050

The issues pop-up context cannot work for external issues - therefore do not show
these.

Fix #17047

Signed-off-by: Andrew Thornton <art27@cantab.net>
release/v1.15
zeripath 2021-09-15 10:38:20 +01:00 committed by GitHub
parent 270c7f36db
commit 6a025d8b4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 4 deletions

View File

@ -827,7 +827,7 @@ func issueIndexPatternProcessor(ctx *RenderContext, node *html.Node) {
reftext := node.Data[ref.RefLocation.Start:ref.RefLocation.End] reftext := node.Data[ref.RefLocation.Start:ref.RefLocation.End]
if exttrack && !ref.IsPull { if exttrack && !ref.IsPull {
ctx.Metas["index"] = ref.Issue ctx.Metas["index"] = ref.Issue
link = createLink(com.Expand(ctx.Metas["format"], ctx.Metas), reftext, "ref-issue") link = createLink(com.Expand(ctx.Metas["format"], ctx.Metas), reftext, "ref-issue ref-external-issue")
} else { } else {
// Path determines the type of link that will be rendered. It's unknown at this point whether // Path determines the type of link that will be rendered. It's unknown at this point whether
// the linked item is actually a PR or an issue. Luckily it's of no real consequence because // the linked item is actually a PR or an issue. Luckily it's of no real consequence because

View File

@ -96,12 +96,14 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
// numeric: render inputs with valid mentions // numeric: render inputs with valid mentions
test := func(s, expectedFmt, marker string, indices ...int) { test := func(s, expectedFmt, marker string, indices ...int) {
var path, prefix string var path, prefix string
isExternal := false
if marker == "!" { if marker == "!" {
path = "pulls" path = "pulls"
prefix = "http://localhost:3000/someUser/someRepo/pulls/" prefix = "http://localhost:3000/someUser/someRepo/pulls/"
} else { } else {
path = "issues" path = "issues"
prefix = "https://someurl.com/someUser/someRepo/" prefix = "https://someurl.com/someUser/someRepo/"
isExternal = true
} }
links := make([]interface{}, len(indices)) links := make([]interface{}, len(indices))
@ -111,8 +113,13 @@ func TestRender_IssueIndexPattern2(t *testing.T) {
expectedNil := fmt.Sprintf(expectedFmt, links...) expectedNil := fmt.Sprintf(expectedFmt, links...)
testRenderIssueIndexPattern(t, s, expectedNil, &RenderContext{Metas: localMetas}) testRenderIssueIndexPattern(t, s, expectedNil, &RenderContext{Metas: localMetas})
class := "ref-issue"
if isExternal {
class += " ref-external-issue"
}
for i, index := range indices { for i, index := range indices {
links[i] = numericIssueLink(prefix, "ref-issue", index, marker) links[i] = numericIssueLink(prefix, class, index, marker)
} }
expectedNum := fmt.Sprintf(expectedFmt, links...) expectedNum := fmt.Sprintf(expectedFmt, links...)
testRenderIssueIndexPattern(t, s, expectedNum, &RenderContext{Metas: numericMetas}) testRenderIssueIndexPattern(t, s, expectedNum, &RenderContext{Metas: numericMetas})
@ -178,7 +185,7 @@ func TestRender_IssueIndexPattern4(t *testing.T) {
test := func(s, expectedFmt string, names ...string) { test := func(s, expectedFmt string, names ...string) {
links := make([]interface{}, len(names)) links := make([]interface{}, len(names))
for i, name := range names { for i, name := range names {
links[i] = alphanumIssueLink("https://someurl.com/someUser/someRepo/", "ref-issue", name) links[i] = alphanumIssueLink("https://someurl.com/someUser/someRepo/", "ref-issue ref-external-issue", name)
} }
expected := fmt.Sprintf(expectedFmt, links...) expected := fmt.Sprintf(expectedFmt, links...)
testRenderIssueIndexPattern(t, s, expected, &RenderContext{Metas: alphanumericMetas}) testRenderIssueIndexPattern(t, s, expected, &RenderContext{Metas: alphanumericMetas})

View File

@ -66,7 +66,7 @@ func createDefaultPolicy() *bluemonday.Policy {
} }
// Allow classes for anchors // Allow classes for anchors
policy.AllowAttrs("class").Matching(regexp.MustCompile(`ref-issue`)).OnElements("a") policy.AllowAttrs("class").Matching(regexp.MustCompile(`ref-issue( ref-external-issue)?`)).OnElements("a")
// Allow classes for task lists // Allow classes for task lists
policy.AllowAttrs("class").Matching(regexp.MustCompile(`task-list-item`)).OnElements("li") policy.AllowAttrs("class").Matching(regexp.MustCompile(`task-list-item`)).OnElements("li")

View File

@ -7,6 +7,9 @@ export default function initContextPopups() {
if (!refIssues.length) return; if (!refIssues.length) return;
refIssues.each(function () { refIssues.each(function () {
if ($(this).hasClass('ref-external-issue')) {
return;
}
const [index, _issues, repo, owner] = $(this).attr('href').replace(/[#?].*$/, '').split('/').reverse(); const [index, _issues, repo, owner] = $(this).attr('href').replace(/[#?].*$/, '').split('/').reverse();
const el = document.createElement('div'); const el = document.createElement('div');