Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
git-merge

GitHub Action

Code Owner Self Merge

v1.2.1

Code Owner Self Merge

git-merge

Code Owner Self Merge

Lets the CODEOWNERS file determine who can merge a PR

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Code Owner Self Merge

uses: OSS-Docs-Tools/code-owner-self-merge@v1.2.1

Learn more about this action in OSS-Docs-Tools/code-owner-self-merge

Choose a version

A GitHub action that lets code-owners merge PRs via a comment.

This action uses the standardized structure of a CODEOWNERS file to handle the access controls.

A simple example

So, with this file at: .github/CODEOWNERS:

README.md @orta

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'".

Then, when/if this happens the GitHub Action will merge for you.

A real-world example

.github/CODEOWNERS:

# Collaborators for Japanese Translation of the Website
packages/playground-examples/copy/ja/** @sasurau4 @Quramy @Naturalclar @Takepepe @orta
packages/tsconfig-reference/copy/ja/** @sasurau4 @Quramy @Naturalclar @Takepepe @orta
packages/typescriptlang-org/src/copy/ja/** @sasurau4 @Quramy @Naturalclar @Takepepe @orta
packages/documentation/copy/ja/** @sasurau4 @Quramy @Naturalclar @Takepepe @orta

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. Code owners can use a review, or a comment to merge.

Setting It Up

You want a unique workflow file, e.g. .github/workflows/codeowners-merge.yml

name: Codeowners merging
on:
  pull_request_target: { types: opened }
  issue_comment: { types: created }
  pull_request_review: { types: submitted }

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v1
      - name: Run Codeowners merge check
        uses:  orta/code-owner-self-merge@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Then you should be good to go.

Security

We force the use of pull_request_target 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.

Dev

Use npx jest --watch to run tests.

Deploy

Use the GH UI to make a tag and release