无法在我的集成中实施检查,获取 'map undefined' 以创建检查方法

Unable to implement check in my integration, getting 'map undefined' for create method of checks

我正在尝试在我的 GitHub 应用程序中实施检查。我的应用程序是用 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,正是await context.github.checks.create

行中的create方法

上面的代码足以创建检查 test-check-1 还是我还需要处理其他事情。我已经在我的仓库的分支保护设置下启用了 "Required status checks to pass before merging" 选项。 该部分显示 抱歉,我们在上周找不到此存储库的任何状态检查。

不确定如何连接所有内容。

编辑 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 参数的更正后的最终工作代码:

请注意,我还必须更正一个错误,那就是 value owner 参数。正确的方法是指定 context.payload.repository.owner.login,这是我最近从

中学到的东西
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:结束

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

此外,请确保 Github 应用程序具有以下权限: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,使用它会发现这些问题:)