-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.qml
397 lines (327 loc) · 12.7 KB
/
App.qml
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
import "./moment.js" as Moment
import QtQuick 2.15
import QtQuick.Controls 1.0
import QtQuick.Layouts 1.15
import QtQuick.Window 2.15
Window {
id: app
property var targetPipelines
property var pipelineStatuses
property int prCount
property var lastUpdateDate
property string currentTimeOdd: ""
property string currentTimeEven: ""
property int refreshIntervalSeconds: 16
property string targetRepository
property string targetBranch
property string githubToken
property int numColumns: 3
property int numRows: pipelineStatuses ? Math.ceil(pipelineStatuses.length / numColumns) : 1
function difftime(dateStr) {
const prev = Qt.moment(new Date(dateStr));
const duration = Qt.moment.duration(prev.diff(new Date()));
return `${duration.humanize()} ago `;
}
function httpGet(url) {
return new Promise((resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.timeout = 15000;
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
if (xhr.readyState !== XMLHttpRequest.DONE)
return ;
if (xhr.status && xhr.status === 200)
resolve(xhr.responseText);
else
reject(new Error(`GET failed with status ${xhr.status}: ${xhr.responseText}`));
};
xhr.setRequestHeader("X-GitHub-Api-Version", "2022-11-28");
xhr.setRequestHeader("Authorization", `Bearer ${app.githubToken}`);
xhr.send();
});
}
function refreshPRCount() {
httpGet(`https://api.github.com/repos/${app.targetRepository}/pulls`).then((response) => {
app.prCount = JSON.parse(response).length;
});
}
function initialLoad() {
httpGet(`https://api.github.com/repos/${app.targetRepository}/actions/workflows`).then((response) => {
app.targetPipelines = JSON.parse(response).workflows.filter((wf) => {
return wf.state === "active";
}).map((wf) => {
return {
"id": wf.id,
"name": wf.name,
"status": "",
"lastActor": "",
"timestamp": 0
};
});
}).catch((e) => {
return console.error("initial load failed", e);
});
}
function refresh() {
refreshPRCount();
const workflowRequests = targetPipelines.map((pl) => {
return httpGet(`https://api.github.com/repos/${app.targetRepository}/actions/workflows/${pl.id}/runs?branch=${app.targetBranch}`)
.then(res => ({
jsonResponse: JSON.parse(res),
workflowName: pl.name
})
);
});
Promise.all(workflowRequests).then((reqs) => {
app.pipelineStatuses = reqs.filter(({jsonResponse, workflowName}) => {
return jsonResponse.workflow_runs && jsonResponse.workflow_runs.length > 0;
}).map(({jsonResponse, workflowName}) => {
return { firstRun: jsonResponse.workflow_runs[0], workflowName};
}).map(({firstRun, workflowName}) => {
return {
"id": firstRun.workflow_id,
"name": firstRun.name,
"workflowName": workflowName,
"status": firstRun.conclusion,
"user": firstRun.actor.login,
"timestamp": firstRun.updated_at,
"run_number": firstRun.run_number
};
});
}).catch((e) => {
return console.error("refresh failed", e);
});
app.lastUpdateDate = new Date();
}
width: 1280
height: 720
color: "#071436"
onGithubTokenChanged: initialLoad()
onTargetPipelinesChanged: targetPipelines && refresh()
Component.onCompleted: {
httpGet("./config.json").then((fileContent) => {
const cfg = JSON.parse(fileContent);
app.targetRepository = cfg.repository;
app.githubToken = cfg.token;
app.targetBranch = cfg.branch;
if (typeof cfg.numColumns === "number")
app.numColumns = cfg.numColumns;
if (cfg.fullscreen)
showFullScreen();
}).catch((e) => {
return console.error("config failed", e);
});
}
Timer {
interval: 1000 * app.refreshIntervalSeconds
repeat: true
running: true
onTriggered: app.refresh()
}
Timer {
property int i: 0
interval: 500
repeat: true
running: true
onTriggered: {
if (i === 0)
currentTimeEven = `${Qt.moment().format('HH:mm:ss')}`;
else if (i === 1 || i === 3)
clockOddEven.odd = !clockOddEven.odd;
else if (i === 2)
currentTimeOdd = `${Qt.moment().format('HH:mm:ss')}`;
i = (i + 1) % 4;
}
}
Item {
id: container
width: parent.width * 0.95
height: parent.height * 0.95
anchors.centerIn: parent
Item {
id: header
width: parent.width - 20
height: parent.height * 0.125
anchors.horizontalCenter: parent.horizontalCenter
Text {
id: headerText
color: "white"
text: `<b>${app.targetBranch}</b> branch`
font.pointSize: 60
textFormat: Text.StyledText
}
ColumnLayout {
anchors.right: parent.right
anchors.top: parent.top
anchors.topMargin: 10
spacing: 1
Rectangle {
id: clockOddEven
property bool odd: true
color: "transparent"
Layout.alignment: Qt.AlignRight
Layout.preferredHeight: childrenRect.height
Layout.preferredWidth: childrenRect.width
states: [
State {
when: clockOddEven.odd
PropertyChanges {
target: oddElement
opacity: 1
}
PropertyChanges {
target: evenElement
opacity: 0
}
},
State {
when: !clockOddEven.odd
PropertyChanges {
target: oddElement
opacity: 0
}
PropertyChanges {
target: evenElement
opacity: 1
}
}
]
transitions: [
Transition {
NumberAnimation {
target: oddElement
properties: "opacity"
duration: 400
easing.type: Easing.OutInQuad
}
NumberAnimation {
target: evenElement
properties: "opacity"
duration: 400
easing.type: Easing.OutInQuad
}
}
]
Text {
id: evenElement
color: "white"
text: currentTimeEven
font.pointSize: 20
textFormat: Text.StyledText
font.family: "Courier New,courier"
font.bold: true
}
Text {
id: oddElement
opacity: 1
color: "white"
text: currentTimeOdd
font.pointSize: 20
textFormat: Text.StyledText
font.family: "Courier New,courier"
font.bold: true
}
}
Text {
id: prCounter
color: "white"
text: `<b>${app.prCount}</b> pull requests`
font.pointSize: 20
textFormat: Text.StyledText
Layout.alignment: Qt.AlignRight
}
Text {
id: updateTimestamp
color: "white"
text: `updated at <b>${Qt.moment(app.lastUpdateDate).format('HH:mm:ss')}</b>`
font.pointSize: 20
Layout.alignment: Qt.AlignRight
}
}
}
GridView {
id: grid
anchors.top: header.bottom
width: parent.width
height: parent.height - header.height
model: app.pipelineStatuses
cellWidth: parent.width / numColumns
cellHeight: grid.height / numRows
delegate: Item {
width: grid.cellWidth
height: grid.cellHeight
Rectangle {
function pickColor(status) {
if (status === "success")
return "#afff94";
if (status && status.includes("failure"))
return "#ff7e75";
return "#fffbb3";
}
width: parent.width - 20
height: parent.height - 20
anchors.centerIn: parent
color: pickColor(modelData["status"])
Item {
width: parent.width * 0.9
height: parent.height * 0.9
anchors.centerIn: parent
Text {
id: workflowName
font.pointSize: 24
font.bold: true
color: "black"
width: parent.width
text: modelData["workflowName"]
elide: Text.ElideRight
}
Text {
id: name
anchors.top: workflowName.bottom
height: modelData["workflowName"] === modelData["name"] ? 0 : 15
font.pointSize: 12
font.bold: true
color: "black"
width: parent.width
text: `#${modelData["run_number"]} ${modelData["name"]}`
elide: Text.ElideRight
}
Text {
id: statusText
font.pointSize: 22
anchors.top: name.bottom
anchors.topMargin: 4
color: "black"
text: modelData["status"]
}
Text {
id: actor
anchors.left: parent.left
anchors.bottom: parent.bottom
font.pointSize: 20
color: "black"
text: modelData["user"]
}
Text {
id: time
anchors.right: parent.right
anchors.bottom: parent.bottom
font.pointSize: 18
color: "black"
text: difftime(modelData["timestamp"])
Timer {
interval: 1000 * 60
repeat: true
running: true
triggeredOnStart: true
onTriggered: {
time.text = app.difftime(modelData["timestamp"]);
}
}
}
}
}
}
}
}
}