Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/PR Context Popups #9822

Merged
merged 24 commits into from
Jan 20, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
636b677
Add data-index attribute to issue anchors
jolheiser Jan 15, 2020
0bb692c
Init JS
jolheiser Jan 15, 2020
04a1fbd
Add required data to anchor
jolheiser Jan 16, 2020
418185c
Finish popup
jolheiser Jan 17, 2020
7ca20c8
Revert changes to html.go
jolheiser Jan 17, 2020
3a45b8c
Better octicon contexts
jolheiser Jan 17, 2020
0335c82
Split out popup function for re-use
jolheiser Jan 17, 2020
4173fe3
Merge branch 'master' into popup_issue
lafriks Jan 17, 2020
79789a6
Merge branch 'master' into popup_issue
sapk Jan 17, 2020
c1b562e
Style changes, test fixes, and cross-reference support
jolheiser Jan 17, 2020
dfe7730
Prefer em to px
jolheiser Jan 17, 2020
9fee588
Move label margin to base CSS
jolheiser Jan 17, 2020
b9a3121
Move JS to separate file.
jolheiser Jan 17, 2020
9efe7e0
Move JS to features and fix module
jolheiser Jan 17, 2020
c8b7cdd
Merge branch 'master' into popup_issue
jolheiser Jan 17, 2020
bbdc8ba
Remove query-string and hash
jolheiser Jan 17, 2020
1452ea7
Merge branch 'master' into popup_issue
sapk Jan 17, 2020
4d60119
Merge branch 'master' into popup_issue
jolheiser Jan 17, 2020
78971f1
Merge branch 'master' into popup_issue
lunny Jan 18, 2020
d68b7d8
Merge branch 'master' into popup_issue
zeripath Jan 19, 2020
9aea76f
Merge branch 'master' into popup_issue
lunny Jan 19, 2020
6b758f3
Merge branch 'master' into popup_issue
lunny Jan 20, 2020
f605e23
Merge branch 'master' into popup_issue
lunny Jan 20, 2020
c8c7b3d
Merge branch 'master' into popup_issue
lunny Jan 20, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions modules/markup/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -636,11 +636,11 @@ func fullIssuePatternProcessor(ctx *postProcessCtx, node *html.Node) {
if matchOrg == ctx.metas["user"] && matchRepo == ctx.metas["repo"] {
// TODO if m[4]:m[5] is not nil, then link is to a comment,
// and we should indicate that in the text somehow
replaceContent(node, m[0], m[1], createLink(link, id, "issue"))
replaceContent(node, m[0], m[1], createLink(link, id, "ref-issue"))

} else {
orgRepoID := matchOrg + "/" + matchRepo + id
replaceContent(node, m[0], m[1], createLink(link, orgRepoID, "issue"))
replaceContent(node, m[0], m[1], createLink(link, orgRepoID, "ref-issue"))
}
}

Expand Down Expand Up @@ -676,7 +676,7 @@ func issueIndexPatternProcessor(ctx *postProcessCtx, node *html.Node) {
reftext := node.Data[ref.RefLocation.Start:ref.RefLocation.End]
if exttrack && !ref.IsPull {
ctx.metas["index"] = ref.Issue
link = createLink(com.Expand(ctx.metas["format"], ctx.metas), reftext, "issue")
link = createLink(com.Expand(ctx.metas["format"], ctx.metas), reftext, "ref-issue")
} else {
// 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
Expand All @@ -686,9 +686,9 @@ func issueIndexPatternProcessor(ctx *postProcessCtx, node *html.Node) {
path = "pulls"
}
if ref.Owner == "" {
link = createLink(util.URLJoin(setting.AppURL, ctx.metas["user"], ctx.metas["repo"], path, ref.Issue), reftext, "issue")
link = createLink(util.URLJoin(setting.AppURL, ctx.metas["user"], ctx.metas["repo"], path, ref.Issue), reftext, "ref-issue")
} else {
link = createLink(util.URLJoin(setting.AppURL, ref.Owner, ref.Name, path, ref.Issue), reftext, "issue")
link = createLink(util.URLJoin(setting.AppURL, ref.Owner, ref.Name, path, ref.Issue), reftext, "ref-issue")
}
}

Expand Down
14 changes: 7 additions & 7 deletions modules/markup/html_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ func TestRender_IssueIndexPattern2(t *testing.T) {

links := make([]interface{}, len(indices))
for i, index := range indices {
links[i] = numericIssueLink(util.URLJoin(setting.AppSubURL, path), "issue", index, marker)
links[i] = numericIssueLink(util.URLJoin(setting.AppSubURL, path), "ref-issue", index, marker)
}
expectedNil := fmt.Sprintf(expectedFmt, links...)
testRenderIssueIndexPattern(t, s, expectedNil, &postProcessCtx{metas: localMetas})

for i, index := range indices {
links[i] = numericIssueLink(prefix, "issue", index, marker)
links[i] = numericIssueLink(prefix, "ref-issue", index, marker)
}
expectedNum := fmt.Sprintf(expectedFmt, links...)
testRenderIssueIndexPattern(t, s, expectedNum, &postProcessCtx{metas: numericMetas})
Expand Down Expand Up @@ -178,7 +178,7 @@ func TestRender_IssueIndexPattern4(t *testing.T) {
test := func(s, expectedFmt string, names ...string) {
links := make([]interface{}, len(names))
for i, name := range names {
links[i] = alphanumIssueLink("https://someurl.com/someUser/someRepo/", "issue", name)
links[i] = alphanumIssueLink("https://someurl.com/someUser/someRepo/", "ref-issue", name)
}
expected := fmt.Sprintf(expectedFmt, links...)
testRenderIssueIndexPattern(t, s, expected, &postProcessCtx{metas: alphanumericMetas})
Expand Down Expand Up @@ -217,7 +217,7 @@ func TestRender_AutoLink(t *testing.T) {

// render valid issue URLs
test(util.URLJoin(setting.AppSubURL, "issues", "3333"),
numericIssueLink(util.URLJoin(setting.AppSubURL, "issues"), "issue", 3333, "#"))
numericIssueLink(util.URLJoin(setting.AppSubURL, "issues"), "ref-issue", 3333, "#"))

// render valid commit URLs
tmp := util.URLJoin(AppSubURL, "commit", "d8a994ef243349f321568f9e36d5c3f444b99cae")
Expand Down Expand Up @@ -248,11 +248,11 @@ func TestRender_FullIssueURLs(t *testing.T) {
test("Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6",
"Here is a link https://git.osgeo.org/gogs/postgis/postgis/pulls/6")
test("Look here http://localhost:3000/person/repo/issues/4",
`Look here <a href="http://localhost:3000/person/repo/issues/4" class="issue">person/repo#4</a>`)
`Look here <a href="http://localhost:3000/person/repo/issues/4" class="ref-issue">person/repo#4</a>`)
test("http://localhost:3000/person/repo/issues/4#issuecomment-1234",
`<a href="http://localhost:3000/person/repo/issues/4#issuecomment-1234" class="issue">person/repo#4</a>`)
`<a href="http://localhost:3000/person/repo/issues/4#issuecomment-1234" class="ref-issue">person/repo#4</a>`)
test("http://localhost:3000/gogits/gogs/issues/4",
`<a href="http://localhost:3000/gogits/gogs/issues/4" class="issue">#4</a>`)
`<a href="http://localhost:3000/gogits/gogs/issues/4" class="ref-issue">#4</a>`)
}

func TestRegExp_sha1CurrentPattern(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions modules/markup/html_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ func TestRender_CrossReferences(t *testing.T) {

test(
"gogits/gogs#12345",
`<p><a href="`+util.URLJoin(AppURL, "gogits", "gogs", "issues", "12345")+`" rel="nofollow">gogits/gogs#12345</a></p>`)
`<p><a href="`+util.URLJoin(AppURL, "gogits", "gogs", "issues", "12345")+`" class="ref-issue" rel="nofollow">gogits/gogs#12345</a></p>`)
test(
"go-gitea/gitea#12345",
`<p><a href="`+util.URLJoin(AppURL, "go-gitea", "gitea", "issues", "12345")+`" rel="nofollow">go-gitea/gitea#12345</a></p>`)
`<p><a href="`+util.URLJoin(AppURL, "go-gitea", "gitea", "issues", "12345")+`" class="ref-issue" rel="nofollow">go-gitea/gitea#12345</a></p>`)
test(
"/home/gitea/go-gitea/gitea#12345",
`<p>/home/gitea/go-gitea/gitea#12345</p>`)
Expand Down
4 changes: 2 additions & 2 deletions modules/markup/markdown/markdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func testAnswers(baseURLContent, baseURLImages string) []string {
<p>See commit <a href="http://localhost:3000/gogits/gogs/commit/65f1bf27bc" rel="nofollow"><code>65f1bf27bc</code></a></p>
<p>Ideas and codes</p>
<ul>
<li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="http://localhost:3000/ocornut/imgui/issues/786" rel="nofollow">ocornut/imgui#786</a></li>
<li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="http://localhost:3000/gogits/gogs/issues/786" rel="nofollow">#786</a></li>
<li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="http://localhost:3000/ocornut/imgui/issues/786" class="ref-issue" rel="nofollow">ocornut/imgui#786</a></li>
<li>Bezier widget (by <a href="` + AppURL + `r-lyeh" rel="nofollow">@r-lyeh</a>) <a href="http://localhost:3000/gogits/gogs/issues/786" class="ref-issue" rel="nofollow">#786</a></li>
<li>Node graph editors <a href="https://github.com/ocornut/imgui/issues/306" rel="nofollow">https://github.com/ocornut/imgui/issues/306</a></li>
<li><a href="` + baseURLContent + `/memory_editor_example" rel="nofollow">Memory Editor</a></li>
<li><a href="` + baseURLContent + `/plot_var_example" rel="nofollow">Plot var helper</a></li>
Expand Down
3 changes: 3 additions & 0 deletions modules/markup/sanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func ReplaceSanitizer() {
// Allow <kbd> tags for keyboard shortcut styling
sanitizer.policy.AllowElements("kbd")

// Allow classes for anchors
sanitizer.policy.AllowAttrs("class").Matching(regexp.MustCompile(`ref-issue`)).OnElements("a")

// Custom keyword markup
for _, rule := range setting.ExternalSanitizerRules {
if rule.Regexp != nil {
Expand Down
67 changes: 67 additions & 0 deletions web_src/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2319,6 +2319,72 @@ function initTemplateSearch() {
changeOwner();
}

function issuePopup(owner, repo, index, $element) {
$.get(`${suburl}/api/v1/repos/${owner}/${repo}/issues/${index}`, (issue) => {
const createdAt = new Date(issue.created_at).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric' });

let body = issue.body.replace(/\n+/g, ' ');
if (body.length > 85) {
body = `${body.substring(0, 85)}...`;
}

let labels = '';
for (let i = 0; i < issue.labels.length; i++) {
const label = issue.labels[i];
const red = parseInt(label.color.substring(0, 2), 16);
const green = parseInt(label.color.substring(2, 4), 16);
const blue = parseInt(label.color.substring(4, 6), 16);
let color = '#ffffff';
if ((red * 0.299 + green * 0.587 + blue * 0.114) > 125) {
color = '#000000';
}
labels += `<div class="ui label" style="color: ${color}; background-color:#${label.color};">${label.name}</div>`;
}
if (labels.length > 0) {
labels = `<p>${labels}</p>`;
}

let octicon;
if (issue.pull_request !== null) {
if (issue.state === 'open') {
octicon = 'green octicon-git-pull-request'; // Open PR
} else if (issue.pull_request.merged === true) {
octicon = 'purple octicon-git-merge'; // Merged PR
} else {
octicon = 'red octicon-git-pull-request'; // Closed PR
}
} else if (issue.state === 'open') {
octicon = 'green octicon-issue-opened'; // Open Issue
} else {
octicon = 'red octicon-issue-closed'; // Closed Issue
}

$element.popup({
variation: 'wide',
delay: {
show: 250
},
html: `<div>
<p><small>${issue.repository.full_name} on ${createdAt}</small></p>
<p><i class="octicon ${octicon}"></i> <strong>${issue.title}</strong> #${index}</p>
<p>${body}</p>
${labels}
</div>`
jolheiser marked this conversation as resolved.
Show resolved Hide resolved
});
});
}

function initIssuePopup() {
$('.ref-issue').each(function () {
const href = $(this).attr('href').split('/');
jolheiser marked this conversation as resolved.
Show resolved Hide resolved
const index = href.pop();
href.pop(); // issues
const repo = href.pop();
const owner = href.pop();
issuePopup(owner, repo, index, $(this));
});
}

$(document).ready(() => {
csrf = $('meta[name=_csrf]').attr('content');
suburl = $('meta[name=_suburl]').attr('content');
Expand Down Expand Up @@ -2556,6 +2622,7 @@ $(document).ready(() => {
initPullRequestReview();
initRepoStatusChecker();
initTemplateSearch();
initIssuePopup();

// Repo clone url.
if ($('#repo-clone-url').length > 0) {
Expand Down
16 changes: 16 additions & 0 deletions web_src/less/_base.less
Original file line number Diff line number Diff line change
Expand Up @@ -1185,3 +1185,19 @@ i.icon.centerlock {
vertical-align: middle;
height: 2.1666em !important;
}

.octicon {
&.green {
color: #21ba45;
}
&.red {
color: #db2828;
}
&.purple {
color: #a333c8;
}
}

.ui.popup .ui.label {
margin-bottom: 0.4em;
}
10 changes: 10 additions & 0 deletions web_src/less/themes/arc-green.less
Original file line number Diff line number Diff line change
Expand Up @@ -1463,3 +1463,13 @@ a.ui.labels .label:hover {
}
}
}

.ui.popup {
background-color: #383c4a;
color: #9e9e9e;
border-color: #9e9e9e;

&.top::before {
background-color: #383c4a;
}
}