Created
June 18, 2013 04:14
-
-
Save soundTricker/5802640 to your computer and use it in GitHub Desktop.
gas-github library sample code. Please see https://github.com/soundTricker/gas-github
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
/** | |
* gas-github library sample codes. | |
* see https://github.com/soundTricker/gas-github | |
*/ | |
//Create new gist | |
function createOrUpdateGist(){ | |
//Create Gist API | |
var gistApi = Github.create(UserProperties.getProperty("githubApiKey")).gists(); | |
//Get latest gist id | |
var gistId = ScriptProperties.getProperty("sampleGistId"); | |
if(gistId) { | |
//If exist latest gist, update code. | |
gistApi.update(gistId, "gas-github library sample code. Please see https://github.com/soundTricker/gas-github" , true , { | |
"sample.js" : { | |
"content" : ScriptApp.getResource("sample").getDataAsString() | |
} | |
}); | |
} else { | |
//If none, create new gist. | |
var newGist = gistApi.create("gas-github library sample code. Please see https://github.com/soundTricker/gas-github" , true , { | |
"sample.js" : { | |
"content" : ScriptApp.getResource("sample").getDataAsString() | |
} | |
}); | |
//Save gist id | |
ScriptProperties.setProperty("sampleGistId", newGist.id); | |
} | |
} | |
//Create and Update | |
function publishToGistAndUpdate() { | |
var gistApi = Github.create(UserProperties.getProperty("githubApiKey")).gists(); | |
//create new gist | |
var newGist = gistApi.create("publish test from gas" , true , { | |
"sample.js" : { | |
"content" : ScriptApp.getResource("sample").getDataAsString() | |
}}); | |
//add new file | |
var updatedGist = newGist.update("add file" , true , { | |
"gistsSpec.js" : { | |
"content" : ScriptApp.getResource("gistsSpec").getDataAsString() | |
} | |
}); | |
//delete file | |
updatedGist.update("deleted files" , true , { | |
"sample.js" : { | |
filename: null | |
} | |
}); | |
//update file content | |
updatedGist.update("update files" , true , { | |
"gistsSpec.js" : { | |
content : "//updated\n" + ScriptApp.getResource("gistsSpec").getDataAsString() | |
} | |
}); | |
//delete gist | |
updatedGist.del(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment