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",
|
"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.17",
|
"version": "1.0.18",
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"browser_specific_settings": {
|
"browser_specific_settings": {
|
||||||
"gecko": {
|
"gecko": {
|
||||||
|
|
Binary file not shown.
|
@ -1,29 +1,51 @@
|
||||||
const bbUrlPrefix = 'https://git.add123.com/rest/api/latest'
|
const bbUrlPrefix = 'https://git.add123.com/rest/api/latest'
|
||||||
|
|
||||||
const pullRequestHasErrored = async pr => {
|
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())
|
const buildStats = await fetch(`https://git.add123.com/rest/build-status/latest/commits/stats/${latestCommitId}`).then(resp => resp.json())
|
||||||
return buildStats.failed !== 0
|
return buildStats.failed !== 0
|
||||||
}
|
}
|
||||||
|
|
||||||
const getErroredPrs = async () => {
|
const getAllRepos = async () => {
|
||||||
const allPullRequests = await fetch(`${bbUrlPrefix}/projects/ADD/repos?limit=999`)
|
const allProjects = (await fetch(`${bbUrlPrefix}/projects`).then(resp => resp.json())).values
|
||||||
.then(resp => resp.json())
|
const allProjectKeys = allProjects.map(project => project.key)
|
||||||
.then(async ({values: allRepos}) => {
|
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`)
|
const prListUrls = allRepos.map(repo => `${bbUrlPrefix}/projects/ADD/repos/${repo.slug}/pull-requests`)
|
||||||
return (await Promise.all(
|
return (await Promise.all(
|
||||||
prListUrls.map(async prListUrl => await fetch(prListUrl).then(resp => resp.json())))
|
prListUrls.map(async prListUrl => await fetch(prListUrl).then(resp => resp.json())))
|
||||||
).flatMap(({values}) => values)
|
).flatMap(({values}) => values)
|
||||||
}).catch(console.error)
|
}).catch(console.error)).filter(Boolean)
|
||||||
const erroredPullRequests = []
|
const erroredPullRequests = []
|
||||||
for (const pullRequest of allPullRequests) {
|
for (const pullRequest of allPullRequests) {
|
||||||
if (await pullRequestHasErrored(pullRequest)) {
|
if (await pullRequestHasErrored(pullRequest)) {
|
||||||
erroredPullRequests.push(pullRequest)
|
action(pullRequest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return erroredPullRequests
|
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 () => {
|
const showErroredPrs = async () => {
|
||||||
if (getCurrentUser() !== 'sagevaillancourt') {
|
if (getCurrentUser() !== 'sagevaillancourt') {
|
||||||
return
|
return
|
||||||
|
@ -44,12 +66,11 @@ const showErroredPrs = async () => {
|
||||||
errorList.style.fontSize = '0.9em'
|
errorList.style.fontSize = '0.9em'
|
||||||
errorParent.appendChild(errorList)
|
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))
|
Array.from(errorList.children).slice(1).forEach(child => errorList.removeChild(child))
|
||||||
|
|
||||||
const erroredPrs = await getErroredPrs()
|
await withErroredPrs(pr => {
|
||||||
erroredPrs.forEach(pr => {
|
|
||||||
const element = document.createElement('li')
|
const element = document.createElement('li')
|
||||||
const link = document.createElement('a')
|
const link = document.createElement('a')
|
||||||
link.href = pr.links.self[0].href
|
link.href = pr.links.self[0].href
|
||||||
|
|
Loading…
Reference in New Issue