Skip to content

Commit 9cdb862

Browse files
authored
go back to token (#65)
1 parent a8490dd commit 9cdb862

2 files changed

Lines changed: 44 additions & 16 deletions

File tree

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

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@ name: Survey on Merged PR by Non-Member
33

44
on:
55
workflow_call:
6+
inputs:
7+
client_id:
8+
description: >-
9+
Client ID of the caller repository's OTELBOT app. Used to mint an
10+
installation token that can comment on PRs and check org membership.
11+
required: true
12+
type: string
13+
secrets:
14+
private_key:
15+
description: PEM private key for the OTELBOT app referenced by client_id.
16+
required: true
617

718
permissions: {}
819

@@ -13,22 +24,31 @@ jobs:
1324
comment-on-pr:
1425
name: Add survey to PR if author is not a member
1526
runs-on: ubuntu-latest
16-
permissions:
17-
pull-requests: write # for gh pr comment
1827
if: >-
1928
github.event.pull_request.merged == true &&
2029
github.repository_owner == 'open-telemetry' &&
21-
github.event.pull_request.user.type != 'Bot' &&
22-
github.event.pull_request.author_association != 'MEMBER' &&
23-
github.event.pull_request.author_association != 'OWNER' &&
24-
github.event.pull_request.author_association != 'COLLABORATOR'
30+
github.event.pull_request.user.type != 'Bot'
2531
steps:
26-
- name: Add survey comment
32+
- uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
33+
id: otelbot-token
34+
with:
35+
client-id: ${{ inputs.client_id }}
36+
private-key: ${{ secrets.private_key }}
37+
permission-pull-requests: write # for 'gh pr comment ...'
38+
permission-members: read # for 'gh api orgs/$ORG/members/$USERNAME'
39+
40+
- name: Add survey comment if author is not an org member
2741
env:
28-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
29-
REPO: ${{ github.repository }}
42+
GH_TOKEN: ${{ steps.otelbot-token.outputs.token }}
3043
USERNAME: ${{ github.event.pull_request.user.login }}
44+
REPO: ${{ github.repository }}
45+
ORG: ${{ github.repository_owner }}
3146
PR_NUMBER: ${{ github.event.pull_request.number }}
3247
run: |
3348
set -euo pipefail
49+
if gh api "orgs/$ORG/members/$USERNAME" --silent; then
50+
echo "Skipping survey for org member: $USERNAME"
51+
exit 0
52+
fi
53+
echo "Adding survey comment for external contributor: $USERNAME"
3454
gh pr comment "$PR_NUMBER" --repo "$REPO" --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})."

survey-on-merged-pr/README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,28 @@ permissions: {}
2626

2727
jobs:
2828
survey:
29-
permissions:
30-
pull-requests: write # required by the shared workflow to post the survey comment
3129
uses: open-telemetry/shared-workflows/.github/workflows/survey-on-merged-pr.yml@<sha-or-tag>
30+
with:
31+
client_id: ${{ vars.OTELBOT_CLIENT_ID }}
32+
secrets:
33+
private_key: ${{ secrets.OTELBOT_PRIVATE_KEY }}
3234
```
3335
34-
Pin `<sha-or-tag>` to a commit SHA or release tag in this repository. No inputs, no secrets — the workflow uses the built-in `GITHUB_TOKEN` and posts as `github-actions[bot]`.
36+
Pin `<sha-or-tag>` to a commit SHA or release tag in this repository. Substitute the variable/secret names on the right-hand sides to match whatever your repo uses.
3537

36-
## Required permissions
38+
The `zizmor: ignore[dangerous-triggers]` inline comment on the `pull_request_target:` line is only relevant if your repo runs [zizmor](https://github.com/zizmorcore/zizmor); it silences the false-positive finding since this caller doesn't check out any PR-controlled code — it just invokes the shared workflow which itself operates entirely through the GitHub API.
3739

38-
The caller's job-level `permissions:` block **must** grant `pull-requests: write`. The shared workflow needs it to post the survey comment via `gh pr comment`.
40+
## Inputs
3941

40-
A [reusable workflow cannot elevate its own permissions beyond what the caller grants](https://docs.github.com/en/actions/using-workflows/reusing-workflows), so a caller job without `pull-requests: write` will fail with a permission error when the comment step runs.
42+
| Input | Required | Type | Description |
43+
| --- | --- | --- | --- |
44+
| `client_id` | yes | `string` | OTELBOT app Client ID for the caller repo. Pass the value of your `OTELBOT_CLIENT_ID`-style variable. |
4145

42-
The `zizmor: ignore[dangerous-triggers]` inline comment on the `pull_request_target:` line is only relevant if your repo runs [zizmor](https://github.com/zizmorcore/zizmor); it silences the false-positive finding since this caller doesn't check out any PR-controlled code — it just invokes the shared workflow which itself operates entirely through the GitHub API.
46+
## Secrets
47+
48+
| Secret | Required | Description |
49+
| --- | --- | --- |
50+
| `private_key` | yes | PEM private key for the OTELBOT app referenced by `client_id`. |
4351

4452
## Behavior notes
4553

0 commit comments

Comments
 (0)