Skip to content

Commit

Permalink
Drop generic linkifier from linkify-branch-refs
Browse files Browse the repository at this point in the history
Closes #2275
Partial solution to #1985
  • Loading branch information
fregante committed Jul 29, 2019
1 parent d0eaed3 commit cb8de12
Showing 1 changed file with 1 addition and 53 deletions.
54 changes: 1 addition & 53 deletions source/features/linkify-branch-refs.tsx
@@ -1,53 +1,10 @@
import React from 'dom-chef';
import select from 'select-dom';
import elementReady from 'element-ready';
import features from '../libs/features';
import * as pageDetect from '../libs/page-detect';
import {getOwnerAndRepo} from '../libs/utils';
import {wrap} from '../libs/dom-utils';

function inPR(): void {
let deletedBranch: string | undefined;
const lastBranchAction = select.all(`
.discussion-item-head_ref_deleted .commit-ref,
.discussion-item-head_ref_restored .commit-ref
`).pop();
if (lastBranchAction && lastBranchAction.closest('.discussion-item-head_ref_deleted')) {
deletedBranch = lastBranchAction.textContent!.trim();
}

// Find the URLs first, some elements don't have titles
const urls = new Map<string, string>();
for (const el of select.all('.commit-ref[title], .base-ref[title], .head-ref[title]')) {
const [repo, branch] = el.title.split(':');
const branchName = el.textContent!.trim();
urls.set(
branchName,
`/${repo}`
);
if (branchName !== deletedBranch) {
urls.set(
branchName,
`/${repo}/tree/${encodeURIComponent(branch)}`
);
}
}

for (const el of select.all('.commit-ref')) {
const branchName = el.textContent!.trim();

if (branchName !== 'unknown repository') {
if (branchName === deletedBranch) {
el.title = 'Deleted';
el.style.textDecoration = 'line-through';
}

wrap(el, <a href={urls.get(branchName)}></a>);
}
}
}

async function inQuickPR(): Promise<void> {
async function init(): Promise<void> {
const el = await elementReady('.branch-name');
if (el) {
const {ownerName, repoName} = getOwnerAndRepo();
Expand All @@ -56,19 +13,10 @@ async function inQuickPR(): Promise<void> {
}
}

function init(): void {
if (pageDetect.isPR()) {
inPR();
} else if (pageDetect.isQuickPR()) {
inQuickPR();
}
}

features.add({
id: __featureName__,
description: 'Click on branch references in pull requests',
include: [
features.isPR,
features.isQuickPR
],
load: features.onAjaxedPages,
Expand Down

0 comments on commit cb8de12

Please sign in to comment.