Skip to content

Commit b1a0ccd

Browse files
authored
Check team membership before actioning backport by comment (#28)
Require the commenter of post merge backport to be a member of a team.
1 parent 96aad20 commit b1a0ccd

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

.github/workflows/backport.yml

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,21 @@ on:
66
required: false
77
type: string
88
default: 'stable'
9-
9+
backport-team:
10+
required: true
11+
type: string
12+
description: 'The org/team-slug allowed to trigger /backport (e.g. my-org/my-team)'
1013
permissions:
1114
contents: write
1215
pull-requests: write
13-
1416
jobs:
1517
backport:
1618
name: Backport
1719
runs-on: ubuntu-latest
1820
# Only run if:
1921
# - triggered by pull request merging, or
20-
# - a label starting with `backport ` is added to a merged PR, or
21-
# - `/backport` commented on a PR by someone other than "Sei Platform / Code Agent" GitHub App.
22+
# - `/backport` commented on a PR by someone other than the bot
23+
# (team membership is verified in a later step)
2224
if: >
2325
(
2426
github.event_name == 'pull_request_target' &&
@@ -36,7 +38,20 @@ jobs:
3638
with:
3739
app-id: ${{ secrets.PLATFORM_CODE_AGENT_APP_ID }}
3840
private-key: ${{ secrets.PLATFORM_CODE_AGENT_APP_PK }}
39-
41+
- name: Check team membership for /backport comments
42+
if: github.event_name == 'issue_comment'
43+
env:
44+
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
45+
ORG_TEAM: ${{ inputs.backport-team }}
46+
COMMENT_USER: ${{ github.event.comment.user.login }}
47+
run: |
48+
ORG="${ORG_TEAM%%/*}"
49+
TEAM="${ORG_TEAM##*/}"
50+
if ! gh api "orgs/${ORG}/teams/${TEAM}/memberships/${COMMENT_USER}" --silent; then
51+
echo "::error::User ${COMMENT_USER} is not a member of ${ORG}/${TEAM}"
52+
exit 1
53+
fi
54+
echo "User ${COMMENT_USER} is a member of ${ORG_TEAM}"
4055
- uses: actions/checkout@v6
4156
- name: Create backport pull requests
4257
uses: korthout/backport-action@v4.3.0

0 commit comments

Comments
 (0)