Skip to content

Commit 6eae7e0

Browse files
committed
fix link and text
1 parent 8e5a654 commit 6eae7e0

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

src/content.js

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,21 @@ function makeUpdateLabel(time) {
169169
return `<time datetime="${time}" is="relative-time"></time>`;
170170
}
171171

172+
function issueOrPrLink(type, repoPath, contributor) {
173+
let end = `${type === "pr" ? "pulls" : "issues"}?utf8=%E2%9C%93&q=is:both+is:${type}+author:${contributor}`;
174+
175+
// repo
176+
if (repoPath.split("/").length === 2) {
177+
return `/${repoPath}/${end}`;
178+
// account
179+
} else if (repoPath === "__self") {
180+
return `https://github.com/${end}`;
181+
// org
182+
} else {
183+
return `https://github.com/${end}+user:${repoPath}`;
184+
}
185+
}
186+
172187
function injectInitialUI({ contributor, repoPath }) {
173188
let $elem = $(".timeline-comment-header-text").first();
174189
let prId = "gce-num-prs";
@@ -206,8 +221,8 @@ function injectInitialUI({ contributor, repoPath }) {
206221
</div>`;
207222

208223
$elem.before(`<span class="timeline-comment-label">
209-
<a href="/${repoPath}/pulls?utf8=%E2%9C%93&q=is:both+is:pr+author:${contributor}" id="${prId}">${prText}</a>
210-
<a href="/${repoPath}/issues?utf8=%E2%9C%93&q=is:both+is:issue+author:${contributor}" id="${issueId}">${issueText}</a>
224+
<a href="${issueOrPrLink("pr", repoPath, contributor)}" id="${prId}">${prText}</a>
225+
<a href="${issueOrPrLink("issue", repoPath, contributor)}" id="${issueId}">${issueText}</a>
211226
${dropdown}
212227
</span>
213228
`);
@@ -235,6 +250,10 @@ ${dropdown}
235250

236251
$inThisAccount.html("in this account");
237252
$inThisRepo.html("in this repo");
253+
254+
$(`#${prId}`).attr("href", issueOrPrLink("pr", repoPath.split("/")[0], contributor));
255+
$(`#${issueId}`).attr("href", issueOrPrLink("issue", repoPath.split("/")[0], contributor));
256+
238257
// global
239258
statsScope = "org";
240259
update(getContributorInfo());
@@ -250,6 +269,10 @@ ${dropdown}
250269

251270
$inThisAccount.html("in this account");
252271
$inThisOrg.html("in this org");
272+
273+
$(`#${prId}`).attr("href", issueOrPrLink("pr", repoPath, contributor));
274+
$(`#${issueId}`).attr("href", issueOrPrLink("issue", repoPath, contributor));
275+
253276
// global
254277
statsScope = "repo";
255278
update(getContributorInfo());
@@ -265,6 +288,10 @@ ${dropdown}
265288

266289
$inThisRepo.html("in this repo");
267290
$inThisOrg.html("in this org");
291+
292+
$(`#${prId}`).attr("href", issueOrPrLink("pr", "__self", contributor));
293+
$(`#${issueId}`).attr("href", issueOrPrLink("issue", "__self", contributor));
294+
268295
// global
269296
statsScope = "account";
270297
update(getContributorInfo());

0 commit comments

Comments
 (0)