Skip to content

Commit

Permalink
Check for multiple related issues in deep-reblame (#4443)
Browse files Browse the repository at this point in the history
  • Loading branch information
yakov116 committed Jun 4, 2021
1 parent 1a9c4f9 commit e948429
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions source/features/deep-reblame.tsx
Expand Up @@ -12,7 +12,7 @@ import GitHubURL from '../github-helpers/github-url';
import LoadingIcon from '../github-helpers/icon-loading';
import looseParseInt from '../helpers/loose-parse-int';

const getPullRequestBlameCommit = mem(async (commit: string, prNumber: number, currentFilename: string): Promise<string> => {
const getPullRequestBlameCommit = mem(async (commit: string, prNumbers: number[], currentFilename: string): Promise<string> => {
const {repository} = await api.v4(`
repository() {
file: object(expression: "${commit}:${currentFilename}") {
Expand Down Expand Up @@ -42,7 +42,7 @@ const getPullRequestBlameCommit = mem(async (commit: string, prNumber: number, c

const associatedPR = repository.object.associatedPullRequests.nodes[0];

if (!associatedPR || associatedPR.number !== prNumber || associatedPR.mergeCommit.oid !== commit) {
if (!associatedPR || !prNumbers.includes(associatedPR.number) || associatedPR.mergeCommit.oid !== commit) {
throw new Error('The PR linked in the title didn’t create this commit');
}

Expand All @@ -63,15 +63,15 @@ async function redirectToBlameCommit(event: delegate.Event<MouseEvent, HTMLAncho
blameElement.blur(); // Hide tooltip after click, it’s shown on :focus

const blameHunk = blameElement.closest('.blame-hunk')!;
const prNumber = looseParseInt(select('.issue-link', blameHunk)!);
const prNumbers = select.all('.issue-link', blameHunk).map(pr => looseParseInt(pr));
const prCommit = select('a.message', blameHunk)!.pathname.split('/').pop()!;
const blameUrl = new GitHubURL(location.href);

const spinner = <LoadingIcon className="mr-2"/>;
blameElement.firstElementChild!.replaceWith(spinner);

try {
blameUrl.branch = await getPullRequestBlameCommit(prCommit, prNumber, blameUrl.filePath);
blameUrl.branch = await getPullRequestBlameCommit(prCommit, prNumbers, blameUrl.filePath);
blameUrl.hash = 'L' + select('.js-line-number', blameHunk)!.textContent!;
location.href = String(blameUrl);
} catch (error: unknown) {
Expand Down

0 comments on commit e948429

Please sign in to comment.