Open Pomax opened 6 years ago
One way you can do this to get the last commit of the specific file and then use that sha
var octo = new Octokat({
username: 'username',
password: 'password'
});
var repo = octo.repos('username', 'repoName');
repo.contents('somefile.txt').fetch(function(err, info) {
if (err) {
console.log(err);
} else {
console.log('somefile.txt's SHA number is: ' + info.sha);
}
});
Example Using promise =>
var Octokat = require('octokat');
var base64 = require('base-64');
var octo = new Octokat({token: 'your token'})
var repo = octo.repos('username', 'reponame');
repo.contents('somefile.txt').fetch().then((info) =>{
var config = {
message: 'Updating somefile.txt',
content: base64.encode('new content'),
sha:info.sha
}
repo.contents('somefile.txt').add(config)
.then((info) => {
console.log('File Updated. new sha is ', info);
})}).catch(function(err){console.log("err"+err)});
Could you turn that into a PR against the README.md?
Right now under the read/write/update section of the readme, there is the following text:
but the code that follows does not show how to get that SHA at all, it just shows a meaningless dummy sha. Can that example be updated to show how to actually get the previous commit sha? (Do we use fetch? do we call something on commits? I can't tell =S)
(Also, the section is titled read/write/update but the examples shown only show off reading and updating. Plain writing does not appear as one of the examples)