Probot check-js pull request

541 Views Asked by At

I'm building a code-review app for github using nodeJS (ProBot)

I'm trying to get the pull_request data out of the check_suite that was created in order to get the relevant files and run my tests but the context.payload.pull_request is empty.

i tried also listening to the event pull_request.created, there I have the data that I need but the context.github.checks.update() / context.github.checks.create() does not update the status of the check and and stays in_progress forever.

here is my code :

module.exports = app => {
app.on([
'check_suite.requested',
'check_run',
'pull_request.opened', 
], check)
async function check (context) {
const startTime = new Date()

if (context.payload.check_suite) {
  const { head_branch: headBranch, head_sha: headSha } = context.payload.check_suite

   return context.github.checks.create(context.repo({
    name: 'SoftaCheck',
    head_branch: headBranch,
    head_sha: headSha,
    status: 'in_progress',
    started_at: startTime,
  }))
}

const payload =  {head_branch: context.payload.pull_request? context.payload.pull_request.base.ref : context.payload.check_run.pull_requests[0].base.ref ,head_sha : context.payload.pull_request? context.payload.pull_request.base.sha : context.payload.check_run.pull_requests[0].base.sha }

const { head_branch, head_sha } = payload

if (context.payload.pull_request) {
    
   //some async code here in order to decide conclusion...

   context.github.checks.create(context.repo({
     name: 'SoftaCheck',
     head_branch,
     head_sha,
     status: 'completed',
     conclusion:'success'
     started_at: startTime,
   }))

}

}

// For more information on building apps: // https://probot.github.io/docs/

// To get your app running against GitHub, see: // https://probot.github.io/docs/development/ }

1

There are 1 best solutions below

0
On

I am not sure how you are trying to implement check.create method. That method takes in several parameters(some mandatory, some optional), but you are passing in a repo object. You should be passing in the repo name instead.

Few things to note:

  • your GitHub App must have check:write permission

  • Also, make sure your checks.create method has the required properties(properties which are mandatory). For instance, owner property is missing in your case.

Earlier I had run into somewhat similar issue.