问题
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.
回答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',
}))
来源:https://stackoverflow.com/questions/61202144/error-event-not-found-when-triggering-event-from-another-event-probot-app-bu