From bcd018707aec96f5fb7d655d526dfb2d43f5f00b Mon Sep 17 00:00:00 2001 From: John Westcott IV <32551173+john-westcott-iv@users.noreply.github.com> Date: Tue, 23 Aug 2022 07:08:24 -0400 Subject: [PATCH] Adding ability to auto-apply community label to PRs and Issues (#12718) --- .github/workflows/label_issue.yml | 31 +++++++++++++++++++++++++++++++ .github/workflows/label_pr.yml | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/.github/workflows/label_issue.yml b/.github/workflows/label_issue.yml index c21eef4edf79..ead15724bbc0 100644 --- a/.github/workflows/label_issue.yml +++ b/.github/workflows/label_issue.yml @@ -19,3 +19,34 @@ jobs: not-before: 2021-12-07T07:00:00Z configuration-path: .github/issue_labeler.yml enable-versioned-regex: 0 + + community: + runs-on: ubuntu-latest + name: Label Issue - Community + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v4 + - name: Install python requests + run: pip install requests + - name: Check if user is a member of Ansible org + uses: jannekem/run-python-script-action@v1 + id: check_user + with: + script: | + import requests + headers = {'Accept': 'application/vnd.github+json', 'Authorization': 'token ${{ secrets.GITHUB_TOKEN }}'} + response = requests.get('${{ fromJson(toJson(github.event.issue.user.url)) }}/orgs?per_page=100', headers=headers) + is_member = False + for org in response.json(): + if org['login'] == 'ansible': + is_member = True + if is_member: + print("User is member") + else: + print("User is community") + - name: Add community label if not a member + if: contains(steps.check_user.outputs.stdout, 'community') + uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90 + with: + add-labels: "community" + repo-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/label_pr.yml b/.github/workflows/label_pr.yml index 5f9e25107fb6..8e3f8b81a210 100644 --- a/.github/workflows/label_pr.yml +++ b/.github/workflows/label_pr.yml @@ -18,3 +18,34 @@ jobs: with: repo-token: "${{ secrets.GITHUB_TOKEN }}" configuration-path: .github/pr_labeler.yml + + community: + runs-on: ubuntu-latest + name: Label PR - Community + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-python@v4 + - name: Install python requests + run: pip install requests + - name: Check if user is a member of Ansible org + uses: jannekem/run-python-script-action@v1 + id: check_user + with: + script: | + import requests + headers = {'Accept': 'application/vnd.github+json', 'Authorization': 'token ${{ secrets.GITHUB_TOKEN }}'} + response = requests.get('${{ fromJson(toJson(github.event.pull_request.user.url)) }}/orgs?per_page=100', headers=headers) + is_member = False + for org in response.json(): + if org['login'] == 'ansible': + is_member = True + if is_member: + print("User is member") + else: + print("User is community") + - name: Add community label if not a member + if: contains(steps.check_user.outputs.stdout, 'community') + uses: andymckay/labeler@e6c4322d0397f3240f0e7e30a33b5c5df2d39e90 + with: + add-labels: "community" + repo-token: ${{ secrets.GITHUB_TOKEN }}