diff --git a/manifest.json b/manifest.json index b872e2b..eef550a 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Sage's BitBucket Addon", "description": "Ensure searches don't include forks (and other enhancements)", - "version": "1.0.18", + "version": "1.0.19", "manifest_version": 2, "browser_specific_settings": { "gecko": { @@ -30,6 +30,7 @@ "backtick-comments.js", "csharp-quotes.js", "file-scroll.js", + "pr-reviewer-suggestions.js", "repo-search-sorter.js", "show-errored-prs.js", "var-highlighter.js" diff --git a/pr-reviewer-suggestions.js b/pr-reviewer-suggestions.js new file mode 100644 index 0000000..6081974 --- /dev/null +++ b/pr-reviewer-suggestions.js @@ -0,0 +1,69 @@ +if (location.toString().includes('/pull-requests?create')) { + const names = [ + "Tam Nguyen", + "David Daniel", + "Nikalas Culvey", + "Michael Mezzina", + "Sage Vaillancourt", + "John Cyr", + "Adam Weizman", + "Caleb Soper", + "Rockey Liles", + "Fernando Batista" + ] + + const urlPrefix = 'https://git.add123.com/rest/api/latest' + + fetch(`${urlPrefix}/projects/ADD/repos?limit=999`) + .then(resp => resp.json()) + .then(async ({values: allRepos}) => { + const prListUrls = allRepos.map(repo => `${urlPrefix}/projects/ADD/repos/${repo.slug}/pull-requests`) + const allPullRequests = (await Promise.all( + prListUrls.map(async prListUrl => await fetch(prListUrl).then(resp => resp.json()))) + ).flatMap(({values}) => values) + + const reviewerCounts = Object.fromEntries(names.map(name => [name, 0])) + allPullRequests.forEach(({reviewers}) => { + reviewers?.map(r => r.user.displayName) + .filter(displayName => !["Chris Gamache", "Tom Keels"].includes(displayName)) + .forEach(displayName => { + reviewerCounts[displayName] ??= 0 + reviewerCounts[displayName] += 1 + }) + }) + const sortedCounts = Object.entries(reviewerCounts) + .map(([name, count]) => ({ name, count })) + .toSorted((a, b) => a.count - b.count) + const tryDisplay = () => setTimeout(() => { + if (document.getElementById('reviewer-counts')) { + return + } + const formBodyMain = document.querySelector('.create-pull-request-form .form-body .form-body-main') + if (formBodyMain) { + const countsParent = formBodyMain.lastChild.cloneNode(true) + const reviewerCountsNode = document.createElement('ol') + reviewerCountsNode.id = 'reviewer-counts' + reviewerCountsNode.style.columns = '3' + reviewerCountsNode.style.listStyle = 'none' + reviewerCountsNode.style.paddingLeft = '2px' + reviewerCountsNode.style.marginTop = 'auto' + // reviewerCountsNode.style.lineHeight = '95%' + reviewerCountsNode.style.fontSize = '0.9em' + sortedCounts.slice(0, 6).forEach(({ name, count }) => { + const listItem = document.createElement('li') + listItem.innerText = `${count} PR${count !== 1 ? 's' : 's'} – ${name}` + reviewerCountsNode.appendChild(listItem) + }) + + const label = countsParent.querySelector('.form-label') + label.innerText = 'Now reviewing' + const message = countsParent.querySelector('.form-field-content') + message.replaceChildren(reviewerCountsNode) + formBodyMain.appendChild(countsParent) + } else { + tryDisplay() + } + }, 300) + tryDisplay() + }) +} diff --git a/repo-search-sorter.js b/repo-search-sorter.js index 77a400f..3293869 100644 --- a/repo-search-sorter.js +++ b/repo-search-sorter.js @@ -33,77 +33,4 @@ const sortSearchResult = () => { } } -///////////////////////////// -// PR Reviewer Suggestions // -///////////////////////////// -if (location.toString().includes('/pull-requests?create')) { - const names = [ - "Tam Nguyen", - "David Daniel", - "Nikalas Culvey", - "Michael Mezzina", - "Sage Vaillancourt", - "John Cyr", - "Adam Weizman", - "Caleb Soper", - "Rockey Liles", - "Fernando Batista" - ] - - const urlPrefix = 'https://git.add123.com/rest/api/latest' - - fetch(`${urlPrefix}/projects/ADD/repos?limit=999`) - .then(resp => resp.json()) - .then(async ({values: allRepos}) => { - const prListUrls = allRepos.map(repo => `${urlPrefix}/projects/ADD/repos/${repo.slug}/pull-requests`) - const allPullRequests = (await Promise.all( - prListUrls.map(async prListUrl => await fetch(prListUrl).then(resp => resp.json()))) - ).flatMap(({values}) => values) - - const reviewerCounts = Object.fromEntries(names.map(name => [name, 0])) - allPullRequests.forEach(({reviewers}) => { - reviewers?.map(r => r.user.displayName) - .filter(displayName => !["Chris Gamache", "Tom Keels"].includes(displayName)) - .forEach(displayName => { - reviewerCounts[displayName] ??= 0 - reviewerCounts[displayName] += 1 - }) - }) - const sortedCounts = Object.entries(reviewerCounts) - .map(([name, count]) => ({ name, count })) - .toSorted((a, b) => a.count - b.count) - const tryDisplay = () => setTimeout(() => { - if (document.getElementById('reviewer-counts')) { - return - } - const formBodyMain = document.querySelector('.create-pull-request-form .form-body .form-body-main') - if (formBodyMain) { - const countsParent = formBodyMain.lastChild.cloneNode(true) - const reviewerCountsNode = document.createElement('ol') - reviewerCountsNode.id = 'reviewer-counts' - reviewerCountsNode.style.columns = '3' - reviewerCountsNode.style.listStyle = 'none' - reviewerCountsNode.style.paddingLeft = '2px' - reviewerCountsNode.style.marginTop = 'auto' - // reviewerCountsNode.style.lineHeight = '95%' - reviewerCountsNode.style.fontSize = '0.9em' - sortedCounts.slice(0, 6).forEach(({ name, count }) => { - const listItem = document.createElement('li') - listItem.innerText = `${count} PR${count !== 1 ? 's' : 's'} – ${name}` - reviewerCountsNode.appendChild(listItem) - }) - - const label = countsParent.querySelector('.form-label') - label.innerText = 'Now reviewing' - const message = countsParent.querySelector('.form-field-content') - message.replaceChildren(reviewerCountsNode) - formBodyMain.appendChild(countsParent) - } else { - tryDisplay() - } - }, 300) - tryDisplay() - }) -} - addFix(sortSearchResult) diff --git a/server/public/sages-bitbucket-addon-1.0.19.xpi b/server/public/sages-bitbucket-addon-1.0.19.xpi new file mode 100644 index 0000000..775b3bb Binary files /dev/null and b/server/public/sages-bitbucket-addon-1.0.19.xpi differ diff --git a/show-errored-prs.js b/show-errored-prs.js index 2830c3f..ca5e371 100644 --- a/show-errored-prs.js +++ b/show-errored-prs.js @@ -3,7 +3,6 @@ const bbUrlPrefix = 'https://git.add123.com/rest/api/latest' const pullRequestHasErrored = async pr => { const latestCommitId = pr?.fromRef?.latestCommit if (!latestCommitId) { - console.log('no latestCommitId on pr', pr) return false } const buildStats = await fetch(`https://git.add123.com/rest/build-status/latest/commits/stats/${latestCommitId}`).then(resp => resp.json()) @@ -20,7 +19,7 @@ const getAllRepos = async () => { return allRepos } -const withErroredPrs = async action => { +const getErroredPrs = async () => { const allPullRequests = (await getAllRepos() .then(async allRepos => { const prListUrls = allRepos.map(repo => `${bbUrlPrefix}/projects/ADD/repos/${repo.slug}/pull-requests`) @@ -31,7 +30,7 @@ const withErroredPrs = async action => { const erroredPullRequests = [] for (const pullRequest of allPullRequests) { if (await pullRequestHasErrored(pullRequest)) { - action(pullRequest) + erroredPullRequests.push(pullRequest) } } return erroredPullRequests @@ -55,6 +54,7 @@ const showErroredPrs = async () => { let errorList = document.getElementById('bb-addon-pr-error-list') if (!errorParent) { errorParent = mainPanel.getElementsByClassName('dashboard-pull-request-table')[0].cloneNode() + errorParent.id = 'bb-addon-pr-error-table' const header = document.createElement('h3') header.innerText = 'Pull requests with errors' @@ -68,9 +68,10 @@ const showErroredPrs = async () => { mainPanel.insertBefore(errorParent, getElementAfterErrorList(mainPanel)) } - Array.from(errorList.children).slice(1).forEach(child => errorList.removeChild(child)) - await withErroredPrs(pr => { + const erroredPrs = await getErroredPrs() + Array.from(errorList.children).forEach(child => errorList.removeChild(child)) + erroredPrs.forEach(pr => { const element = document.createElement('li') const link = document.createElement('a') link.href = pr.links.self[0].href @@ -83,5 +84,5 @@ const showErroredPrs = async () => { if (location.toString().includes('/dashboard')) { addFix(() => showErroredPrs().catch(console.error)) - setInterval(() => showErroredPrs().catch(console.error), 1000 * 60 * 5) + setInterval(() => showErroredPrs().catch(console.error), 1000 * 60 * 2) } \ No newline at end of file