-
Notifications
You must be signed in to change notification settings - Fork 3
Add reusable workflow to check external contributor status #78
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
solace-mdupls
wants to merge
13
commits into
main
Choose a base branch
from
feat/check-external-contributor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f12a17a
feat: Add reusable workflow to check external contributor status
solace-mdupls 316e24a
feat: Add reusable action to check external contributor status
solace-mdupls 05ce417
refactor: Remove workflow in favor of reusable action
solace-mdupls fdedc15
fix: Use github-script action for adding labels with proper permissions
solace-mdupls 94b4caf
fix: Use github-script for team membership check with error handling
solace-mdupls 472a5cc
Revert "fix: Use github-script for team membership check with error h…
solace-mdupls 19dd374
Revert "fix: Use github-script action for adding labels with proper p…
solace-mdupls fdf1dea
Reapply "fix: Use github-script action for adding labels with proper …
solace-mdupls 1fa523c
Revert "Reapply "fix: Use github-script action for adding labels with…
solace-mdupls 8ad13fa
Reapply "fix: Use github-script for team membership check with error …
solace-mdupls 993bf3d
fix: Replace gh CLI with github-script for label addition
solace-mdupls e9d7d6c
refactor: Move check-external-contributor action to root level
solace-mdupls 62e994b
.
solace-mdupls File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| name: Check External Contributor | ||
|
|
||
| on: | ||
| workflow_call: | ||
| inputs: | ||
| github_team_slug: | ||
| type: string | ||
| required: true | ||
| description: "GitHub team slug to check membership against (e.g., 'devs')" | ||
| label_name: | ||
| type: string | ||
| required: false | ||
| default: "external contributor" | ||
| description: "Label to add to PR if creator is not in the team" | ||
| secrets: | ||
| GITHUB_TOKEN: | ||
| required: true | ||
|
|
||
| permissions: | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| check-contributor: | ||
| name: Check PR Creator Team Membership | ||
| if: github.event_name == 'pull_request' | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check if PR creator is in team | ||
| id: check-team | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| script: | | ||
| const { data: teams } = await github.rest.teams.listMembershipsForAuthenticatedUser(); | ||
| const teamSlugs = teams.map(team => team.slug); | ||
| const teamSlug = '${{ inputs.github_team_slug }}'; | ||
|
|
||
| const isMember = teamSlugs.includes(teamSlug); | ||
| console.log(`Looking for team: ${teamSlug}`); | ||
| console.log(`User's teams: ${teamSlugs.join(', ')}`); | ||
| console.log(`Is member: ${isMember}`); | ||
|
|
||
| core.setOutput('is_member', isMember); | ||
|
|
||
| - name: Add external contributor label | ||
| if: steps.check-team.outputs.is_member == 'false' | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| script: | | ||
| const labelName = '${{ inputs.label_name }}'; | ||
| github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| labels: [labelName] | ||
| }); | ||
| console.log(`Added label "${labelName}" to PR #${context.issue.number}`); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐞 Bug - Wrong User Checked: Replace the API call with one that checks the PR creator's team membership. Get the PR creator from context.payload.pull_request.user.login and use github.rest.teams.getMembershipForUserInOrg() with the repository's organization (context.repo.owner), team_slug, and the PR creator's username.
Is this review accurate? Use 👍 or 👎 to rate it
If you want to tell us more, use
/gs feedbacke.g. /gs feedback this review doesn't make sense, I disagree, and it keeps repeating over and over