Created
March 14, 2016 21:06
-
-
Save reportbase/643c5542806cac8e383b to your computer and use it in GitHub Desktop.
readme promise
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 readme() | |
{ | |
var name = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); return v.toString(16);}) + ".md"; | |
var str = "" | |
var a = new Array() | |
for (var n = 0; n < catobj.data.length; ++n) | |
{ | |
var k = catobj.data[n] | |
if (k.number == -1) | |
{ | |
a = a.concat(k.symbols) | |
continue | |
} | |
var url = application_url(k.number) | |
str += "* [" + k.title + "](" + url + ") [**Edit**](https://github.com/" + | |
global.owner + "/" + global.repos + "/issues/" + k.number + ")\n" | |
} | |
var index = _.findIndex(contentobj.data, function(a) {return a.name == "README.md"}) | |
var http = new XMLHttpRequest() | |
var phttp = new Promise(function(resolve, reject) | |
{ | |
http.onreadystatechange = function() | |
{ | |
if (this.readyState != this.DONE) | |
return | |
if (this.status == 200) | |
resolve(this.status); | |
else | |
reject(this.status + " " + this.statusText); | |
} | |
}) | |
http.open('PUT', github_api_url("/contents/README.md"), true) | |
http.send(JSON.stringify({"message": "update", "content": btoa(str), "sha": contentobj.data[index].sha})) | |
var http2 = new XMLHttpRequest() | |
http2.onreadystatechange = function() | |
{ | |
if (this.readyState != this.DONE) | |
return | |
if (this.status != 201) | |
{ | |
nag(this.status + " " + this.statusText) | |
return | |
} | |
window.open(github_url("/blob/master/reports/" + name), "_self") | |
} | |
phttp.then(function() | |
{ | |
http2.open("PUT", github_api_url("/contents/reports/" + name)) | |
http2.send(JSON.stringify({"message": name, "content": btoa(str)})) | |
}). | |
catch(function(error) | |
{ | |
jug(loginobj, error.message) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment