0

我正在 probot 和 nodejs 中构建一个 GitHub 应用程序,并尝试在pull_request.synchronize事件发生时更新 PR。我知道这没有多大意义,但关键是我希望能够在某个事件发生时更新 PR。

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',
    })

  })

我每次都得到以下错误:

    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)

为什么它无法从上下文中获取详细信息,而实际上上下文确实由我的控制台语句打印出来并包含 pull_request 详细信息。

我只是 probot 和 nodejs 的初学者,所以我不确定这是否与语法有关。

4

1 回答 1

1

问题是这context.payload.repository.owner是一个对象,比较https://developer.github.com/v3/activity/events/types/#webhook-payload-example-28上的示例有效负载

尝试将其替换为context.payload.repository.owner.login.

Probot 还提供了一个方便的方法,它{ owner, repo }根据上下文返回和对象,您可以向它传递额外的参数

尝试以下

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',
}))
于 2020-04-14T19:16:52.310 回答