自动将 Dependabot 生成的 Pull 请求与代码所有者文件和分支保护规则合并?

pix*_*xel 5 github github-actions dependabot github-codeowners

我已经为 GitHub Actions 创建了工作流程,如下所述:https: //docs.github.com/en/code-security/supply-chain-security/keeping-your-dependency-updated-automatically/automating-dependabot-with-github - 行动

    name: Dependabot auto-approve
    on: pull_request_target
    
    permissions:
      contents: write
      pull-requests: write
    
    jobs:
      dependabot:
        runs-on: ubuntu-latest
        if: ${{ github.actor == 'dependabot[bot]' }}
        steps:

          - name: Approve a PR
            run: gh pr review --approve "$PR_URL"
            env:
              PR_URL: ${{github.event.pull_request.html_url}}
              GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

          - name: Enable auto-merge for Dependabot PRs
            run: gh pr merge --auto --merge "$PR_URL"
            env:
              PR_URL: ${{github.event.pull_request.html_url}}
              # The documentation incorrectly forgets `GITHUB_TOKEN` here.
              GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
Run Code Online (Sandbox Code Playgroud)

上述自动化工作正常,但我有一个分支保护规则,需要代码所有者的审查。

有没有办法包含github-actions到 CODEOWNERS 文件中以使其批准有效?

Ric*_*kow 8

截至目前,GitHub 应用程序无法添加到此处引用的 CODEOWNERS.

\n
\n

非常感谢您的到来!目前,GitHub 应用程序不能在不支持的代码所有者 \xe2\x80\x93 中使用\xe2\x80\x99。这是团队未来正在考虑的事情,我一定会将您的用例添加到内部功能请求中。

\n
\n

但是,您可以做的是使用您自己生成的 GitHub 个人访问令牌(如此处文档中所述) ,然后将其添加为机密并在您的工作流程中使用它。请参阅GitHub 文档 .

\n

然后,您操作的最后一步将引用您自定义的秘密。在下面的示例中,我假设它被称为MYTOKEN

\n
          - name: Enable auto-merge for Dependabot PRs\n            run: gh pr merge --auto --merge "$PR_URL"\n            env:\n              PR_URL: ${{github.event.pull_request.html_url}}\n              # The documentation incorrectly forgets `GITHUB_TOKEN` here.\n              GITHUB_TOKEN: ${{secrets.MYTOKEN}}\n
Run Code Online (Sandbox Code Playgroud)\n

通过这种方法,合并将以您的用户身份完成,我认为您的用户是代码所有者的一部分。

\n