|
1 |
| -name: Test Org Membership |
| 1 | +name: Survey on Merged PR by Non-Member |
2 | 2 |
|
3 | 3 | 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] |
14 | 6 |
|
15 | 7 | jobs:
|
16 |
| - test-membership: |
| 8 | + comment-on-pr: |
17 | 9 | runs-on: ubuntu-latest
|
18 |
| - |
| 10 | + if: github.event.pull_request.merged == true |
19 | 11 | 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 |
22 | 26 |
|
23 | 27 | - name: Check if user is a member of the org
|
24 | 28 | id: check-membership
|
25 | 29 | 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 |
31 | 34 | echo "MEMBER_FOUND=true" >> $GITHUB_ENV
|
32 | 35 | else
|
33 | 36 | echo "MEMBER_FOUND=false" >> $GITHUB_ENV
|
34 | 37 | fi
|
| 38 | + env: |
| 39 | + GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }} |
35 | 40 |
|
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' |
37 | 43 | 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