From afe18b5cfb3c102ec0458ba215b70c66b25ddd73 Mon Sep 17 00:00:00 2001 From: Peter Nied Date: Tue, 17 Oct 2023 09:26:09 -0500 Subject: [PATCH] Use another technique to read the table Signed-off-by: Peter Nied --- .github/workflows/test.yml | 10 +++++----- MAINTAINERS-Simple.md | 9 --------- README.md | 7 +++++-- action.yml | 13 ++++++------- 4 files changed, 16 insertions(+), 23 deletions(-) delete mode 100644 MAINTAINERS-Simple.md diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 07884bf..7e5c4c7 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,7 +14,7 @@ jobs: uses: ./ # Use the action with: token: ${{ secrets.GITHUB_TOKEN }} - maintainers-file: ./MAINTAINERS-Simple.md + maintainers: peternied min-required: 1 mock-approvers: 'peternied' @@ -30,7 +30,7 @@ jobs: uses: ./ # Use the action with: token: ${{ secrets.GITHUB_TOKEN }} - maintainers-file: ./MAINTAINERS-Simple.md + maintainers: peternied min-required: 1 mock-approvers: 'peternied greengiant' @@ -46,7 +46,7 @@ jobs: uses: ./ # Use the action with: token: ${{ secrets.GITHUB_TOKEN }} - maintainers-file: ./MAINTAINERS-Simple.md + maintainers: peternied min-required: 1 mock-approvers: '' @@ -62,7 +62,7 @@ jobs: uses: ./ # Use the action with: token: ${{ secrets.GITHUB_TOKEN }} - maintainers-file: ./MAINTAINERS-Simple.md + maintainers: peternied min-required: 1 mock-approvers: 'greengiant' @@ -78,7 +78,7 @@ jobs: uses: ./ # Use the action with: token: ${{ secrets.GITHUB_TOKEN }} - maintainers-file: ./MAINTAINERS-Simple.md + maintainers: 'peternied greengiant' min-required: 2 mock-approvers: 'peternied' diff --git a/MAINTAINERS-Simple.md b/MAINTAINERS-Simple.md deleted file mode 100644 index 21e6ab4..0000000 --- a/MAINTAINERS-Simple.md +++ /dev/null @@ -1,9 +0,0 @@ -## Overview - -This document contains a list of maintainers in this repo. - -## Current Maintainers - -| Maintainer | GitHub ID | -| ---------- | ----------------------------------------- | -| Peter Nied | [peternied](https://github.com/peternied) | diff --git a/README.md b/README.md index dce4a52..f20c7a8 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,8 @@ inputs: token: description: "GitHub token used for authentication" required: true - maintainers-file: - description: 'The file where the maintainers are listed, defaults to MAINTAINERS.md' + maintainers: + description: 'The list of maintainers that can approve the request, space seperated' required: false min-required: description: 'The minimum number of maintainers required to approve, e.g. 2' @@ -24,6 +24,9 @@ on: types: [opened, reopened] ... steps: +- id: find-maintainers + run: echo "maintainers=$(cat C:/Users/peter/Documents/GitHub/OpenSearch/MAINTAINERS.md | grep -oP '(?<=\[).+(?=\]\(http)' | tr '\n' ' ')" >> $GITHUB_ENV + - uses: peternied/approved-by-maintainers@v1 with: token: ${{ secrets.GITHUB_TOKEN }} diff --git a/action.yml b/action.yml index c617de4..3993c9e 100644 --- a/action.yml +++ b/action.yml @@ -6,8 +6,8 @@ inputs: token: description: "GitHub token used for authentication" required: true - maintainers-file: - description: 'The file where the maintainers are listed, defaults to MAINTAINERS.md' + maintainers: + description: 'The list of maintainers that can approve the request, space seperated' required: false min-required: description: 'The minimum number of maintainers required to approve, e.g. 2' @@ -31,10 +31,6 @@ runs: fi shell: bash - - run: | - echo "maintainers=$(awk '/## Current Maintainers/ {flag=1; next} flag && /^\|/ {print $3} !/^\|/ && flag {exit}' ${{ inputs.maintainers-file }} | grep -oP '\[\K([^\]]+)')" >> $GITHUB_ENV - shell: bash - - run: | reviewers=$(curl -s -H "Authorization: token ${{ inputs.token }}" \ "https://api.github.com/repos/$GITHUB_REPOSITORY/pulls/${{ github.event.pull_request.number }}/reviews") @@ -50,9 +46,12 @@ runs: - run: | approvals_count=0 + maintainers-padded=" ${{ inputs.maintainers }} " # Padding before and after for substring safety check below maintainer_approvals="" for user in $approvers; do - if [[ $MAINTAINERS =~ $user ]]; then + # Match with strings padding the username on both sides to avoid substring matches + # e.g. maintainer named 'foo', someone creates a fake account named 'fake-foo' and approves + if [[ maintainers-padded == *" $user "* ]]; then echo "Approval by maintainer: $user" maintainer_approvals="$maintainer_approvals $user" ((approvals_count++))