Dependabot生成的拉取请求如何自动合并代码所有者文件和分支保护规则?

5

我已经按照这里描述的方式创建了GitHub Actions的工作流程:

https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/automating-dependabot-with-github-actions
    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}}

以上自动化方案可行,但是我有一个分支保护规则需要代码所有者审查。

是否有一种方法可以将 github-actions 包含在 CODEOWNERS 文件中,以便使其批准计数?


使用代码所有者账户的PAT代替GITHUB_TOKEN,行为是否相同? - GuiFalourd
1个回答

8
目前,GitHub应用程序不能像这里引用的那样添加到CODEOWNERS中。
谢谢您的使用!目前,GitHub应用程序无法在CODEOWNERS中使用-不支持此功能。这是团队考虑将来的事情,并且我一定会将您的用例添加到内部功能请求中。
但是,您可以使用自己生成的GitHub个人访问令牌,如此处的文档所述,然后将其添加为密钥并在工作流程中使用它。请参见GitHub文档
您的操作的最后一步将引用您自定义的密钥。在下面的示例中,我假设它被称为MYTOKEN
          - 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.MYTOKEN}}

使用这种方法,合并将作为您的用户完成,我假设您是CODEOWNERS的一部分。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接