Create Github Issues
Create Github Issues
by Lissandro Dittmar
HTML
<div id="banner-message">
<p>Create issues</p>
<button>Start creation</button>
</div>
<div style="background-color: white;">
<ol id="liste">
</ol>
<br/>
<ol id="listeSuccess">
</ol>
</div>
CSS
i {
color: #669FAB;
}
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#banner-message {
background: #fff;
border-radius: 4px;
padding: 20px;
font-size: 25px;
text-align: center;
transition: all 0.2s;
margin: 0 auto;
width: 300px;
}
button {
background: #0084ff;
border: none;
border-radius: 5px;
padding: 8px 14px;
font-size: 15px;
color: #fff;
}
#banner-message.alt {
background: #0084ff;
color: #fff;
margin-top: 40px;
width: 200px;
}
#banner-message.alt button {
background: #fff;
color: #000;
}
JavaScript
const githubToken = ""; //https://github.com/settings/tokens
const test = true;
const issueTitle = "Titel";
const issueBody = "Bla, Bla";
const adapterList = ["ioBroker/ioBroker.js-controller"];
const start = function(){
for (i = 0; i < 7; i++) {
$.getJSON("https://api.github.com/search/repositories?q=iobroker&sort=updated&page=" + i + "&per_page=100", function (data) {
let counter = 0;
$.each(data.items, function (key, val) {
const full_name = val.full_name;
const link = "https://raw.githubusercontent.com/" + full_name + "/master/io-package.json";
$.getJSON(link, function (res) {
if ($.inArray(full_name, adapterList) == -1 && res && res.common
&& !res.common.onlyWWW
&& !res.common.compact) {
adapterList.push(full_name);
if (test) {
testIssueCreation(full_name);
} else {
counter++;
if(counter == 3){
counter = 0;
wait(5000);
}
createIssue(full_name);
}
}
});
});
});
}
}
$("button").on("click", function(){
start();
});
function GithubInteractor(token) {
this.token = token;
}
const interactor = new GithubInteractor(githubToken);
function createIssue(repo) {
var url = "https://api.github.com/repos/" + repo + "/issues";
$.ajax({
url: url,
type: "POST",
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "token " + interactor.token);
},
error: function(xhr, status, error) {
var err = JSON.parse(xhr.responseText);
$('#liste').append("<li style='color: red;'>" + repo + " - issue failed (" + status...