我正在使用nodeJS (ProBot)为github构建一个代码审查应用程序。
我试图从为获取相关文件和运行测试而创建的check_suite中获取pull_request数据,但context.payload.pull_request是空的。
我还尝试了监听事件pull_request.created,那里有我需要的数据,但是context.github.checks.update() / context.github.checks.create()不会更新检查的状态,并且永远保持为in_progress。
下面是我的代码:
module.exports = app => {
app.on([
'check_suite.requested',
'check_run',
'pull_request.opened',
], check)
async function check (context) {
const startTime = new Date()
if (context.payload.check_suite) {
const { head_branch: headBranch, head_sha: headSha } = context.payload.check_suite
return context.github.checks.create(context.repo({
name: 'SoftaCheck',
head_branch: headBranch,
head_sha: headSha,
status: 'in_progress',
started_at: startTime,
}))
}
const payload = {head_branch: context.payload.pull_request? context.payload.pull_request.base.ref : context.payload.check_run.pull_requests[0].base.ref ,head_sha : context.payload.pull_request? context.payload.pull_request.base.sha : context.payload.check_run.pull_requests[0].base.sha }
const { head_branch, head_sha } = payload
if (context.payload.pull_request) {
//some async code here in order to decide conclusion...
context.github.checks.create(context.repo({
name: 'SoftaCheck',
head_branch,
head_sha,
status: 'completed',
conclusion:'success'
started_at: startTime,
}))
}}
//构建应用的更多信息: // https://probot.github.io/docs/
//要使您的应用程序在GitHub上运行,请参阅: // https://probot.github.io/docs/development/ }
发布于 2020-07-22 04:59:48
我不确定您是如何实现check.create方法的。相反,您应该传入repo名称。
需要注意的几件事:
您的GitHub应用程序必须具有check:write permission的
checks.create方法具有required properties(属性是必需的)。例如,在您的案例中缺少所有者属性。早些时候,我遇到了somewhat similar issue。
https://stackoverflow.com/questions/62947254
复制相似问题