From 1399504142ed6b4be444bffcb93665211a6b468f Mon Sep 17 00:00:00 2001 From: John Westcott IV <32551173+john-westcott-iv@users.noreply.github.com> Date: Fri, 4 Nov 2022 11:55:47 -0400 Subject: [PATCH] Adding community labels on PRs and Issues (#1108) --- .github/workflows/label_issue.yml | 54 +++++++++++++++++++++++++++++++ .github/workflows/label_pr.yml | 40 +++++++++++++++++++++++ .github/workflows/triage_new.yml | 22 ------------- 3 files changed, 94 insertions(+), 22 deletions(-) create mode 100644 .github/workflows/label_issue.yml create mode 100644 .github/workflows/label_pr.yml delete mode 100644 .github/workflows/triage_new.yml diff --git a/.github/workflows/label_issue.yml b/.github/workflows/label_issue.yml new file mode 100644 index 00000000..e29a8bab --- /dev/null +++ b/.github/workflows/label_issue.yml @@ -0,0 +1,54 @@ +--- +name: Label Issues + +on: + issues: + types: + - opened + - reopened + +jobs: + triage: + runs-on: ubuntu-latest + name: Label + + steps: + - name: Label Issue - Needs Triage + uses: github/issue-labeler@v2.4.1 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" + not-before: 2021-12-07T07:00:00Z + configuration-path: .github/issue_labeler.yml + enable-versioned-regex: 0 + if: github.event_name == 'issues' + + 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 new file mode 100644 index 00000000..356e3dcc --- /dev/null +++ b/.github/workflows/label_pr.yml @@ -0,0 +1,40 @@ +name: Label PR + +on: + pull_request_target: + types: + - opened + - reopened + - synchronize + +jobs: + 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 }} diff --git a/.github/workflows/triage_new.yml b/.github/workflows/triage_new.yml deleted file mode 100644 index b54c3c6f..00000000 --- a/.github/workflows/triage_new.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -name: Triage - -on: - issues: - types: - - opened - -jobs: - triage: - runs-on: ubuntu-latest - name: Label - - steps: - - name: Label issues - uses: github/issue-labeler@v2.4.1 - with: - repo-token: "${{ secrets.GITHUB_TOKEN }}" - not-before: 2021-12-07T07:00:00Z - configuration-path: .github/issue_labeler.yml - enable-versioned-regex: 0 - if: github.event_name == 'issues'