diff --git a/README.md b/README.md index f73b266..df9bb02 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,7 @@ Also: - Drop down menus are bigger! - Prompts to add links to work items are much less prominent, unless hovered over - "Show More" buttons on work item forms and on Kanban boards are auto-clicked for you! +- Work item forms show under the comment box who else is following the work item ## Documentation diff --git a/src/azdo-pr-dashboard.user.js b/src/azdo-pr-dashboard.user.js index 50d0553..84b15b4 100644 --- a/src/azdo-pr-dashboard.user.js +++ b/src/azdo-pr-dashboard.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name AzDO Pull Request Improvements -// @version 2.48.0 +// @version 2.49.0 // @author Alejandro Barreto (National Instruments) // @description Adds sorting and categorization to the PR dashboard. Also adds minor improvements to the PR diff experience, such as a base update selector and per-file checkboxes. // @license MIT @@ -63,6 +63,7 @@ // Invoke our new eus-style features. watchPullRequestDashboard(); watchForNewLabels(); + watchForWorkItemForms(); watchForNewDiffs(isDarkTheme); watchForShowMoreButtons(); @@ -210,6 +211,49 @@ }); } + function watchForWorkItemForms() { + // Annotate work items (under the comment box) with who is following it. + eus.globalSession.onEveryNew(document, '.discussion-messages-right', async commentEditor => { + const workItemId = commentEditor.closest('.witform-layout').querySelector('.work-item-form-id > span').innerText; + const queryResponse = await fetch(`${azdoApiBaseUrl}/_apis/notification/subscriptionquery?api-version=6.0`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + conditions: [ + { + filter: { + type: 'Artifact', + eventType: '', + artifactId: workItemId, + artifactType: 'WorkItem', + }, + }, + ], + }), + }); + + const followers = [...(await queryResponse.json()).value].sort((a, b) => a.subscriber.displayName.localeCompare(b.subscriber.displayName)); + + const commentFollowers = followers + .filter(workItemSubscriptionFollowsEverything) + .map(s => `${s.subscriber.displayName}`) + .join(', ') + || 'Nobody'; + + const fieldFollowerCount = followers.filter(s => !workItemSubscriptionFollowsEverything(s)).length; + const fieldFollowers = fieldFollowerCount ? `(and ${fieldFollowerCount} field follower${fieldFollowerCount > 1 ? 's' : ''})` : ''; + + const annotation = `
${commentFollowers} ${fieldFollowers}
`; + commentEditor.insertAdjacentHTML('BeforeEnd', annotation); + }); + } + + function workItemSubscriptionFollowsEverything(subscription) { + return subscription.description.startsWith("Following 'WorkItem' artifact"); + } + function watchForShowMoreButtons() { // Auto-click Show More buttons on work item forms, until they disappear or until we've pressed it 10 times (a reasonable limit which will still bring in 60 more items into view). eus.globalSession.onEveryNew(document, 'div[role="button"].la-show-more', async showMoreButton => {