Skip to content

Commit

Permalink
CI: Add approve-and-merge back as admin only. (#33028)
Browse files Browse the repository at this point in the history
  • Loading branch information
bnchrch authored Dec 2, 2023
1 parent 9ab20eb commit 13b631c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/approve-and-merge-dispatch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Approve and Merge Command Dispatch
on:
issue_comment:
types: [created]
jobs:
approveAndMergeDispatch:
runs-on: ubuntu-latest
steps:
- name: Auto Approve Slash Command Dispatch
uses: peter-evans/slash-command-dispatch@v3
id: scd
with:
token: ${{ secrets.GH_PAT_APPROVINGTON_OCTAVIA }}
permission: admin
issue-type: pull-request
repository: airbytehq/airbyte-platform-internal
dispatch-type: repository
commands: |
approve-and-merge
- name: Edit comment with error message
if: steps.scd.outputs.error-message
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ github.event.comment.id }}
body: |
> Error!: ${{ steps.scd.outputs.error-message }}
- name: Checkout Airbyte
id: checkout
if: failure() || steps.scd.outputs.error-message
uses: actions/checkout@v2

- name: Run get_repo_admins.sh
if: failure() || steps.scd.outputs.error-message
id: repo_admins
run: |
echo "REPO_ADMINS=$(./tools/bin/get_repo_admins.sh ${{ secrets.GH_PAT_APPROVINGTON_OCTAVIA }} airbytehq/airbyte)" >> $GITHUB_ENV
- name: Edit comment with repo admins
if: failure() || steps.scd.outputs.error-message
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ github.event.comment.id }}
body: |
>
> Important: This command can only be run by one of the repository admins:
> ${{ env.REPO_ADMINS }}
19 changes: 19 additions & 0 deletions tools/bin/get_repo_admins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# Check if the correct number of arguments is provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <personal_access_token> <repository>"
exit 1
fi

# Assign arguments to variables
TOKEN="$1"
REPO="$2"

# GitHub API URL for repository collaborators
API_URL="https://api.github.com/repos/$REPO/collaborators"

# Curl command to get the list of collaborators with admin rights
curl -H "Authorization: token $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
"$API_URL" | jq '.[] | select(.permissions.admin == true) | "[\(.login)](\(.html_url)),"' | tr -d '"' | paste -sd " " -

0 comments on commit 13b631c

Please sign in to comment.