|
1 | 1 | # codeowners-automerge |
2 | 2 | Automerges PRs from code owners that only change owned files. |
| 3 | + |
| 4 | + |
| 5 | +## Main usecase |
| 6 | +You want CODEOWNERS to be able to self-merge PRs to files they are "owners" of. |
| 7 | + |
| 8 | +The code owners could be external users of a public repo, or collaborators added |
| 9 | +to a repo that has "Require a pull request before merging" enabled + "Require review from Code Owners". |
| 10 | + |
| 11 | +This bot will check if all files changed in a given PR have the submitter as |
| 12 | +their codeowner, and if so the PR will be merged automatically. |
| 13 | + |
| 14 | +Note that if you have branch rules, you will need to give the bot a admin token |
| 15 | +in order to be able to bypass rules: |
| 16 | + |
| 17 | +```diff |
| 18 | +- GITHUB_TOKEN = ${{ secrets.GITHUB_TOKEN }} |
| 19 | ++ GITHUB_TOKEN = ${{ secrets.AUTOMERGE_TOKEN }} |
| 20 | +``` |
| 21 | + |
| 22 | +>[!NOTE] |
| 23 | +>The bot will use as source of truth the CODEOWNERS file at the latest commmit |
| 24 | +>of the default branch. In other words a PR that modifies CODEOWNERS will not be |
| 25 | +>able to hijack the bot. |
| 26 | +
|
| 27 | +## Usage |
| 28 | + |
| 29 | +1. Setup [CODEOWNERS](https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners) and restrict user's write access to the repo as needed. |
| 30 | +2. Add a workflow that uses this Action. If you have other jobs, you might |
| 31 | + want to have the automerge job depend on their success. |
| 32 | + |
| 33 | +Example workflow: |
| 34 | + |
| 35 | +```yaml |
| 36 | +name: Codeowners Automerge |
| 37 | +on: |
| 38 | + pull_request_target: { types: [opened, synchronize] } |
| 39 | + |
| 40 | +jobs: |
| 41 | + codeowners-automerge: |
| 42 | + runs-on: ubuntu-latest |
| 43 | + # needs: [other-check1, other-check2] |
| 44 | + permissions: |
| 45 | + pull-requests: write |
| 46 | + contents: write |
| 47 | + steps: |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + fetch-depth: 0 |
| 51 | + - name: Codeowners Automerge Check |
| 52 | + uses: kristoff-it/codeowners-automerge@v1 |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | +``` |
| 56 | +
|
| 57 | +Supported options: |
| 58 | +
|
| 59 | +```yaml |
| 60 | +- name: Codeowners automerge check |
| 61 | + uses: kristoff-it/codeowners-automerge@v1 |
| 62 | + with: |
| 63 | + dir: ".github/" |
| 64 | + merge_method: 'merge' # 'merge' 'squash' 'rebase' |
| 65 | +``` |
| 66 | +
|
| 67 | +
|
| 68 | +
|
| 69 | +
|
| 70 | +
|
| 71 | +
|
| 72 | +
|
| 73 | + |
0 commit comments