Skip to content

Commit 48b127b

Browse files
Merge pull request #224 from alejandro5042/addParticipatesInRelease
Add Icon for PARTICIPATES_IN_RELEASE
2 parents 71c9299 + 9abb14f commit 48b127b

File tree

1 file changed

+71
-50
lines changed

1 file changed

+71
-50
lines changed

src/azdo-pr-dashboard.user.js

+71-50
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ==UserScript==
22

33
// @name More Awesome Azure DevOps (userscript)
4-
// @version 3.5.1
4+
// @version 3.5.2
55
// @author Alejandro Barreto (NI)
66
// @description Makes general improvements to the Azure DevOps experience, particularly around pull requests. Also contains workflow improvements for NI engineers.
77
// @license MIT
@@ -283,6 +283,18 @@
283283
cursor: not-allowed;
284284
color: #b1b1b1;
285285
}
286+
.agent-name-span {
287+
width: calc(100% - 60px);
288+
}
289+
.capabilities-holder {
290+
font-size: 20px;
291+
text-align: left;
292+
width: 40px;
293+
margin-right: 20px;
294+
overflow: hidden;
295+
text-overflow: ellipsis;
296+
}
297+
286298
`);
287299

288300
session.onEveryNew(document, '.pipelines-pool-agents.page-content.page-content-top', agentsTable => {
@@ -389,7 +401,6 @@
389401
regexFilter = new RegExp(regexFilterString, 'i');
390402
} catch (e) {
391403
showAllAgents(e);
392-
filterAgents.running = false;
393404
return;
394405
}
395406
document.getElementById('agentFilterCounter').innerText = 'Filtering...';
@@ -404,9 +415,8 @@
404415
error(e);
405416
}
406417

407-
let totalCount = 0;
408-
let matchedCount = 0;
409418
const agentRows = document.querySelectorAll('a.bolt-list-row.single-click-activation');
419+
const totalCount = agentRows.length;
410420

411421
const poolName = Array.from(document.querySelectorAll('div.bolt-breadcrumb-item-text-container')).pop().innerText;
412422
const currentPoolId = await fetchJsonAndCache(
@@ -419,7 +429,7 @@
419429

420430
const poolAgentsInfo = await fetchJsonAndCache(
421431
`azdoPool${poolName}IdAgents`,
422-
5,
432+
6,
423433
`${azdoApiBaseUrl}/_apis/distributedtask/pools/${currentPoolId}/agents?includeCapabilities=True&propertyFilters=*`,
424434
2,
425435
poolAgentsInfoWithCapabilities => {
@@ -428,6 +438,7 @@
428438
filteredAgentInfo[agentInfo.name] = {
429439
id: agentInfo.id,
430440
userCapabilities: agentInfo.userCapabilities,
441+
participatesInRelease: agentInfo.systemCapabilities.PARTICIPATES_IN_RELEASE,
431442
properties: agentInfo.properties,
432443
};
433444
});
@@ -436,65 +447,49 @@
436447
);
437448

438449
try {
439-
agentRows.forEach(agentRow => {
440-
totalCount += 1;
441-
agentRow.classList.remove('hiddenAgentRow');
442-
agentRow.classList.remove('visibleAgentRow');
450+
$('.hiddenAgentRow').show();
451+
$(agentRows).find('.disable-reason').remove();
452+
$(agentRows).find('.capabilities-holder').remove();
443453

444-
if (atNI) {
445-
addAgentDisableReason(agentRow, currentPoolId, poolAgentsInfo);
446-
addAgentArbitrationInformation(agentRow, currentPoolId, poolAgentsInfo);
447-
}
454+
const matchedAgents = {};
455+
agentRows.forEach(agentRow => {
456+
const agentCells = agentRow.querySelectorAll('div');
457+
const agentName = agentCells[1].innerText;
458+
const disableReason = (poolAgentsInfo[agentName].userCapabilities || {}).DISABLE_REASON || null;
448459

449-
const rowValue = agentRow.textContent.replace(/[\r\n]/g, '').trim();
460+
const rowValue = agentRow.textContent.replace(/[\r\n]/g, '').trim() + disableReason;
450461
if (!regexFilter.test(rowValue)) {
451462
agentRow.classList.add('hiddenAgentRow');
452463
} else {
453-
matchedCount += 1;
454-
agentRow.classList.add('visibleAgentRow');
464+
agentCells[1].querySelectorAll('span')[0].classList.add('agent-name-span');
465+
agentRow.classList.remove('hiddenAgentRow');
466+
if (atNI) {
467+
matchedAgents[agentName] = agentCells;
468+
}
455469
}
456470
});
457-
$('.visibleAgentRow').show();
458471
$('.hiddenAgentRow').hide();
459-
document.getElementById('agentFilterCounter').innerText = `(${matchedCount}/${totalCount})`;
472+
473+
for (const [agentName, agentCells] of Object.entries(matchedAgents)) {
474+
addAgentExtraInformation(agentCells, agentName, currentPoolId, poolAgentsInfo);
475+
}
476+
document.getElementById('agentFilterCounter').innerText = `(${Object.keys(matchedAgents).length}/${totalCount})`;
460477
} catch (e) {
461478
showAllAgents(e);
479+
return;
462480
}
481+
exitFilterAgents();
482+
}
463483

484+
function exitFilterAgents() {
485+
document.getElementById('agentFilterInput').readOnly = false;
464486
filterAgents.running = false;
465487
filterAgents.enter = false;
466-
document.getElementById('agentFilterInput').readOnly = false;
467-
}
468-
469-
function addAgentArbitrationInformation(agentRow, currentPoolId, poolAgentsInfo) {
470-
$(agentRow).find('.arbiter').remove();
471-
472-
if (document.body.classList.contains('agent-arbitration-status-off')) return;
473-
474-
const agentCells = agentRow.querySelectorAll('div');
475-
const agentName = agentCells[1].innerText;
476-
const agentInfo = poolAgentsInfo[agentName];
477-
478-
if (agentInfo.properties && Object.prototype.hasOwnProperty.call(agentInfo.properties, 'under_arbitration')) {
479-
const underArbitration = agentInfo.properties.under_arbitration.$value.toLowerCase() === 'true';
480-
const iconType = underArbitration ? 'CirclePause' : 'Airplane';
481-
482-
const arbitrationIcon = document.createElement('span');
483-
arbitrationIcon.className = `arbiter fabric-icon ms-Icon--${iconType}`;
484-
arbitrationIcon.title = underArbitration ? 'Arbitration Started: ' : 'Last Arbitration: ';
485-
arbitrationIcon.title += new Date(agentInfo.properties.arbitration_start.$value * 1000);
486-
arbitrationIcon.style = 'padding-right: 5px';
487-
488-
agentCells[2].prepend(arbitrationIcon);
489-
}
490488
}
491489

492-
function addAgentDisableReason(agentRow, currentPoolId, poolAgentsInfo) {
493-
const agentCells = agentRow.querySelectorAll('div');
494-
const agentName = agentCells[1].innerText;
490+
function addAgentExtraInformation(agentCells, agentName, currentPoolId, poolAgentsInfo) {
495491
const agentInfo = poolAgentsInfo[agentName];
496492

497-
$(agentRow).find('.disable-reason').remove();
498493
if (agentInfo.userCapabilities) {
499494
const disableReason = agentInfo.userCapabilities.DISABLE_REASON || null;
500495
if (disableReason) {
@@ -521,16 +516,42 @@
521516
$(agentCells[5]).prepend(disableReasonMessage);
522517
}
523518
}
519+
520+
const capabilitiesHolder = document.createElement('div');
521+
capabilitiesHolder.className = 'capabilities-holder';
522+
523+
const participatesInRelease = agentInfo.participatesInRelease || null;
524+
if (participatesInRelease === '1') {
525+
const participatesInReleaseElement = document.createElement('span');
526+
participatesInReleaseElement.className = 'capability-icon release-machine fabric-icon ms-Icon--Rocket';
527+
participatesInReleaseElement.title = 'PARTICIPATES_IN_RELEASE';
528+
capabilitiesHolder.append(participatesInReleaseElement);
529+
}
530+
531+
if (!document.body.classList.contains('agent-arbitration-status-off')) {
532+
if (agentInfo.properties && Object.prototype.hasOwnProperty.call(agentInfo.properties, 'under_arbitration')) {
533+
const underArbitration = agentInfo.properties.under_arbitration.$value.toLowerCase() === 'true';
534+
const iconType = underArbitration ? 'CirclePause' : 'Airplane';
535+
536+
const arbitrationIcon = document.createElement('span');
537+
arbitrationIcon.className = `capability-icon arbiter fabric-icon ms-Icon--${iconType}`;
538+
arbitrationIcon.title = underArbitration ? 'Arbitration Started: ' : 'Last Arbitration: ';
539+
arbitrationIcon.title += new Date(agentInfo.properties.arbitration_start.$value * 1000);
540+
541+
capabilitiesHolder.append(arbitrationIcon);
542+
}
543+
}
544+
545+
agentCells[1].append(capabilitiesHolder);
524546
}
525547

526548
function showAllAgents(searchError) {
527549
if (searchError) {
528550
document.getElementById('agentFilterCounter').innerText = searchError;
529551
}
530-
document.querySelectorAll('a.bolt-list-row.single-click-activation').forEach(agentRow => {
531-
$(agentRow).show();
532-
});
533-
document.getElementById('agentFilterRefresh').disabled = false;
552+
$('.hiddenAgentRow').show();
553+
$('.hiddenAgentRow').removeClass('hiddenAgentRow');
554+
exitFilterAgents();
534555
}
535556

536557
async function watchForReviewerList(session) {

0 commit comments

Comments
 (0)