Created
August 22, 2019 13:17
-
-
Save PiotrJander/bc31e7689a067631960ea58cb7e15667 to your computer and use it in GitHub Desktop.
List Zenhub issues which were moved due to deleting pipelines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
</head> | |
<body> | |
<p>This script has to be run with CORS disabled. | |
<a href="https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome#comment75090678_6083677"> | |
Instructions for Chrome on MacOS. | |
</a> | |
</p> | |
<ul id="list"></ul> | |
<script> | |
const token = "{{your_token}}"; | |
const affected = ["Icebox", "Up Next", "New Issues"]; | |
async function queryZenhub(url) { | |
const response = await fetch(url, { | |
"credentials": "omit", | |
"headers": { | |
"accept": "application/json, text/javascript, */*; q=0.01", | |
"x-authentication-token": token, | |
"x-zenhub-agent": "webapp/2.38.120" | |
} | |
}); | |
return await response.json(); | |
} | |
async function getRepos() { | |
const json = await queryZenhub("https://api.zenhub.io/v4/workspaces/5b57093c92e09f0d21193695"); | |
return json.repos.map(({ repo_id, repository }) => ({ repo_id, repository })); | |
} | |
// E.G. getIssuesInRepo(198830384) | |
async function getIssuesInRepo(repo) { | |
const json = await queryZenhub(`https://api.zenhub.io/v5/repositories/${repo}/issues?workspaceId=5b57093c92e09f0d21193695`); | |
return json.map(i => i.issue_number); | |
} | |
async function getIssueTransferEvents(repo, issue) { | |
const json = await queryZenhub(`https://api.zenhub.io/v5/repositories/${repo}/issues/${issue}/events`); | |
const events = json.events.filter(e => e.type === "transferIssue"); | |
return events.sort((e1, e2) => compare(e1.createdAt, e2.createdAt)); | |
} | |
function compare(e1, e2) { | |
return e1 < e2 ? -1 : (e1 > e2 ? 1 : 0) | |
} | |
// E.G. getIfMoved(198830384, 48) | |
async function getIfMoved(repo, issue) { | |
const transfers = await getIssueTransferEvents(repo, issue); | |
const lastTranfer = transfers.length > 0 && transfers[transfers.length - 1] | |
return lastTranfer && affected.includes(lastTranfer.destPipelineName) && issue; | |
} | |
// E.G. getAffectedIssuesInRepo(198830384) | |
async function getAffectedIssuesInRepo(repo) { | |
const issues = await getIssuesInRepo(repo); | |
const affected = await Promise.all(issues.map(issue => getIfMoved(repo, issue))); | |
return affected.filter(i => i); | |
} | |
async function getAffectedIssues() { | |
const repos = await getRepos(); | |
return await Promise.all(repos.map(async ({ repo_id, repository }) => { | |
const affectedIssues = await getAffectedIssuesInRepo(repo_id); | |
return { repository, affectedIssues } | |
})); | |
} | |
const list = document.getElementById("list"); | |
function writeAffectedIssues({ repository, affectedIssues }) { | |
const li = document.createElement("li"); | |
li.appendChild(document.createElement("b").appendChild(document.createTextNode(repository + ":"))); | |
for (let i of affectedIssues) { | |
li.appendChild(document.createTextNode(" ")); | |
const a = document.createElement("a"); | |
a.appendChild(document.createTextNode(i)); | |
a.setAttribute("href", `https://app.zenhub.com/workspaces/enso-5b57093c92e09f0d21193695/issues/luna/${repository}/${i}`); | |
li.appendChild(a); | |
} | |
list.appendChild(li); | |
} | |
async function main() { | |
const results = await getAffectedIssues(); | |
results.forEach(r => writeAffectedIssues(r)); | |
} | |
main(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment