Skip to content

Commit 2368396

Browse files
authored
chore: Migrate to otelbot (#3039)
1 parent 9d689e1 commit 2368396

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

.github/workflows/survey-on-merged-pr.yml

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,40 @@ permissions:
99

1010
env:
1111
PR_NUM: ${{ github.event.pull_request.number }}
12-
SURVEY_URL: https://docs.google.com/forms/d/e/1FAIpQLSf2FfCsW-DimeWzdQgfl0KDzT2UEAqu69_f7F2BVPSxVae1cQ/viewform?entry.1540511742=open-telemetry/opentelemetry-js-contrib
12+
SURVEY_URL: https://docs.google.com/forms/d/e/1FAIpQLSf2FfCsW-DimeWzdQgfl0KDzT2UEAqu69_f7F2BVPSxVae1cQ/viewform?entry.1540511742=${{ github.repository }}
1313

1414
jobs:
1515
comment-on-pr:
1616
name: Add survey to PR if author is not a member
1717
runs-on: ubuntu-latest
18-
permissions:
19-
contents: write
20-
pull-requests: write
2118
if: github.event.pull_request.merged == true
2219
steps:
23-
- uses: actions/checkout@v5
24-
- name: Check if user is a member of the org
25-
id: check-membership
20+
- uses: actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b # v2.1.1
21+
id: otelbot-token
22+
with:
23+
app-id: ${{ vars.OTELBOT_APP_ID }}
24+
private-key: ${{ secrets.OTELBOT_PRIVATE_KEY }}
25+
26+
- name: Add survey comment if author is not a member or bot
2627
run: |
27-
USERNAME=$(jq -r '.pull_request.user.login' "$GITHUB_EVENT_PATH")
28+
USERNAME="${{ github.event.pull_request.user.login }}"
29+
USER_TYPE="${{ github.event.pull_request.user.type }}"
2830
ORG="${{ github.repository_owner }}"
29-
STATUS=$(gh api "orgs/$ORG/members/$USERNAME" --silent && echo "true" || echo "false")
30-
if [[ "$STATUS" == "true" ]]; then
31-
echo "MEMBER_FOUND=true" >> $GITHUB_ENV
32-
else
33-
echo "MEMBER_FOUND=false" >> $GITHUB_ENV
31+
32+
# Skip if user is a bot
33+
if [[ "$USER_TYPE" == "Bot" ]]; then
34+
echo "Skipping survey for bot user: $USERNAME"
35+
exit 0
3436
fi
37+
38+
# Skip if user is an org member
39+
if gh api "orgs/$ORG/members/$USERNAME" --silent; then
40+
echo "Skipping survey for org member: $USERNAME"
41+
exit 0
42+
fi
43+
44+
# Add survey comment for external contributor
45+
echo "Adding survey comment for external contributor: $USERNAME"
46+
gh pr comment ${PR_NUM} --repo ${{ github.repository }} --body "Thank you for your contribution @${USERNAME}! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this [survey](${SURVEY_URL})."
3547
env:
36-
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
37-
38-
- name: Add comment to PR if author is not a member
39-
if: env.MEMBER_FOUND == 'false'
40-
run: |
41-
USERNAME=$(jq -r '.pull_request.user.login' "$GITHUB_EVENT_PATH")
42-
gh pr comment ${PR_NUM} --repo open-telemetry/opentelemetry-js-contrib --body "Thank you for your contribution @${USERNAME}! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this [survey](${SURVEY_URL})."
43-
env:
44-
GH_TOKEN: ${{ secrets.OPENTELEMETRYBOT_GITHUB_TOKEN }}
48+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}

0 commit comments

Comments
 (0)