Skip to content

Commit 71bfebc

Browse files
authored
Merge pull request #9 from tsalemink/auth_dev
Add permission check for update-database action
2 parents 73e9850 + f8013c7 commit 71bfebc

3 files changed

Lines changed: 41 additions & 2 deletions

File tree

.github/workflows/update-database.yaml

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,32 @@ on:
1010
push:
1111

1212
jobs:
13+
check-permission:
14+
runs-on: ubuntu-latest
15+
outputs:
16+
authorised: ${{ steps.check-permission.outputs.authorised }}
17+
steps:
18+
- name: Determine if user has permission to update the database
19+
id: check-permission
20+
run: |
21+
USER=${{ github.event.sender.login }}
22+
REPO=${{ github.repository }}
23+
RESPONSE=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
24+
"https://api.github.com/repos/$REPO/collaborators/$USER/permission")
25+
PERMISSION=$(echo "$RESPONSE" | sed -n 's/.*"permission": "\(.*\)".*/\1/p')
26+
if [ "$PERMISSION" = "admin" ] || [ "$PERMISSION" = "maintain" ] || [ "$PERMISSION" = "write" ]; then
27+
AUTHORISED="true"
28+
else
29+
AUTHORISED="false"
30+
fi
31+
echo "authorised=$AUTHORISED" >> $GITHUB_OUTPUT
32+
1333
update-database:
34+
needs: check-permission
1435
# If the workflow was triggered by closing an issue, only run if the issue contains the 'add-plugin' label.
15-
if: ${{ github.event_name == 'workflow_dispatch' }} or ${{ github.event.label.name == 'add-plugin' }}
36+
if: |
37+
needs.check-permission.outputs.authorised == 'true' &&
38+
(github.event_name == 'workflow_dispatch' || github.event.label.name == 'add-plugin')
1639
runs-on: ubuntu-latest
1740
steps:
1841
- name: Checkout repo content
@@ -23,7 +46,7 @@ jobs:
2346
- name: Retrieve URL submission
2447
id: url
2548
run: |
26-
if ${{ github.event_name == 'issues' }}; then
49+
if [ "${{ github.event_name }}" == "issues" ]; then
2750
echo "url=${{ github.event.issue.body }}" >> $GITHUB_OUTPUT
2851
else
2952
echo "url=''" >> $GITHUB_OUTPUT

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
5+
# Distribution / packaging
6+
wheels/
7+
build/
8+
dist/
9+
*.egg-info/
10+
*.egg
11+
.eggs/
12+
13+
# Intellij projects
14+
.idea/

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@ MAP-Client users are able to submit their own MAP plugins to the MAP Plugin Data
1717
to submit an issue in the `MAP Plugin Database`_ GitHub repository. The issue should be tagged with the *add-plugin* label. The body of the
1818
issue submission should contain only the GitHub repository path of the plugin to be added; this path should be in the format:
1919
*{organization}/{repository}*, for example: *mapclient-plugins/pointsourcestep*.
20+
21+
Editing database entries and triggering the automated processes to update this database are restricted to repository maintainers.

0 commit comments

Comments
 (0)