Skip to content
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

ci: don't add a external label to issues from organisation members #13752

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 39 additions & 8 deletions .github/workflows/label_external_issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,47 @@ jobs:
label-external-issues:
name: Label issue from external user
runs-on: ubuntu-latest
# https://docs.github.com/en/graphql/reference/enums#commentauthorassociation
if: ${{ !contains(fromJson('["MEMBER", "OWNER", "COLLABORATOR"]'), github.event.issue.author_association) }}
steps:
- name: add external label
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['external']
})
const issueAuthor = context.payload.issue.user.login

if (context.repo.owner == issueAuthor) {
maximyurchuk marked this conversation as resolved.
Show resolved Hide resolved
console.log("Issue author is here");
return
}

const org = context.repo.owner;

const isOrgMember = async function () {
try {
const response = await github.rest.orgs.checkMembershipForUser({
org,
username: issueAuthor,
});
return response.status == 204;
} catch (error) {
if (error.status && error.status == 404) {
return false;
}
throw error;
}
}

console.log(`Checking membership for user: ${issueAuthor} in organization: ${org}`);

if (!await isOrgMember()) {
console.log(`User ${issueAuthor} is not a member of the organization.`)

github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['external']
})
} else {
console.log(`User ${issueAuthor} is a member of the organization.`)
}
Loading