githubgithub-apiprobotgithub-app

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


I am trying to implement Checks into my GitHub app. My App is built with probot.

I am just not able to implement the checks. I have tried going through the documentation which demonstrate ruby example that includes several different setups(not sure if required with probot). I just got confused with the example there.

Below is the code that resides in my 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"
      })
  })

I get below error

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

The error log complains about index.js:24:35, which is precisely the createmethod in the line await context.github.checks.create

Is the above code sufficient to create the check test-check-1 or do I need to take care of other things too. I already have the "Required status checks to pass before merging" option enabled under the branch protection settings of my repo. And that section displays Sorry, we couldn’t find any status checks in the last week for this repository.

Not sure how to connect everything.

EDIT 1 : START

Below is the code after including the required params as suggested by @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"
      })
  })

Unfortunately, I still get the same error at exact same line and column.

EDIT 1 : END

EDIT 2 : START

Below is the final working code after including corrections for the mediaType parameter :

Please note there was one more mistake I had to correct and that is the value owner param. The correct way is to specify context.payload.repository.owner.login and this was something I had recently learnt from this StackOverflow post

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"
      })
  })

EDIT 2 : END


Solution

  • Would it be possible you need to pass the owner and the repository to context.github.checks.create() method? I think they are required properties: https://octokit.github.io/rest.js/v17#checks

    Also, make sure the Github App has the following permissions: checks:write(https://developer.github.com/v3/activity/events/types/#checkrunevent)


    Also, checking your code snippet, seems that you are not using the mediaType properly. If you check the type definition, mediaType has the following structure:

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

    Reference here: https://octokit.github.io/rest.js/v17#previews

    Can you try it with this?

    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"
            })
        })
    

    As a general feedback, I suggest you to try TypeScript, these issues would have been spotted using it :)