From af5c98577695632cbe6913debe1492bd0eb21e43 Mon Sep 17 00:00:00 2001 From: Florent Le Borgne Date: Mon, 16 Jun 2025 17:53:11 +0200 Subject: [PATCH 1/3] Action for identifying issues open by community --- .github/workflows/label-community-issues.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .github/workflows/label-community-issues.yml diff --git a/.github/workflows/label-community-issues.yml b/.github/workflows/label-community-issues.yml new file mode 100644 index 0000000000..e69de29bb2 From 36a0757c613d3bea1ba680fd31198b7d2b281e3d Mon Sep 17 00:00:00 2001 From: Florent Le Borgne Date: Mon, 16 Jun 2025 17:58:02 +0200 Subject: [PATCH 2/3] Add yml --- .github/workflows/label-community-issues.yml | 51 ++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/.github/workflows/label-community-issues.yml b/.github/workflows/label-community-issues.yml index e69de29bb2..43b99fe062 100644 --- a/.github/workflows/label-community-issues.yml +++ b/.github/workflows/label-community-issues.yml @@ -0,0 +1,51 @@ +name: Label Community Issues + +on: + issues: + types: [opened] + +jobs: + label-community-issues: + runs-on: ubuntu-latest + permissions: + issues: write + contents: read + + steps: + - name: Check if user is organization member and label accordingly + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const issue = context.payload.issue; + const issueAuthor = issue.user.login; + const orgName = 'elastic'; + + try { + // Check if the user is a member of the elastic organization + await github.rest.orgs.getMembershipForUser({ + org: orgName, + username: issueAuthor + }); + + console.log(`${issueAuthor} is a member of ${orgName} organization`); + + } catch (error) { + // If the API call fails, it means the user is not a public member + // or not a member at all of the organization + if (error.status === 404) { + console.log(`${issueAuthor} is not a public member of ${orgName} organization`); + + // Add the "community" label + await github.rest.issues.addLabels({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: issue.number, + labels: ['community'] + }); + + console.log('Added "community" label to the issue'); + } else { + console.log('Error checking organization membership:', error); + } + } \ No newline at end of file From c2ae48dee11ec8a0c7118c5527ceec60dc871d9f Mon Sep 17 00:00:00 2001 From: Florent Le Borgne Date: Tue, 24 Jun 2025 11:08:12 +0200 Subject: [PATCH 3/3] change script to use PAT for reading membership --- .github/workflows/label-community-issues.yml | 45 +++++++++++--------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/.github/workflows/label-community-issues.yml b/.github/workflows/label-community-issues.yml index 43b99fe062..583e3f33cc 100644 --- a/.github/workflows/label-community-issues.yml +++ b/.github/workflows/label-community-issues.yml @@ -12,40 +12,47 @@ jobs: contents: read steps: - - name: Check if user is organization member and label accordingly + - name: Check organization membership + id: check-membership uses: actions/github-script@v7 with: - github-token: ${{ secrets.GITHUB_TOKEN }} + github-token: ${{ secrets.ORG_MEMBER_READ_TOKEN }} script: | - const issue = context.payload.issue; - const issueAuthor = issue.user.login; + const issueAuthor = '${{ github.event.issue.user.login }}'; const orgName = 'elastic'; try { - // Check if the user is a member of the elastic organization await github.rest.orgs.getMembershipForUser({ org: orgName, username: issueAuthor }); console.log(`${issueAuthor} is a member of ${orgName} organization`); + return 'member'; } catch (error) { - // If the API call fails, it means the user is not a public member - // or not a member at all of the organization if (error.status === 404) { - console.log(`${issueAuthor} is not a public member of ${orgName} organization`); - - // Add the "community" label - await github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: issue.number, - labels: ['community'] - }); - - console.log('Added "community" label to the issue'); + console.log(`${issueAuthor} is not a member of ${orgName} organization`); + return 'non-member'; } else { console.log('Error checking organization membership:', error); + return 'error'; } - } \ No newline at end of file + } + + - 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}`); \ No newline at end of file