<commit_before>import {h} from 'dom-chef';
import select from 'select-dom';
import {safeElementReady, wrap} from '../libs/utils';
import * as pageDetect from '../libs/page-detect';

export function inPR() {
	let deletedBranch = false;
	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();
	for (const el of select.all('.commit-ref[title], .base-ref[title], .head-ref[title]')) {
		urls.set(el.textContent.trim(), '/' + el.title.replace(':', '/tree/'));
	}

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

		if (branchName === deletedBranch) {
			el.title = 'Deleted';
			el.style.textDecoration = 'line-through';
		} else if (branchName !== 'unknown repository') {
			wrap(el, <a href={urls.get(branchName)}></a>);
		}
	}
}

export async function inQuickPR() {
	const el = await safeElementReady('.branch-name');
	if (el) {
		const {ownerName, repoName} = pageDetect.getOwnerAndRepo();
		const branchUrl = `/${ownerName}/${repoName}/tree/${el.textContent}`;
		wrap(el.closest('.branch-name'), <a href={branchUrl}></a>);
	}
}<commit_msg>Linkify non-URL-friendly branch names in PRs (#986)<commit_after>import {h} from 'dom-chef';
import select from 'select-dom';
import {safeElementReady, wrap} from '../libs/utils';
import * as pageDetect from '../libs/page-detect';

export function inPR() {
	let deletedBranch = false;
	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();
	for (const el of select.all('.commit-ref[title], .base-ref[title], .head-ref[title]')) {
		const [repo, branch] = el.title.split(':');
		urls.set(
			el.textContent.trim(),
			`/${repo}/tree/${encodeURIComponent(branch)}`
		);
	}

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

		if (branchName === deletedBranch) {
			el.title = 'Deleted';
			el.style.textDecoration = 'line-through';
		} else if (branchName !== 'unknown repository') {
			wrap(el, <a href={urls.get(branchName)}></a>);
		}
	}
}

export async function inQuickPR() {
	const el = await safeElementReady('.branch-name');
	if (el) {
		const {ownerName, repoName} = pageDetect.getOwnerAndRepo();
		const branchUrl = `/${ownerName}/${repoName}/tree/${el.textContent}`;
		wrap(el.closest('.branch-name'), <a href={branchUrl}></a>);
	}
}
{'fraction_non_alphanumeric': 0.18063186813186813, 'fraction_numerical': 0.0010302197802197802, 'mean_word_length': 4.4858757062146895, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1674065', 'n_tokens_mistral': 1030, 'n_tokens_neox': 999, 'n_words': 216}