From 55db8c14dfdadbe93938d7e36757fe8000406527 Mon Sep 17 00:00:00 2001 From: Steve Boyd Date: Wed, 28 Aug 2024 19:25:34 +1200 Subject: [PATCH] ENH Look for an existing rhino issue before creating a new one --- .github/workflows/rhino-issue.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/.github/workflows/rhino-issue.yml b/.github/workflows/rhino-issue.yml index 2f7e0a6..ae416e1 100644 --- a/.github/workflows/rhino-issue.yml +++ b/.github/workflows/rhino-issue.yml @@ -17,8 +17,32 @@ jobs: permissions: issues: write steps: + - name: Check for existing open issue + id: check_for_existing_open_issue + run: | + # get the date 21 days ago to limit issues returned to allow a broken builds issue to + # be unresolved for up to 3 weeks + SINCE=$(date -d "-21 days" '+%Y-%m-%d') + # https://docs.github.com/en/rest/issues/issues?apiVersion=2022-11-28#list-repository-issues + RESP_CODE=$(curl -w %{http_code} -s -L -o __response.json \ + -X GET \ + -H "Accept: application/vnd.github+json" \ + -H "Authorization: Bearer ${{ github.token }}" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + https://api.github.com/repos/$GITHUB_REPOSITORY/issues?state=open\&since=$SINCE + ) + # use jq to find github issues with the title "Broken builds and merge-ups" + ISSUE_NUMBER=$(jq -r '.[] | select(.title == "Broken builds and merge-ups") | .id' __response.json) + if [[ "$ISSUE_NUMBER" == "" ]]; then + echo "Did not find an open issue with the title 'Broken builds and merge-ups'" + echo "has_issue=false" >> $GITHUB_OUTPUT + else + echo "Found an open issue with the title 'Broken builds and merge-ups'" + echo "has_issue=true" >> $GITHUB_OUTPUT + fi - name: Rhino issue uses: silverstripe/gha-issue@v1 + if: steps.check_for_existing_open_issue.outputs.has_issue == 'false' with: title: Broken builds and merge-ups close_existing: true