I am using the npm GitHub API.
And I have four pieces of data.
- the ref to the file I want to update
- the path to the file I want to update
- the new contents I want to be in this file
- the commit message I want for this edit
Additionally, I can authenticate to the API, and have access to this repo.
How do I now edit this file and push this commit?
const GitHub = require('github-api')
const gh = new GitHub({
token: config.app.git_token,
}, githubUrl)
const repo = gh.getRepo(config.app.repoOwner, config.app.repoName)
repo.getRef(`heads/${config.app.repoBranch}`).then((response) => {
const ref = response.data.object.sha
const path = 'README.md'
const content = '#Foo Bar\nthis is foo bar'
const message = 'make readme foo bar'
console.log('ref to the file i want to update')
console.log(ref)
console.log('path to the file i want to update')
console.log(path)
console.log('contents i now want in this file')
console.log(content)
console.log('commit message message')
console.log(message)
// how do i now edit and add a commit to this remote file?
})
I've tried using .commit but, so far, have not gotten it to work, I don't understand how to generate the correct params to that function call.