Add show-errored-prs.js (currently only enabled for the sagevaillancourt user)
1.0.17.xpi
This commit is contained in:
parent
f85f3534ca
commit
4081e176ce
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "Sage's BitBucket Addon",
|
||||
"description": "Ensure searches don't include forks (and other enhancements)",
|
||||
"version": "1.0.16",
|
||||
"version": "1.0.17",
|
||||
"manifest_version": 2,
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
|
@ -31,6 +31,7 @@
|
|||
"csharp-quotes.js",
|
||||
"file-scroll.js",
|
||||
"repo-search-sorter.js",
|
||||
"show-errored-prs.js",
|
||||
"var-highlighter.js"
|
||||
],
|
||||
"run_at": "document_start"
|
||||
|
|
Binary file not shown.
|
@ -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)
|
||||
}
|
Loading…
Reference in New Issue