Created
July 16, 2019 22:46
-
-
Save naosim/2144551711a66de2ac6563d1d9b4f097 to your computer and use it in GitHub Desktop.
【GAS】GithubApiライブラリ
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 GithubApi( | |
accessToken, | |
owner, | |
repo | |
) { | |
var requestOptions = { | |
headers: { Authorization: 'token ' + accessToken } | |
} | |
function exec(url) { | |
if(url.indexOf('http') != 0) { | |
url = 'https://api.github.com' + url; | |
} | |
url = url.split(':owner').join(owner).split(':repo').join(repo); | |
var content = UrlFetchApp.fetch(url, requestOptions).getContentText("UTF-8"); | |
Logger.log(JSON.stringify(JSON.parse(content), null, ' ')) | |
return JSON.parse(content); | |
} | |
function trees(treeSha) { | |
var url = '/repos/:owner/:repo/git/trees/:tree_sha'; | |
return exec(url.split(':tree_sha').join(treeSha)); | |
} | |
function getBlobContent(url) { | |
var c = exec(url)['content']; | |
return Utilities.newBlob(Utilities.base64Decode(c)).getDataAsString() | |
} | |
return { | |
exec: exec, | |
trees: trees, | |
getBlobContent: getBlobContent, | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment