-
Notifications
You must be signed in to change notification settings - Fork 354
/
url.js
146 lines (113 loc) · 4.66 KB
/
url.js
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// NB: Treeherder sets a Content-Security-Policy header in production, so when
// adding new domains *for use by fetch()*, update the `connect-src` directive:
// https://github.com/mozilla/treeherder/blob/master/treeherder/middleware.py
import tcLibUrls from 'taskcluster-lib-urls';
export const uiJobsUrlBase = '/#/jobs';
export const uiPushHealthBase = '/pushhealth.html';
export const bzBaseUrl = 'https://bugzilla.mozilla.org/';
export const hgBaseUrl = 'https://hg.mozilla.org/';
export const dxrBaseUrl = 'https://dxr.mozilla.org/';
export const bugsEndpoint = 'failures/';
export const bugDetailsEndpoint = 'failuresbybug/';
export const graphsEndpoint = 'failurecount/';
export const deployedRevisionUrl = '/revision.txt';
export const loginCallbackUrl = '/login.html';
export const pushEndpoint = '/push/';
export const repoEndpoint = '/repository/';
export const perfSummaryEndpoint = 'performance/summary/';
export const tcAuthCallbackUrl = '/taskcluster-auth.html';
export const getRunnableJobsURL = function getRunnableJobsURL(
decisionTask,
rootUrl,
) {
const { id, run } = decisionTask;
const tcUrl = tcLibUrls.withRootUrl(rootUrl);
const url = tcUrl.api(
'queue',
'v1',
`/task/${id}/runs/${run}/artifacts/public/runnable-jobs.json`,
);
return url;
};
export const createQueryParams = function createQueryParams(params) {
const query =
params instanceof URLSearchParams ? params : new URLSearchParams(params);
return `?${query.toString()}`;
};
// Leaving this here since even though SERVICE_DOMAIN no longer exists (proxying
// is used instead), it provides a single place to modify if needed in the future.
export const getServiceUrl = function getServiceUrl(uri) {
return uri;
};
export const getApiUrl = function getApiUrl(uri) {
return getServiceUrl(`/api${uri}`);
};
export const getBugUrl = function getBugUrl(bugId) {
return `${bzBaseUrl}show_bug.cgi?id=${bugId}`;
};
export const getInspectTaskUrl = function getInspectTaskUrl(
taskId,
rootUrl,
timestamp,
) {
// 1573257600 is the timestamp for the 2019-11-09 taskcluster migration date
const _rootUrl = timestamp < 1573257600 ? 'https://taskcluster.net' : rootUrl;
return tcLibUrls.ui(_rootUrl, `tasks/${taskId}`);
};
export const getReftestUrl = function getReftestUrl(logUrl) {
return `https://hg.mozilla.org/mozilla-central/raw-file/tip/layout/tools/reftest/reftest-analyzer.xhtml#logurl=${logUrl}&only_show_unexpected=1`;
};
// repoName here is necessary because this data comes from the /jobs endpoint
// which is a "project" endpoint that requires the project name. We shouldn't
// need that since the ids are unique across projects.
// Bug 1441938 - The project_bound_router is not needed and cumbersome in some cases
export const getLogViewerUrl = function getLogViewerUrl(
jobId,
repoName,
lineNumber,
) {
const rv = `logviewer.html#?job_id=${jobId}&repo=${repoName}`;
return lineNumber ? `${rv}&lineNumber=${lineNumber}` : rv;
};
export const getPerfAnalysisUrl = function getPerfAnalysisUrl(url) {
return `https://profiler.firefox.com/from-url/${encodeURIComponent(url)}`;
};
// This takes a plain object, rather than a URLSearchParams object.
export const getJobsUrl = function getJobsUrl(params) {
return `${uiJobsUrlBase}${createQueryParams(params)}`;
};
// This takes a plain object, rather than a URLSearchParams object.
export const getPushHealthUrl = function getJobsUrl(params) {
return `${uiPushHealthBase}${createQueryParams(params)}`;
};
export const getCompareChooserUrl = function getCompareChooserUrl(params) {
return `perf.html#/comparechooser${createQueryParams(params)}`;
};
export const parseQueryParams = function parseQueryParams(search) {
const params = new URLSearchParams(search);
return [...params.entries()].reduce(
(acc, [key, value]) => ({ ...acc, [key]: value }),
{},
);
};
// TODO: Combine this with getApiUrl().
export const createApiUrl = function createApiUrl(api, params) {
const query = createQueryParams(params);
return `/api/${api}${query}`;
};
// bugs can be one bug or a comma separated (no spaces) string of bugs
export const bugzillaBugsApi = function bugzillaBugsApi(api, params) {
const query = createQueryParams(params);
return `${bzBaseUrl}rest/${api}${query}`;
};
export const getRevisionUrl = (revision, projectName) =>
revision ? getJobsUrl({ repo: projectName, revision }) : '';
export const updateQueryParams = function updateHistoryWithQueryParams(
queryParams,
history,
location,
) {
history.replace({ pathname: location.pathname, search: queryParams });
// we do this so the api's won't be called twice (location/history updates will trigger a lifecycle hook)
location.search = queryParams;
};