summaryrefslogtreecommitdiff
path: root/source/features/view-last-pr-deployment.tsx
blob: 17f3ff91365f6fe35815ec75e41ab0f73c7acfc6 (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
37
38
39
40
41
42
43
44
import React from 'dom-chef';
import {lastElement} from 'select-dom';
import * as pageDetect from 'github-url-detection';
import {RocketIcon} from '@primer/octicons-react';

import features from '../feature-manager.js';
import observe from '../helpers/selector-observer.js';

function addLink(header: HTMLElement): void {
	const lastDeployment = lastElement('.js-timeline-item a[title="Deployment has completed"]');
	if (!lastDeployment) {
		return;
	}

	header.prepend(
		<a
			className="rgh-last-deployment btn btn-sm d-none d-md-block mr-1"
			target="_blank" // Matches GitHub’s own behavior
			rel="noopener noreferrer"
			href={lastDeployment.href}
		>
			<RocketIcon className="mr-1 v-align-text-top"/>
			Latest deployment
		</a>,
	);
}

function init(signal: AbortSignal): void {
	observe('.gh-header-actions', addLink, {signal});
}

void features.add(import.meta.url, {
	include: [
		pageDetect.isPRConversation,
	],
	awaitDomReady: true, // Must select last item on the page
	init,
});

// TODO: Needs a URL with multiple deployments and deactivated deployments
/*
Test URLs:
https://github.com/fregante/bundle/pull/2
*/