51 lines
1.9 KiB
YAML
51 lines
1.9 KiB
YAML
name: Slash Command Dispatch
|
|
|
|
permissions: {}
|
|
|
|
on:
|
|
issue_comment:
|
|
types: [created]
|
|
workflow_dispatch:
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref || github.run_id }}
|
|
cancel-in-progress: false
|
|
|
|
jobs:
|
|
slashCommandDispatch:
|
|
name: slashCommandDispatch
|
|
runs-on: ubuntu-latest
|
|
timeout-minutes: 5
|
|
if: github.repository == 'tensorzero/tensorzero'
|
|
permissions:
|
|
pull-requests: write # For doing the emoji reaction on a PR comment
|
|
issues: write # For doing the emoji reaction on an issue comment
|
|
contents: write # For executing the repository_dispatch event
|
|
steps:
|
|
- name: "Check permission"
|
|
id: check-permission
|
|
env:
|
|
ACTOR: ${{ github.actor }}
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
MEMBER=$((gh api "orgs/tensorzero/members/$ACTOR" && echo 1) || echo 0)
|
|
echo "ACTOR_MEMBER=$MEMBER" >> $GITHUB_OUTPUT
|
|
|
|
- name: Leave a comment if permission check fails for a slash command
|
|
if: ${{ steps.check-permission.outputs.ACTOR_MEMBER != '1' && (startsWith(github.event.comment.body, '/')) }}
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
ISSUE_NUMBER: ${{ github.event.issue.number }}
|
|
run: |
|
|
gh issue comment "$ISSUE_NUMBER" --repo "$GITHUB_REPOSITORY" --body "❌ Only public members of the \`tensorzero\` organization can use slash commands"
|
|
|
|
- name: Slash Command Dispatch
|
|
if: ${{ steps.check-permission.outputs.ACTOR_MEMBER == '1' }}
|
|
uses: peter-evans/slash-command-dispatch@13bc09769d122a64f75aa5037256f6f2d78be8c4 # v4.0.0
|
|
with:
|
|
token: ${{ secrets.GITHUB_TOKEN }}
|
|
commands: |
|
|
check-fork
|
|
# Use our custom permission check above, since `peter-evans/slash-command-dispatch` doesn't handle organizations
|
|
permission: none
|