Skip to content

Commit

Permalink
Use another technique to read the table
Browse files Browse the repository at this point in the history
Signed-off-by: Peter Nied <[email protected]>
  • Loading branch information
peternied committed Oct 17, 2023
1 parent 3b75294 commit afe18b5
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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'

Expand All @@ -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: ''

Expand All @@ -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'

Expand All @@ -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'

Expand Down
9 changes: 0 additions & 9 deletions MAINTAINERS-Simple.md

This file was deleted.

7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 }}
Expand Down
13 changes: 6 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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")
Expand All @@ -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++))
Expand Down

0 comments on commit afe18b5

Please sign in to comment.