|
1 |
| -A GitHub action that lets code-owners merge code via GitHub reviews. |
| 1 | +A GitHub action that lets code-owners merge PRs via a comment. |
| 2 | + |
| 3 | +This action uses the standardized structure of [a CODEOWNERS file](https://github.blog/2017-07-06-introducing-code-owners/) to handle the access controls. |
| 4 | + |
| 5 | +## A simple example |
| 6 | + |
| 7 | +So, with this file at: `.github/CODEOWNERS`: |
| 8 | + |
| 9 | +```sh |
| 10 | +README.md @orta |
| 11 | +``` |
| 12 | + |
| 13 | +If a PR contained _only_ a change to the `README.md` - this action would say that "@orta has the ability to merge by commenting 'LGTM'". |
| 14 | + |
| 15 | +Then, when/if this happens the GitHub Action will merge for you. |
| 16 | + |
| 17 | +## A real-world example |
| 18 | + |
| 19 | +`.github/CODEOWNERS`: |
| 20 | + |
| 21 | +```sh |
| 22 | +# Collaborators for Japanese Translation of the Website |
| 23 | +packages/playground-examples/copy/ja/** @sasurau4 @Quramy @Naturalclar @Takepepe @orta |
| 24 | +packages/tsconfig-reference/copy/ja/** @sasurau4 @Quramy @Naturalclar @Takepepe @orta |
| 25 | +packages/typescriptlang-org/src/copy/ja/** @sasurau4 @Quramy @Naturalclar @Takepepe @orta |
| 26 | +packages/documentation/copy/ja/** @sasurau4 @Quramy @Naturalclar @Takepepe @orta |
| 27 | +``` |
| 28 | + |
| 29 | +This allows any of `@sasurau4`, `@Quramy`, `@Naturalclar`, `@Takepepe` or `@orta` to merge PRs which affect their areas of the translation process in the TypeScript Website repo. |
| 30 | + |
| 31 | +## Setting It Up |
| 32 | + |
| 33 | +You want a unique workflow file, e.g. `.github/workflows/codeowners-merge.yml` |
2 | 34 |
|
3 | 35 | ```yml
|
4 |
| -name: Example Workflow |
| 36 | +name: Codeowners merging |
5 | 37 | on:
|
6 | 38 | pull_request_target:
|
7 | 39 | issue_comment: { types: created }
|
8 | 40 |
|
9 | 41 | jobs:
|
10 | 42 | build:
|
11 |
| - |
12 | 43 | runs-on: ubuntu-latest
|
13 |
| - |
| 44 | + |
14 | 45 | steps:
|
15 | 46 | - uses: actions/checkout@v1
|
16 |
| - - name: Runs this workflow |
| 47 | + - name: Run Codeowners merge check |
17 | 48 | env:
|
18 | 49 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
19 | 50 | uses: orta/code-organizer-merge-on-green@master
|
| 51 | +``` |
20 | 52 |
|
| 53 | +Then you should be good to go. |
21 | 54 |
|
22 |
| -``` |
| 55 | +### Security |
| 56 | +
|
| 57 | +We force the use of [`pull_request_target`](https://github.blog/2020-08-03-github-actions-improvements-for-fork-and-pull-request-workflows/) as a workflow event to ensure that someone cannot change the CODEOWNER files at the same time as having that change be used to validate if they can merge. |
0 commit comments