Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/actions/update-snapshots-check-permission/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Check user permission before running the update snapshots workflow
description: |
Check user permission before running the update snapshots workflow.
Reacts with either a thumb up or a thumb down to the comment depending on the user rights.

inputs:
# Mandatory inputs
github_token:
description: "The GitHub token to use"
required: true

runs:
using: composite
steps:
- name: Get commenter association
id: association
env:
GH_TOKEN: ${{ inputs.github_token }}
run: |
association=$(gh api \
repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }} \
--jq '.author_association')

echo "association=$association" >> $GITHUB_OUTPUT

- name: Fail if user is not authorized
if: |
!contains(fromJSON('["OWNER","COLLABORATOR","MEMBER"]'), steps.association.outputs.association)
run: |
gh api repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions --raw-field 'content=-1'
echo "User not authorized to update snapshots"
exit 1
env:
GITHUB_TOKEN: ${{ inputs.github_token }}

- name: React positively to the triggering comment
run: |
gh api repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions --raw-field 'content=+1'
env:
GITHUB_TOKEN: ${{ inputs.github_token }}
Loading