Add show-errored-prs.js (currently only enabled for the sagevaillancourt user)

1.0.17.xpi
This commit is contained in:
Sage Vaillancourt 2024-12-19 13:55:49 -05:00
parent f85f3534ca
commit 4081e176ce
3 changed files with 68 additions and 1 deletions

View File

@ -1,7 +1,7 @@
{ {
"name": "Sage's BitBucket Addon", "name": "Sage's BitBucket Addon",
"description": "Ensure searches don't include forks (and other enhancements)", "description": "Ensure searches don't include forks (and other enhancements)",
"version": "1.0.16", "version": "1.0.17",
"manifest_version": 2, "manifest_version": 2,
"browser_specific_settings": { "browser_specific_settings": {
"gecko": { "gecko": {
@ -31,6 +31,7 @@
"csharp-quotes.js", "csharp-quotes.js",
"file-scroll.js", "file-scroll.js",
"repo-search-sorter.js", "repo-search-sorter.js",
"show-errored-prs.js",
"var-highlighter.js" "var-highlighter.js"
], ],
"run_at": "document_start" "run_at": "document_start"

Binary file not shown.

66
show-errored-prs.js Normal file
View File

@ -0,0 +1,66 @@
const bbUrlPrefix = 'https://git.add123.com/rest/api/latest'
const pullRequestHasErrored = async pr => {
const latestCommitId = pr.fromRef.latestCommit
const buildStats = await fetch(`https://git.add123.com/rest/build-status/latest/commits/stats/${latestCommitId}`).then(resp => resp.json())
return buildStats.failed !== 0
}
const getErroredPrs = async () => {
const allPullRequests = await fetch(`${bbUrlPrefix}/projects/ADD/repos?limit=999`)
.then(resp => resp.json())
.then(async ({values: allRepos}) => {
const prListUrls = allRepos.map(repo => `${bbUrlPrefix}/projects/ADD/repos/${repo.slug}/pull-requests`)
return (await Promise.all(
prListUrls.map(async prListUrl => await fetch(prListUrl).then(resp => resp.json())))
).flatMap(({values}) => values)
}).catch(console.error)
const erroredPullRequests = []
for (const pullRequest of allPullRequests) {
if (await pullRequestHasErrored(pullRequest)) {
erroredPullRequests.push(pullRequest)
}
}
return erroredPullRequests
}
const showErroredPrs = async () => {
if (getCurrentUser() !== 'sagevaillancourt') {
return
}
const mainPanel = document.getElementsByClassName('main-panel')[0]
let errorParent = document.getElementById('bb-addon-pr-error-table')
let errorList = document.getElementById('bb-addon-pr-error-list')
if (!errorParent) {
errorParent = mainPanel.getElementsByClassName('dashboard-pull-request-table')[0].cloneNode()
const header = document.createElement('h3')
header.innerText = 'Pull requests with errors'
errorParent.appendChild(header)
errorList = document.createElement('ul')
errorList.id = 'bb-addon-pr-error-list'
errorList.style.listStyle = 'none'
errorList.style.fontSize = '0.9em'
errorParent.appendChild(errorList)
mainPanel.insertBefore(errorParent, mainPanel.children[1])
}
Array.from(errorList.children).slice(1).forEach(child => errorList.removeChild(child))
const erroredPrs = await getErroredPrs()
erroredPrs.forEach(pr => {
const element = document.createElement('li')
const link = document.createElement('a')
link.href = pr.links.self[0].href
link.innerText = pr.title
link.style.color = 'black'
element.appendChild(link)
errorList.appendChild(element)
})
}
if (location.toString().includes('/dashboard')) {
addFix(() => showErroredPrs().catch(console.error))
setInterval(() => showErroredPrs().catch(console.error), 1000 * 60 * 5)
}