summaryrefslogtreecommitdiff
path: root/source/features/patch-diff-links.tsx
blob: cd1c84d90df8966fee3a142ecea364fdcf15438b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import React from 'dom-chef';
import elementReady from 'element-ready';
import * as pageDetect from 'github-url-detection';

import features from '../feature-manager.js';
import {getCleanPathname} from '../github-helpers/index.js';

async function init(): Promise<void> {
	let commitUrl = '/' + getCleanPathname();

	// Avoids a redirection
	if (pageDetect.isPRCommit()) {
		commitUrl = commitUrl.replace(/\/pull\/\d+\/commits/, '/commit');
	}

	const commitMeta = await elementReady('.commit-meta')!;
	commitMeta!.classList.remove('no-wrap'); // #5987
	commitMeta!.lastElementChild!.append(
		<span className="sha-block" data-turbo="false">
			<a href={`${commitUrl}.patch`} className="sha">patch</a>
			{' '}
			<a href={`${commitUrl}.diff`} className="sha">diff</a>
		</span>,
	);
}

void features.add(import.meta.url, {
	include: [
		pageDetect.isCommit,
	],
	exclude: [
		pageDetect.isPRCommit404,
	],
	deduplicate: 'has-rgh-inner',
	init,
});