-
Notifications
You must be signed in to change notification settings - Fork 2
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
11
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 all commits
Commits
Show all changes
11 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 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,71 @@ | ||
| name: Check External Contributor | ||
| description: Checks if PR creator is in a GitHub team and adds a label if not | ||
|
|
||
| inputs: | ||
| github_team_slug: | ||
| description: "GitHub team slug to check membership against (e.g., 'solace-ai')" | ||
| required: true | ||
| label_name: | ||
| description: "Label to add to PR if creator is not in the team" | ||
| required: false | ||
| default: "external contributor" | ||
| github-token: | ||
| description: "GitHub token for API access" | ||
| required: true | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Check if PR creator is in team | ||
| id: check-team | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| github-token: ${{ inputs.github-token }} | ||
| script: | | ||
| const teamSlug = '${{ inputs.github_team_slug }}'; | ||
| const org = context.repo.owner; | ||
| const prCreator = context.payload.pull_request.user.login; | ||
|
|
||
| console.log(`🔍 Checking team membership for PR creator...`); | ||
| console.log(` - Team slug: ${teamSlug}`); | ||
| console.log(` - PR creator: ${prCreator}`); | ||
| console.log(` - Organization: ${org}`); | ||
|
|
||
| try { | ||
| const { data } = await github.rest.teams.getMembershipForUserInOrg({ | ||
| org: org, | ||
| team_slug: teamSlug, | ||
| username: prCreator | ||
| }); | ||
|
|
||
| core.setOutput('is_member', 'true'); | ||
| console.log(`✅ PR creator is a member of the team`); | ||
| } catch (error) { | ||
| if (error.status === 404) { | ||
| core.setOutput('is_member', 'false'); | ||
| console.log(`⚠️ PR creator is not a member of the team`); | ||
| } else { | ||
| console.log(`⚠️ Could not verify team membership (${error.message}), assuming external contributor`); | ||
| core.setOutput('is_member', 'false'); | ||
| } | ||
| } | ||
|
|
||
| - name: Add external contributor label | ||
| if: steps.check-team.outputs.is_member == 'false' | ||
| uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 | ||
| with: | ||
| github-token: ${{ inputs.github-token }} | ||
| script: | | ||
| const labelName = '${{ inputs.label_name }}'; | ||
| const prNumber = context.issue.number; | ||
|
|
||
| console.log(`🏷️ Adding label "${labelName}" to PR #${prNumber}...`); | ||
|
|
||
| await github.rest.issues.addLabels({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: prNumber, | ||
| labels: [labelName] | ||
| }); | ||
|
|
||
| console.log(`✅ Added label "${labelName}" to PR #${prNumber}`); | ||
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.
@solace-mdupls can we re-home this in the home folder. We wanted to move all the actions on the root-level
Also if you can generate a README.md on the same folder as the action.