无法在我的集成中实施检查,创建检查方法时出现“映射未定义”

2023-12-12

我正在尝试在我的 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,这正是create行中的方法await context.github.checks.create

上面的代码足以创建检查吗测试检查-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:结束


您是否需要将所有者和存储库传递给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,使用它会发现这些问题:)

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法在我的集成中实施检查,创建检查方法时出现“映射未定义” 的相关文章

随机推荐