我正在通过github操作进行一些自动化,并且希望在提交来自所有者的comment
时,在现有的pull请求上触发squash-and-merge
。
我的代码看起来像这样:
merge-release:
if: |
${{ github.repository == 'repo/to/avoid/execution/from/forks' }} &&
${{ (github.triggering_actor == 'xyz' }} &&
${{ github.event.client_payload.slash_command.command == "approve-merge" }}
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const { Octokit } = require("@octokit/rest");
const octokit = new Octokit({ auth: '${{ secrets.GITHUB_TOKEN }}' });
await octokit.request('PUT /repos/${{ github.action_repository }}/pulls/${{ github.event.number }}/merge', {
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: '${{ github.event.number }}',
commit_title: 'Example',
commit_message: 'Example.',
headers: { 'X-GitHub-Api-Version': '2022-11-28' }
})
根据这些资源,您应该能够做到:
- is it possible to squash commits via Github API?
- https://docs.github.com/en/rest/pulls/pulls?apiVersion=2022-11-28#merge-a-pull-request
但是我的代码失败了:
Error: Cannot find module '@octokit/rest'
Require stack:
- /home/runner/work/_actions/actions/github-script/v6/dist/index.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at resolve (node:internal/modules/cjs/helpers:108:19)
at Object.apply (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15188:43)
at eval (eval at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15143:16), <anonymous>:3:21)
at callAsyncFunction (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15144:12)
at main (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15236:26)
at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:15217:1
at /home/runner/work/_actions/actions/github-script/v6/dist/index.js:15268:3
at Object.<anonymous> (/home/runner/work/_actions/actions/github-script/v6/dist/index.js:15271:12)
at Module._compile (node:internal/modules/cjs/loader:1105:14) {
code: 'MODULE_NOT_FOUND',
requireStack: [
Error: Unhandled error: Error: Cannot find module '@octokit/rest'
Require stack:
- /home/runner/work/_actions/actions/github-script/v6/dist/index.js
'/home/runner/work/_actions/actions/github-script/v6/dist/index.js'
]
}
我错过了什么?还有别的办法吗?
1条答案
按热度按时间xqkwcwgp1#
看起来你需要用
npm i @octokit/rest
安装@octokit/rest。