0

I am building a GitHub app in probot and nodejs and trying to update the PR whenever a pull_request.synchronize event occurs. I know that doesn't make much sense, but the point is I want to be able to update the PR upon the occurrence of a certain event.

app.on('pull_request.synchronize', async context => {
    console.log('---------------------- on pull_request.synchronize, body of PR : ', context.payload.pull_request)
    console.log('State of PR after pull_request.synchronize event :---------------', context.payload.pull_request.state)
    await context.github.pulls.update({
      owner:context.payload.repository.owner,
      repo :context.payload.repository.name,
      pull_number :context.payload.pull_request.number,
      title:'updated Pull Request Title: Success',
      body:'updated Pull Request Body: Success',
    })

  })

I get below error every time :

    ERROR event: Not Found (id=ssjsk-dd-sdfsdfs-fsfs-fsfsfsffsd)
  HttpError: Not Found
      at response.text.then.message (C:\GitWorkspace\user\GitHubApps\github-app-name\node_modules\@octokit\request\dist-node\index.js:66:23)
      at process._tickCallback (internal/process/next_tick.js:68:7)
  --
  event: {
    "event": "pull_request.synchronize",
    "id": "2332-3131-131-31231313-1313232144142",
    "installation": 3352243,
    "repository": "user/Demo-Repo"
  }
06:24:58.460Z ERROR probot: Not Found
  HttpError: Not Found
      at response.text.then.message (C:\GitWorkspace\user\GitHubApps\github-app-name\node_modules\@octokit\request\dist-node\index.js:66:23)
      at process._tickCallback (internal/process/next_tick.js:68:7)
06:24:58.472Z  INFO http: POST / 500 - 519.93 ms (id=3424234-43242-42423478a-4242-42342342)
06:24:58.476Z ERROR probot: Internal Server Error
  Error: Internal Server Error
      at Request.callback (C:\GitWorkspace\user\GitHubApps\github-app-name\node_modules\superagent\lib\node\index.js:706:15)
      at IncomingMessage.parser (C:\GitWorkspace\user\GitHubApps\github-app-name\node_modules\superagent\lib\node\index.js:916:18)
      at IncomingMessage.emit (events.js:203:15)
      at IncomingMessage.EventEmitter.emit (domain.js:448:20)
      at endReadableNT (_stream_readable.js:1129:12)
      at process._tickCallback (internal/process/next_tick.js:63:19)

Why is it unable to get the detail out of context, when in fact the context does get printed out by my console statement and contains the pull_request details.

I am just a beginner in both probot and nodejs so I am not sure if this has anything to to do with the syntax.

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

1 Answers1

1

The problem is that context.payload.repository.owner is an object, compare the example payload at https://developer.github.com/v3/activity/events/types/#webhook-payload-example-28

Try to replace it with context.payload.repository.owner.login.

Probot also provides a convenience method which returns and { owner, repo } object based on the context, and you can pass extra parameters to it

Try the following

await context.github.pulls.update(context.repo({
  pull_number: context.payload.pull_request.number,
  title:'updated Pull Request Title: Success',
  body:'updated Pull Request Body: Success',
}))
Gregor
  • 2,325
  • 17
  • 27
  • Just tried it and it runs fine. But the error doesn't seem to hint at that. I'm just not able to relate this to the error message. Did I miss anything here? Also, I tried printing out the context just to see what the context.payload.repository.owner.login contains and what I noticed is that the owner doesn't show any value, just the [Object]. I scrolled a bit and found context.payload.sender.login . Now, as per the docs I have been correct in using context.payload.repository.owner.login, but still unable to understand why it doesn't display any data other than the data type(here Object[]). – Asif Kamran Malick Apr 14 '20 at 20:26
  • I checked the payload under smee.io channel, it displays the detailed payload. was able to see the context.payload.repository.owner.login under payload of check_suite webhook – Asif Kamran Malick Apr 14 '20 at 20:44
  • NOTE : I have noticed that if another user(who is not owner or collaborator) submits Pull Request(with invalid pr body) to this repo, then the bot(my GitHub App) closes this PR. The closing message reads :"Closed with unmerged commits". The user is not able to see any reopen pull request button. All he/she is able to see is a Comment button. Whereas, the owner of the repo is well able to see both "Reopen pull request" and "Comment" buttons. Below is the code I am using in my index.js of the GitHub App: – Asif Kamran Malick Apr 15 '20 at 07:31