Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
46 changes: 45 additions & 1 deletion src/azdo-pr-dashboard.user.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -63,6 +63,7 @@
// Invoke our new eus-style features.
watchPullRequestDashboard();
watchForNewLabels();
watchForWorkItemForms();
watchForNewDiffs(isDarkTheme);
watchForShowMoreButtons();

Expand Down Expand Up @@ -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 => `<a href="mailto:${s.subscriber.uniqueName}">${s.subscriber.displayName}</a>`)
.join(', ')
|| 'Nobody';

const fieldFollowerCount = followers.filter(s => !workItemSubscriptionFollowsEverything(s)).length;
const fieldFollowers = fieldFollowerCount ? `(and ${fieldFollowerCount} field follower${fieldFollowerCount > 1 ? 's' : ''})` : '';

const annotation = `<div style="margin: 1em 0em; opacity: 0.8"><span class="menu-item-icon bowtie-icon bowtie-watch-eye-fill" aria-hidden="true"></span> ${commentFollowers} ${fieldFollowers}</div>`;
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 => {
Expand Down