From f082861df8203f6a3d0a247963d69efe0e8cb7bd Mon Sep 17 00:00:00 2001 From: "Rodrigo Q. Saramago" Date: Tue, 25 Oct 2022 19:06:59 -0300 Subject: [PATCH] Add reusable query-issues action --- .../workflows/actions/query-issues/action.yml | 40 +++++++++++++++++++ .github/workflows/report-stale-issues.yml | 37 ++++++++++------- 2 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/actions/query-issues/action.yml diff --git a/.github/workflows/actions/query-issues/action.yml b/.github/workflows/actions/query-issues/action.yml new file mode 100644 index 000000000..7f7ab8942 --- /dev/null +++ b/.github/workflows/actions/query-issues/action.yml @@ -0,0 +1,40 @@ +name: Query issues using GraphQL API +inputs: + token: + description: 'The GITHUB_TOKEN secret' + required: true + query: + description: "The GraphQL search query to be executed" + required: true + type: string +outputs: + query_result: + description: "The result of the query" + value: ${{ steps.get_issues.outputs.query_result }} + +runs: + using: "composite" + steps: + - id: get_issues + shell: bash + env: + GH_TOKEN: ${{ inputs.token }} + run: | + result="$(gh api graphql \ + --field search_query="${{ inputs.query }}" \ + --raw-field query=' + query($search_query: String!, $cursor: String) { + search(first: 100, query: $search_query, type: ISSUE, after: $cursor) { + pageInfo { + hasNextPage, + endCursor + } + nodes { + ... on Issue { + title + url + } + } + } + }')" + echo "query_result=$result" >> $GITHUB_OUTPUT diff --git a/.github/workflows/report-stale-issues.yml b/.github/workflows/report-stale-issues.yml index 94456a202..6af18e07d 100644 --- a/.github/workflows/report-stale-issues.yml +++ b/.github/workflows/report-stale-issues.yml @@ -1,4 +1,4 @@ -name: Report stale triaged issues +name: Report stale issues on: workflow_dispatch: @@ -7,38 +7,47 @@ on: env: PERIOD: 14 # in days - WAIT_FOR_INFO: "waiting for more info" + REPO: "${{ github.repository_owner }}/${{ github.event.repository.name }}" + WAIT_FOR_INFO: "waiting for more input" DRY_RUN: true jobs: - check-status: - name: Retrieve all open issues that are inactive for more than ${{ env.PERIOD }} days + check-issue-status: + name: Retrieve all open issues that are inactive runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2.5.0 - name: Get period date id: date run: | - period_date=$(date -d "${{ env.PERIOD }} days ago" -u +"%Y-%m-%dT%H:%M:%SZ") - echo "::set-output name=period::$period_date" + period_date=$(date -d "$PERIOD days ago" -u +"%Y-%m-%dT%H:%M:%SZ") + echo "period=$period_date" >> $GITHUB_OUTPUT - name: Get inactive open issues if: ${{ success() }} - id: stale-issues - uses: lee-dohm/select-matching-issues@v1 + id: stale_issues + uses: ./.github/actions/query-issues with: token: ${{ secrets.GITHUB_TOKEN }} - query: 'is:issue is:open updated:<${{ steps.date.outputs.period }}' + query: 'repo:${{ env.REPO }} is:issue is:open updated:<${{ steps.date.outputs.period }}' - name: Comment on found issues if: ${{ success() }} env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - for issue_url in $(cat ${{ steps.stale-issues.outputs.path }}); do - # Filter issues that were triaged and are not waiting for more info + query_result=$( + jq --raw-output \ + --null-input \ + --argjson result '${{ steps.stale_issues.outputs.query_result }}' \ + '[$result.data.search.nodes[].url] | @sh' \ + | tr -d \' + ) + for issue_url in $query_result; do + # Filter issues that were triaged and are not waiting for more information stale_triaged=$(gh issue view $issue_url \ --json labels \ - --jq '.labels | map(.name != "${{ env.WAIT_FOR_INFO }}") | all and length > 0') - if [[ "$stale_triaged" == "true" ]]; then - if [[ "${{ env.DRY_RUN }}" == "true" ]]; then + --jq '.labels | map(.name != "$WAIT_FOR_INFO") | all and length > 0') + if [[ $stale_triaged == 'true' ]]; then + if [[ $DRY_RUN == 'true' ]]; then echo "Commenting on issue: $issue_url" else gh issue comment $issue_url --body "Hey, devs! I have been waiting for too long. Please give me some attention! :-)"