1

我正在尝试在我的 GitHub 应用程序中实施 Checks。我的应用程序是用 probot 构建的。

我只是无法实施检查。我尝试过查看演示 ruby​​ 示例的文档,其中包括几个不同的设置(不确定 probot 是否需要)。我只是对那里的例子感到困惑。

下面是驻留在我的 index.js 中的代码:

app.on('check_suite.requested', async context =>{
      console.log('************------------ check suite requested')
      await context.github.checks.create({
        mediaType:'application/vnd.github.antiope-preview+json',
        name : 'test-check-1',
        head_sha: context.payload.check_suite.after,
        conclusion: "success"
      })
  })

我得到以下错误

 ERROR probot: Cannot read property 'map' of undefined
  TypeError: Cannot read property 'map' of undefined

错误日志抱怨 index.js:24:35,这正是该create行中的方法await context.github.checks.create

上面的代码是否足以创建检查test-check-1还是我还需要处理其他事情。我已经在我的仓库的分支保护设置下启用了“在合并之前通过所需的状态检查”选项。该部分显示对不起,我们在上周找不到此存储库的任何状态检查。

不知道如何连接一切。

编辑 1:开始

以下是包含@OscarDOM 建议的所需参数后的代码:-

app.on('check_suite.requested', async context =>{
      console.log('*****check suite requested*****')
      context.github.checks.create({
        owner:context.payload.repository.owner,
        repo:context.payload.repository.name,
        mediaType:'application/vnd.github.antiope-preview+json',
        name : 'test-check-1',
        head_sha: context.payload.check_suite.after,
        conclusion: "success"
      })
  })

不幸的是,我仍然在完全相同的行和列上遇到相同的错误。

编辑 1:结束

编辑 2:开始

以下是修正 mediaType 参数后的最终工作代码:

请注意,我还必须纠正一个错误,那就是价值所有者参数。正确的方法是指定 context.payload.repository.owner.login ,这是我最近从StackOverflow 帖子中学到的

app.on('check_suite.requested', async context =>{
      console.log('*****check suite requested*****')
      context.github.checks.create({
        owner:context.payload.repository.owner.login,
        repo:context.payload.repository.name,
        mediaType: { previews: ['antiope']},
        name : 'test-check-1',
        head_sha: context.payload.check_suite.after,
        conclusion: "success"
      })
  })

编辑 2:结束

4

1 回答 1

1

您是否可能需要将所有者和存储库传递给context.github.checks.create()方法?我认为它们是必需的属性:https ://octokit.github.io/rest.js/v17#checks

另外,请确保 Github App 具有以下权限checks:write:( https://developer.github.com/v3/activity/events/types/#checkrunevent )


此外,检查您的代码片段,似乎您没有mediaType正确使用。如果检查类型定义,mediaType 具有以下结构:

mediaTypes: {
   format?: string,
   previews?: string[]
}

参考这里:https ://octokit.github.io/rest.js/v17#previews

你能用这个试试吗?

app.on('check_suite.requested', async context =>{
        console.log('************------------ check suite requested')
        await context.github.checks.create({
            owner: '<YOUR_ORGANIZATION>',
            repo: '<YOUR_REPO>',
            mediaType: { previews: ['antiope']},
            name : 'test-check-1',
            head_sha: context.payload.check_suite.after,
            conclusion: "success"
        })
    })

作为一般反馈,我建议您尝试使用 TypeScript,使用它会发现这些问题 :)

于 2020-05-16T00:08:18.907 回答