From 082d85305663a3b5b51321fe1592449fb8b9fdeb Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Tue, 17 May 2022 14:24:07 +0200 Subject: [PATCH] Add up-for-grabs workflow - improve log messages in pr-first-response --- .github/workflows/pr-first-response.yml | 15 ++++- .github/workflows/up-for-grabs-response.yml | 63 +++++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/up-for-grabs-response.yml diff --git a/.github/workflows/pr-first-response.yml b/.github/workflows/pr-first-response.yml index 0969a883c9..991a5d0808 100644 --- a/.github/workflows/pr-first-response.yml +++ b/.github/workflows/pr-first-response.yml @@ -4,12 +4,12 @@ on: pull_request_target: types: [opened] -jobs: +jobs: send-response: runs-on: ubuntu-latest permissions: issues: write - pull-requests: write + pull-requests: write steps: - name: Install dependencies run: | @@ -45,8 +45,17 @@ jobs: body: data }); } else { - console.log("Status code did not indicate success:", response.status); + console.log("Returned data not indicate success."); + + if(response.status !== 200) { + console.log("Status code:", response.status) + } + console.log("Returned data:", data); + + if(data === '') { + console.log("An empty response usually indicates that either no comment was found or the actor user was not eligible for getting an automated response (HQ users are not getting auto-responses).") + } } } catch(error) { console.log(error); diff --git a/.github/workflows/up-for-grabs-response.yml b/.github/workflows/up-for-grabs-response.yml new file mode 100644 index 0000000000..51f04d1d83 --- /dev/null +++ b/.github/workflows/up-for-grabs-response.yml @@ -0,0 +1,63 @@ +name: pr-first-response + +on: + issues: + types: + - labeled + +jobs: + send-response: + if: github.event.label.name == 'community/up-for-grabs' + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - name: Install dependencies + run: | + npm install node-fetch@2 + - name: Fetch comment 🗣️ and add it to the issue + uses: actions/github-script@v6 + with: + script: | + const fetch = require('node-fetch'); + const response = await fetch('https://collaboratorsv2.euwest01.umbraco.io/umbraco/api/comments/PostComment', { + method: 'post', + body: JSON.stringify({ + repo: '${{ github.repository }}', + number: '${{ github.event.issue.number }}', + actor: '${{ github.event.issue.user.login }}', + commentType: 'labeled-up-for-grabs-first-comment' + }), + headers: { + 'Authorization': 'Bearer ${{ secrets.OUR_BOT_API_TOKEN }}', + 'Content-Type': 'application/json' + } + }); + + try { + const data = await response.text(); + + if(response.status === 200 && data !== '') { + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: data + }); + } else { + console.log("Returned data not indicate success."); + + if(response.status !== 200) { + console.log("Status code:", response.status) + } + + console.log("Returned data:", data); + + if(data === '') { + console.log("An empty response usually indicates that either no comment was found or the actor user was not eligible for getting an automated response (HQ users are not getting auto-responses).") + } + } + } catch(error) { + console.log(error); + };