diff --git a/src/azdo-pr-dashboard.user.js b/src/azdo-pr-dashboard.user.js index b148343..4be90d5 100644 --- a/src/azdo-pr-dashboard.user.js +++ b/src/azdo-pr-dashboard.user.js @@ -148,6 +148,10 @@ watchForRepoBrowsingPages(session); }); + eus.onUrl(/\/agentqueues(\?|\/)/gi, (session, urlMatch) => { + watchForAgentPage(session, pageData); + }); + // Throttle page update events to avoid using up CPU when AzDO is adding a lot of elements during a short time (like on page load). const onPageUpdatedThrottled = _.throttle(onPageUpdated, 400, { leading: false, trailing: true }); @@ -919,6 +923,47 @@ commentEditor.insertAdjacentHTML('BeforeEnd', annotation); } + async function watchForAgentPage(session, pageData) { + addStyleOnce('agent-css', /* css */ ` + .agent-icon{ + width: 10px; + height: 10px; + border-radius: 8px; + margin-right: 2px; + } + .agent-online{ + background: rgba(16, 124, 16, 1); + } + .agent-offline{ + background: rgba(205, 74, 69, 1); + } + .agent-enabled{ + background: rgba(16, 124, 16, 1); + } + .agent-disabled{ + background: rgba(200,200,200, 1); + } + `); + + const urlParams = new URLSearchParams(window.location.search); + const agentId = urlParams.get('agentId') || ''; + const queueId = urlParams.get('queueId') || ''; + const projectName = pageData['ms.vss-tfs-web.team-data']['team'].projectName; + const poolInfo = await getPoolInfoAsync(queueId, projectName); + const agentInfo = await getAgentInfoAsync(poolInfo['pool'].id, agentId); + + session.onEveryNew(document, '.bolt-header-title', section => { + if(section.innerText == agentInfo.name) { + const state = (agentInfo.enabled) ? "enabled" :"disabled"; + const blockingAnnotation2 = ` +
${agentInfo.status}
+
${state}
+ `; + section.insertAdjacentHTML('afterend', blockingAnnotation2); + } + }); + } + function watchForRepoBrowsingPages(session) { // Add a copy branch button. session.onEveryNew(document, '.version-dropdown > button', versionSelector => { @@ -2213,5 +2258,15 @@ return ownersInfo; } + // Async helper function get info on Pool + function getPoolInfoAsync(queueId, projectName) { + return $.get(`${azdoApiBaseUrl}/${projectName}/_apis/distributedtask/queues/${queueId}?api-version=5.0`); + } + + // Async helper function get info on agent + function getAgentInfoAsync(poolId, agentId) { + return $.get(`${azdoApiBaseUrl}/_apis/distributedtask/pools/${poolId}/agents/${agentId}?api-version=5.0`); + } + main(); }());