Skip to content

Commit 4c9c562

Browse files
authored
Update survey-on-merged-pr.yml
1 parent ebcc12c commit 4c9c562

File tree

1 file changed

+29
-26
lines changed

1 file changed

+29
-26
lines changed
+29-26
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,45 @@
1-
name: Test Org Membership
1+
name: Survey on Merged PR by Non-Member
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
username:
7-
description: "GitHub username to check"
8-
required: true
9-
type: string
10-
org:
11-
description: "GitHub organization name"
12-
required: true
13-
type: string
4+
pull_request:
5+
types: [closed]
146

157
jobs:
16-
test-membership:
8+
comment-on-pr:
179
runs-on: ubuntu-latest
18-
10+
if: github.event.pull_request.merged == true
1911
steps:
20-
- name: Install GitHub CLI
21-
run: sudo apt-get install gh -y
12+
- name: Check if PR author is a member of the org
13+
id: check-membership
14+
run: |
15+
PR_AUTHOR=$(jq -r '.pull_request.user.login' "$GITHUB_EVENT_PATH")
16+
ORG_NAME="${{ github.repository_owner }}"
17+
ORG_MEMBERS=$(gh api "orgs/$ORG_NAME/members" --jq '.[].login')
18+
echo "PR_AUTHOR=${PR_AUTHOR}" >> $GITHUB_ENV
19+
echo "MEMBER_FOUND=false" >> $GITHUB_ENV
20+
for MEMBER in $ORG_MEMBERS; do
21+
if [[ "$PR_AUTHOR" == "$MEMBER" ]]; then
22+
echo "MEMBER_FOUND=true" >> $GITHUB_ENV
23+
break
24+
fi
25+
done
2226
2327
- name: Check if user is a member of the org
2428
id: check-membership
2529
run: |
26-
USERNAME="${{ inputs.username }}"
27-
ORG="${{ inputs.org }}"
28-
STATUS=$(gh api "orgs/$ORG/members/$USERNAME" -q '.login' || true)
29-
30-
if [[ "$STATUS" == "$USERNAME" ]]; then
30+
USERNAME=$(jq -r '.pull_request.user.login' "$GITHUB_EVENT_PATH")
31+
ORG="${{ github.repository_owner }}"
32+
STATUS=$(gh api "orgs/$ORG/members/$USERNAME" --silent && echo "true" || echo "false")
33+
if [[ "$STATUS" == "true" ]]; then
3134
echo "MEMBER_FOUND=true" >> $GITHUB_ENV
3235
else
3336
echo "MEMBER_FOUND=false" >> $GITHUB_ENV
3437
fi
38+
env:
39+
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
3540

36-
- name: Comment on the check result
41+
- name: Add comment to PR if author is not a member
42+
if: env.MEMBER_FOUND == 'false'
3743
run: |
38-
if [[ "$MEMBER_FOUND" == "true" ]]; then
39-
echo "✅ $USERNAME is a member of the $ORG organization."
40-
else
41-
echo "❌ $USERNAME is NOT a member of the $ORG organization."
42-
fi
44+
PR_NUMBER=${{ github.event.pull_request.number }}
45+
gh pr comment $PR_NUMBER --body "Thank you for your contribution! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by filling out this survey: https://forms.gle/WV58koUBGSG9HBY66"

0 commit comments

Comments
 (0)