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 create
method 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