From 08f6413b27636fa45f67e3df485b51b720794d7c Mon Sep 17 00:00:00 2001 From: Humberto Garza Date: Mon, 10 Jan 2022 18:50:09 -0600 Subject: [PATCH] Add agent status and enabled state to page summary --- src/azdo-pr-dashboard.user.js | 55 +++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/src/azdo-pr-dashboard.user.js b/src/azdo-pr-dashboard.user.js index dd4c913..8d0fa26 100644 --- a/src/azdo-pr-dashboard.user.js +++ b/src/azdo-pr-dashboard.user.js @@ -135,6 +135,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 }); @@ -621,6 +625,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 => { @@ -1914,5 +1959,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(); }());