blob: d1d0f9535f0a17039defb79d4e3b4b5d41f6f639 [file] [log] [blame]
Primiano Tuccie0ccef92017-10-03 10:43:20 -07001/**
2 * Copyright (c) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you
5 * may not use this file except in compliance with the License. You may
6 * obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 * implied. See the License for the specific language governing
14 * permissions and limitations under the License.
15 */
16
17'use strict';
18
19const REPO_URL = 'https://android.googlesource.com/platform/external/perfetto/';
20const GERRIT_REVIEW_URL = 'https://android-review.googlesource.com/c/platform/external/perfetto';
Primiano Tuccifecbb172017-12-19 15:05:37 +010021const CHANGES_URL = '/changes/?q=project:platform/external/perfetto+-age:7days+-is:abandoned&o=DETAILED_ACCOUNTS';
Primiano Tucci46e47192017-10-04 09:32:12 -070022const REPO = 'catapult-project/perfetto';
Primiano Tuccie0ccef92017-10-03 10:43:20 -070023
24let botIndex = {};
25
26// Builds a map of bot name -> column index, e.g.:
27// {'linux-clang-x86_64-relese' -> 1, 'android-clang-arm-debug' -> 2}.
28function GetColumnIndexes() {
29 const cols = document.getElementById('cls_header').children;
30 for (let i = 0; i < cols.length; i++) {
31 const id = cols[i].id;
32 if (id)
33 botIndex[id] = i + 4 /* 4 = subject...updated columns */;
34 }
35}
36
37function GetTravisStatusForJob(jobId, div) {
Lalit Maganti2044f392018-01-30 11:32:27 +000038 fetch('https://api.travis-ci.org/jobs/' + jobId)
39 .then(response => {
40 if (response.status != 200)
41 throw 'Unable to make request to Travis';
42 return response.json();
43 })
44 .then(resp => {
45 let jobName = resp.config.env.split(' ')[0];
46 if (jobName.startsWith('CFG='))
47 jobName = jobName.substring(4);
48 if (!(jobName in botIndex))
49 return;
50 let link = document.createElement('a');
51 link.href = 'https://travis-ci.org/' + REPO + '/jobs/' + jobId;
52 link.title = resp.state + ' [' + jobName + ']';
53 let jobState = resp.state;
54 if (resp.state == 'finished' && resp.result !== 0)
55 jobState = 'errored';
56 link.classList.add(jobState);
57 if (jobState == 'finished')
58 link.innerHTML = '<i class="material-icons">check_circle</i>';
59 else if (jobState == 'created')
60 link.innerHTML = '<i class="material-icons">autorenew</i>';
61 else if (jobState == 'errored' || jobState == 'cancelled')
62 link.innerHTML = '<i class="material-icons">bug_report</i>';
63 else
64 link.innerHTML = '<i class="material-icons">hourglass_full</i>';
65 let td = div.children[botIndex[jobName]];
66 td.innerHTML = '';
67 td.appendChild(link);
68 });
Primiano Tuccie0ccef92017-10-03 10:43:20 -070069}
70
71function GetTravisStatusForBranch(branch, div) {
Lalit Maganti2044f392018-01-30 11:32:27 +000072 fetch('https://api.travis-ci.org/repos/' + REPO + '/branches/' + branch)
73 .then(response => {
74 if (response.status != 200)
75 throw 'Unable to make request to Travis';
76 return response.json()
77 })
78 .then(resp => {
79 for (const jobId of resp.branch.job_ids)
80 GetTravisStatusForJob(jobId, div);
81 });
Primiano Tuccie0ccef92017-10-03 10:43:20 -070082}
83
Primiano Tuccie0ccef92017-10-03 10:43:20 -070084function CreateRowForBranch(branch, href, subject, status, author, updated) {
Lalit Maganti2044f392018-01-30 11:32:27 +000085 let table = document.getElementById('cls');
86 let tr = document.createElement('tr');
87 tr.classList.add(status);
Primiano Tuccie0ccef92017-10-03 10:43:20 -070088
Lalit Maganti2044f392018-01-30 11:32:27 +000089 let link = document.createElement('a');
90 link.href = href;
91 link.innerText = subject;
92 let td = document.createElement('td');
93 td.appendChild(link);
94 tr.appendChild(td);
Primiano Tuccie0ccef92017-10-03 10:43:20 -070095
Lalit Maganti2044f392018-01-30 11:32:27 +000096 td = document.createElement('td');
97 td.innerText = status;
98 tr.appendChild(td);
99
100 td = document.createElement('td');
101 td.innerText = author;
102 tr.appendChild(td);
103
104 td = document.createElement('td');
105 td.innerText = updated;
106 tr.appendChild(td);
107
108 for (let _ in botIndex) {
Primiano Tuccie0ccef92017-10-03 10:43:20 -0700109 td = document.createElement('td');
Lalit Maganti2044f392018-01-30 11:32:27 +0000110 td.classList.add('job');
Primiano Tuccie0ccef92017-10-03 10:43:20 -0700111 tr.appendChild(td);
Lalit Maganti2044f392018-01-30 11:32:27 +0000112 }
113 table.appendChild(tr);
114 GetTravisStatusForBranch(branch, tr);
Primiano Tuccie0ccef92017-10-03 10:43:20 -0700115}
116
117function LoadGerritCLs() {
Lalit Maganti2044f392018-01-30 11:32:27 +0000118 fetch(CHANGES_URL)
119 .then(response => {
120 if (response.status != 200)
121 throw 'Unable to make request to Travis';
Lalit Maganticf324a52018-01-30 14:58:48 +0000122 return response.text();
Lalit Maganti2044f392018-01-30 11:32:27 +0000123 })
124 .then(text => {
125 let json;
126 if (text.startsWith(')]}\''))
127 json = text.substring(4);
Primiano Tuccie0ccef92017-10-03 10:43:20 -0700128 else
Lalit Maganti2044f392018-01-30 11:32:27 +0000129 json = text;
130 let resp = JSON.parse(json);
131 for (const cl of resp) {
132 const branch = 'changes/' + cl._number;
133 const href = GERRIT_REVIEW_URL + '/+/' + cl._number;;
134 const lastUpdate = new Date(cl.updated + ' UTC');
135 const lastUpdateMins = Math.ceil((Date.now() - lastUpdate) / 60000);
136 let lastUpdateText = '';
137 if (lastUpdateMins < 60)
138 lastUpdateText = lastUpdateMins + ' mins ago';
139 else if (lastUpdateMins < 60 * 24)
140 lastUpdateText = Math.ceil(lastUpdateMins / 60) + ' hours ago';
141 else
142 lastUpdateText = lastUpdate.toLocaleDateString();
143 CreateRowForBranch(branch, href, cl.subject, cl.status,
144 cl.owner.email.replace('@google.com', '@'), lastUpdateText);
145 }
146 });
Primiano Tuccie0ccef92017-10-03 10:43:20 -0700147}
148
Lalit Maganti2044f392018-01-30 11:32:27 +0000149// Register the service worker to cache job requests.
150if ('serviceWorker' in navigator) {
151 navigator.serviceWorker.register('/service_worker.js', { scope: '/' });
152}
153
154// Fetch the CLs and the corresponding status for the Travis jobs.
Primiano Tuccie0ccef92017-10-03 10:43:20 -0700155GetColumnIndexes();
156CreateRowForBranch('master', REPO_URL, '*** master branch ***', 'MASTER', '', '');
157LoadGerritCLs();