Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(benchmark): add comment permission check and filter paths #4766

Merged
merged 1 commit into from Apr 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 21 additions & 2 deletions .github/workflows/benchmark.yml
Expand Up @@ -4,6 +4,8 @@ on:
pull_request:
branches:
- '*'
paths:
- lib/**
issue_comment:
types:
- created
Expand All @@ -18,7 +20,8 @@ jobs:
github.event_name == 'pull_request' || (
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
startsWith(github.event.comment.body, 'test this please ✅')
github.event.issue.state == 'open' &&
startsWith(github.event.comment.body, '@npm-robot benchmark this')
)
env:
# gh cli uses these env vars for owner/repo/token
Expand All @@ -39,6 +42,12 @@ jobs:
PR="${{ github.event.pull_request.number }}"
else
PR="${{ github.event.issue.number }}"
SENDER="${{ github.event.issue.sender.login }}"
ROLE=$(gh api repos/${OWNER}/${REPO}/collaborators/${SENDER}/permission -q '.permission')
if [[ "$ROLE" != "admin"]]; then
echo "${SENDER} is ${ROLE}, not an admin, exiting"
exit 0
fi
fi

EVENT="${EVENT_NAME} ${OWNER}/${REPO}#${PR}"
Expand All @@ -58,11 +67,21 @@ jobs:
if: |
github.event_name == 'issue_comment' &&
github.event.issue.pull_request &&
startsWith(github.event.comment.body, 'test this please ✅')
github.event.issue.state == 'open' &&
startsWith(github.event.comment.body, '@npm-robot benchmark this')
env:
# gh cli uses this env var as the token
GITHUB_TOKEN: ${{ secrets.NPM_BENCHMARKS_TOKEN }}
run: |
OWNER="${{ github.event.repository.owner.login }}"
REPO="${{ github.event.repository.name }}"
SENDER="${{ github.event.issue.sender.login }}"
ROLE=$(gh api repos/${OWNER}/${REPO}/collaborators/${SENDER}/permission -q '.permission')
if [[ "$ROLE" != "admin"]]; then
echo "${SENDER} is ${ROLE}, not an admin, exiting"
exit 0
fi

COMMENT_NODE_ID="${{ github.event.comment.node_id }}"
QUERY='mutation ($inputData:AddReactionInput!) {
addReaction (input:$inputData) {
Expand Down