import React from 'dom-chef'; import select from 'select-dom'; import * as pageDetect from 'github-url-detection'; import PullRequestIcon from 'octicon/git-pull-request.svg'; import features from '.'; import * as api from '../github-helpers/api'; import {buildRepoURL} from '../github-helpers'; import getDefaultBranch from '../github-helpers/get-default-branch'; interface BranchInfo { baseRef: string; baseRefName: string; } function buildQuery(issueIds: string[]): string { return ` repository() { ${issueIds.map(id => ` ${id}: pullRequest(number: ${id.replace(/\D/g, '')}) { baseRef {id} baseRefName } `).join('\n')} } `; } async function init(): Promise { const prLinks = select.all('.js-issue-row .js-navigation-open[data-hovercard-type="pull_request"]'); if (prLinks.length === 0) { return false; } const query = buildQuery(prLinks.map(pr => pr.id)); const [data, defaultBranch] = await Promise.all([ api.v4(query), getDefaultBranch() ]); for (const prLink of prLinks) { const pr: BranchInfo = data.repository[prLink.id]; if (pr.baseRefName === defaultBranch) { continue; } const branch = pr.baseRef && buildRepoURL(`tree/${pr.baseRefName}`); prLink.parentElement!.querySelector('.text-small.text-gray')!.append( {' To '} {pr.baseRefName} ); } } void features.add(__filebasename, { include: [ pageDetect.isRepoConversationList ], init });