Pull from ALL projects, and move the dashboard section.
Now sits between 'Your pull requests' and 'Recently closed pull requests' 1.0.18.xpi
This commit is contained in:
parent
4081e176ce
commit
945d819f0e
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "Sage's BitBucket Addon",
|
||||
"description": "Ensure searches don't include forks (and other enhancements)",
|
||||
"version": "1.0.17",
|
||||
"version": "1.0.18",
|
||||
"manifest_version": 2,
|
||||
"browser_specific_settings": {
|
||||
"gecko": {
|
||||
|
|
Binary file not shown.
|
@ -1,29 +1,51 @@
|
|||
const bbUrlPrefix = 'https://git.add123.com/rest/api/latest'
|
||||
|
||||
const pullRequestHasErrored = async pr => {
|
||||
const latestCommitId = pr.fromRef.latestCommit
|
||||
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())
|
||||
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 getAllRepos = async () => {
|
||||
const allProjects = (await fetch(`${bbUrlPrefix}/projects`).then(resp => resp.json())).values
|
||||
const allProjectKeys = allProjects.map(project => project.key)
|
||||
let allRepos = await Promise.all(allProjectKeys.map(async key =>
|
||||
await fetch(`${bbUrlPrefix}/projects/${key}/repos?limit=999`)
|
||||
.then(resp => resp.json()).then(({ values }) => values)))
|
||||
allRepos = allRepos.flatMap(a => a)
|
||||
return allRepos
|
||||
}
|
||||
|
||||
const withErroredPrs = async action => {
|
||||
const allPullRequests = (await getAllRepos()
|
||||
.then(async 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)
|
||||
}).catch(console.error)).filter(Boolean)
|
||||
const erroredPullRequests = []
|
||||
for (const pullRequest of allPullRequests) {
|
||||
if (await pullRequestHasErrored(pullRequest)) {
|
||||
erroredPullRequests.push(pullRequest)
|
||||
action(pullRequest)
|
||||
}
|
||||
}
|
||||
return erroredPullRequests
|
||||
}
|
||||
|
||||
const getElementAfterErrorList = mainPanel => {
|
||||
for (const child of mainPanel.children) {
|
||||
if (child.innerHTML.includes('Recently closed pull requests')) {
|
||||
return child
|
||||
}
|
||||
}
|
||||
return mainPanel.children[1]
|
||||
}
|
||||
|
||||
const showErroredPrs = async () => {
|
||||
if (getCurrentUser() !== 'sagevaillancourt') {
|
||||
return
|
||||
|
@ -44,12 +66,11 @@ const showErroredPrs = async () => {
|
|||
errorList.style.fontSize = '0.9em'
|
||||
errorParent.appendChild(errorList)
|
||||
|
||||
mainPanel.insertBefore(errorParent, mainPanel.children[1])
|
||||
mainPanel.insertBefore(errorParent, getElementAfterErrorList(mainPanel))
|
||||
}
|
||||
Array.from(errorList.children).slice(1).forEach(child => errorList.removeChild(child))
|
||||
|
||||
const erroredPrs = await getErroredPrs()
|
||||
erroredPrs.forEach(pr => {
|
||||
await withErroredPrs(pr => {
|
||||
const element = document.createElement('li')
|
||||
const link = document.createElement('a')
|
||||
link.href = pr.links.self[0].href
|
||||
|
|
Loading…
Reference in New Issue