Created
September 17, 2019 04:52
-
-
Save mrdotkg/835d1051dc2828da753cdcb8f2ce202d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function httpRequest(url, callback) { | |
var req = new XMLHttpRequest(); | |
req.open("GET", url); | |
req.addEventListener("readystatechange", function() { | |
if (req.readyState === 4 && req.status === 200) { | |
callback.call(null, req.responseText); | |
} | |
}); | |
req.send(); | |
} | |
function listRepo() { | |
var githubUserName = document.getElementById("github_user_name").value; | |
var githubApiRequestUrl = | |
"https://api.github.com/users/" + githubUserName + "/repos"; | |
var getRepoList = function(githubUrl, formatter) { | |
httpRequest(githubUrl, response => | |
formatter.call(null, JSON.parse(response)) | |
); | |
}; | |
getRepoList(githubApiRequestUrl, repos => { | |
// --------------------- Provide repo list for selection | |
var repoSelect = document.createElement("select"); | |
var addButton = document.createElement("button"); | |
repoSelect.id = "repo_select"; | |
addButton.id = "add_repo"; | |
addButton.innerHTML = "add"; | |
repos.forEach(repo => { | |
// ------------------- Only active and owned repos | |
if (!repo.archived && !repo.fork) { | |
var opt = document.createElement("option"); | |
opt.value = repo.name; | |
opt.innerHTML = repo.name; | |
repoSelect.appendChild(opt); | |
} | |
}); | |
document.getElementById("repo_select_span").innerHTML = ""; | |
document.getElementById("repo_select_span").append(repoSelect); | |
document.getElementById("repo_select_span").append(addButton); | |
// ---------------------- Install ghost setup for selected repo | |
document.getElementById("add_repo").addEventListener("click", () => { | |
var e = document.getElementById("repo_select"); | |
var repoName = e.options[e.selectedIndex].text; | |
exec( | |
`sh actions/install.sh ${githubUserName} ${repoName}`, | |
(error, stdout, stderr) => { | |
// ------------------ Append output / errors to log paragraph | |
document.getElementById("log").innerHTML = stdout + stderr; | |
var openSite = document.createElement("button"); | |
openSite.id = "open_site"; | |
openSite.innerHTML = "open site"; | |
document.getElementById("repo_select_span").append(openSite); | |
document.getElementById("open_site").addEventListener("click", () => { | |
ipcRenderer.send("newWindow", "http://localhost:2368/ghost/#/site"); | |
}); | |
if (error !== null) { | |
console.log(`exec error: ${error}`); | |
} | |
} | |
); | |
}); | |
}); | |
} | |
document.getElementById("github_user_name").addEventListener("blur", listRepo); |
This file contains hidden or 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
<input id="github_user_name" type="text" placeholder="github user name" /> | |
<span id="repo_select_span"></span> | |
<p id="log"></p> | |
<script src="github-repolist.js"></script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment