我正在使用npm GitHub API。
我有四个数据。
此外,我可以对API进行身份验证,并且可以访问此存储库。
我现在如何编辑此文件并推送此提交?
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?
})
我尝试过使用.commit但到目前为止还没有使用它,我不明白如何为该函数调用生成正确的参数。
答案 0 :(得分:0)
知道了!
以下是如何执行此操作的语法:
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)
const branch = config.app.repoBranch
const path = 'README.md'
const content = '#Foo Bar\nthis is foo bar'
const message = 'add foo bar to the readme'
const options = {}
repo.writeFile(
branch,
path,
content,
message,
options
).then((r) => {
console.log(r)
})
我需要使用.writeFile方法!