Last active
August 29, 2015 13:55
-
-
Save lucaswerkmeister/8695919 to your computer and use it in GitHub Desktop.
JS script to create Ceylon OBR "multiplexer" issues
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
var repoNames = [ | |
"ceylon/ceylon-spec", | |
"ceylon/ceylon-compiler", | |
"ceylon/ceylon-js", | |
"ceylon/ceylon-dist", | |
"ceylon/ceylon.language", | |
"ceylon/ceylon-runtime", | |
"ceylon/ceylon-common", | |
"ceylon/ceylon-module-resolver" | |
]; | |
var obr = "ceylon/ceylon"; | |
var accessToken = ENTER TOKEN HERE; // you can obtain a token in your Github settings page, under "Applications" | |
var repos = {}; | |
for (name of repoNames) | |
repos[name] = NaN; | |
var maxIssues = -1; | |
for (repo in repos) { | |
var req1 = new XMLHttpRequest(); | |
req1.open("GET", "https://api.github.com/repos/" + repo + "/issues?state=open", false); | |
req1.send(null); | |
if (req1.status !== 200) | |
throw req1; | |
var response1 = JSON.parse(req1.responseText); | |
var nOpen = response1[0].number; | |
var req2 = new XMLHttpRequest(); | |
req2.open("GET", "https://api.github.com/repos/" + repo + "/issues?state=closed", false); | |
req2.send(null); | |
if (req2.status !== 200) | |
throw req2; | |
var response2 = JSON.parse(req2.responseText); | |
var nClosed = response2[0].number; | |
var nIssues = Math.max(nOpen, nClosed); | |
repos[repo] = nIssues; | |
maxIssues = Math.max(maxIssues, nIssues); | |
} | |
for (var i = 1; i <= maxIssues; i++) { | |
var title = ""; | |
var markdown = "Issue " + i + " may refer to the following issues:\n\n" | |
for (repo in repos) { | |
if (i <= repos[repo]) { | |
markdown += "* " + repo + "#" + i + "\n"; | |
if (title != "") { | |
title += ", "; | |
} | |
title += repo.split('/')[1]; | |
} | |
} | |
var reqCreate = new XMLHttpRequest(); | |
reqCreate.open("POST", "https://api.github.com/repos/" + obr + "/issues?access_token=" + accessToken, false); | |
reqCreate.send(JSON.stringify( | |
{ | |
"title": title, | |
"body": markdown | |
})); | |
if (reqCreate.status == 201) { | |
var issue = JSON.parse(reqCreate.responseText); | |
if (issue.number != i) { | |
console.log("Issue numbers mismatch! Expected: " + i, ", created: " + issue.number); | |
throw issue; | |
} | |
var reqClose = new XMLHttpRequest(); | |
reqClose.open("PATCH", "https://api.github.com/repos/" + obr + "/issues/" + issue.number + "?access_token=" + accessToken, false); | |
reqClose.send(JSON.stringify( | |
{ | |
"title": issue.title, | |
"state": "closed" | |
})); | |
if (reqClose.status != 200) { | |
console.log("Couldn’t close issue #" + issue.number); | |
} | |
} else { | |
console.log("Request unsuccessful"); | |
throw reqCreate; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment