我正在使用 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/ }