-
Notifications
You must be signed in to change notification settings - Fork 106
[Github Action] Label community issues #1746
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
Merged
florent-leborgne
merged 4 commits into
elastic:main
from
florent-leborgne:label-community-issues
Jun 24, 2025
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
af5c985
Action for identifying issues open by community
florent-leborgne 36a0757
Add yml
florent-leborgne c2ae48d
change script to use PAT for reading membership
florent-leborgne 052b5ee
Merge branch 'main' into label-community-issues
florent-leborgne 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,58 @@ | ||
name: Label Community Issues | ||
|
||
on: | ||
issues: | ||
types: [opened] | ||
|
||
jobs: | ||
label-community-issues: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
issues: write | ||
contents: read | ||
|
||
steps: | ||
- name: Check organization membership | ||
id: check-membership | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.ORG_MEMBER_READ_TOKEN }} | ||
script: | | ||
const issueAuthor = '${{ github.event.issue.user.login }}'; | ||
const orgName = 'elastic'; | ||
|
||
try { | ||
await github.rest.orgs.getMembershipForUser({ | ||
org: orgName, | ||
username: issueAuthor | ||
}); | ||
|
||
console.log(`${issueAuthor} is a member of ${orgName} organization`); | ||
return 'member'; | ||
|
||
} catch (error) { | ||
if (error.status === 404) { | ||
console.log(`${issueAuthor} is not a member of ${orgName} organization`); | ||
return 'non-member'; | ||
} else { | ||
console.log('Error checking organization membership:', error); | ||
return 'error'; | ||
} | ||
} | ||
|
||
- name: Add community label | ||
if: steps.check-membership.outputs.result == 'non-member' | ||
uses: actions/github-script@v7 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
const issueAuthor = '${{ github.event.issue.user.login }}'; | ||
|
||
await github.rest.issues.addLabels({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.issue.number, | ||
labels: ['community'] | ||
}); | ||
|
||
console.log(`Added "community" label to issue by ${issueAuthor}`); |
Oops, something went wrong.
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.
unfortunately, I'm afraid this won't work with the standard github token.
You need a PAT that is able to read org membership
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.
Argh yes I didn't consider most of our users have private membership.
Can we use a PAT that we store somewhere safe and invoke it here?
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.
Yes. Adding it to the GitHub repository secrets should be sufficient for now.
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.
Nice, is this something you can help with? I don't have any permissions to do such things I believe
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.
I created the
ORG_MEMBER_READ_TOKEN
which can be accessed withsecrets.ORG_MEMBER_READ_TOKEN
.For now it's configured to our max TTL. We can revisit this in a couple of months.
The platform team is working on ephemeral token service that we can utilize in the future.
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.
The token can only read the membership. Hence you might need to split the script into two steps. One for reading and one for adding the label
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.
Ok thank you :) will look into it later!