1

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

Asif Kamran Malick
  • 2,409
  • 3
  • 25
  • 47

1 Answers1

1

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 :)

OscarDOM
  • 716
  • 5
  • 15
  • Of course.I'll have to make it possible. :) If its says the params are reqd, then there's no escaping. I feel so dumb to have missed it. But I did provide the checks write permission. I will pass those reqd parameters and share my findings with you. Thank you so much @OscarDOM – Asif Kamran Malick May 16 '20 at 11:45
  • @AsifKamranMalick edited response with a possible missing change you need to apply :) – OscarDOM May 17 '20 at 17:06
  • Ok. I think I did exactly same.But that never worked for me. I will edit my OP and under section EDIT 1 I'll provide the changes I made to my code after your first suggestion. I think the only difference is the way of specifying the mediaType. Will try with that too.But please do check the EDIT and let me know if that's fine – Asif Kamran Malick May 17 '20 at 18:35
  • 1
    The rest looks good but without the mediaType fix, you want be able to communicate to the API. Let us know how it looks after your try – OscarDOM May 18 '20 at 19:09
  • 1
    This worked. Thanks a ton. :) I can find them in the checks tab. There was one extra thing I had to take care of, i.e.owner.login instead of just owner. – Asif Kamran Malick May 19 '20 at 08:30