Apply suggested changes

This commit is contained in:
Rodrigo Q. Saramago 2022-11-26 01:40:56 +01:00
parent a257fddf24
commit cf85b0e5e1
No known key found for this signature in database
GPG Key ID: 9B36B2525704A359
3 changed files with 56 additions and 47 deletions

View File

@ -1,15 +1,16 @@
name: Query issues using GraphQL API name: Query issues using GraphQL API
inputs: inputs:
token: github_token:
description: 'The GITHUB_TOKEN secret' description: 'GitHub API token'
required: true required: true
query: filter:
description: "The GraphQL search query to be executed" # Filter syntax: https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests
description: "The search filter for issues."
required: true required: true
type: string type: string
outputs: outputs:
query_result: query_result:
description: "The result of the query" description: "The result of the query (JSON)"
value: ${{ steps.get_issues.outputs.query_result }} value: ${{ steps.get_issues.outputs.query_result }}
runs: runs:
@ -18,23 +19,25 @@ runs:
- id: get_issues - id: get_issues
shell: bash shell: bash
env: env:
GH_TOKEN: ${{ inputs.token }} GH_TOKEN: ${{ inputs.github_token }}
run: | run: |
result="$(gh api graphql \ result="$(
--field search_query="${{ inputs.query }}" \ gh api graphql \
--raw-field query=' --field search_query="${{ inputs.query }}" \
query($search_query: String!, $cursor: String) { --raw-field query='
search(first: 100, query: $search_query, type: ISSUE, after: $cursor) { query($search_query: String!, $cursor: String) {
pageInfo { search(first: 100, query: $search_query, type: ISSUE, after: $cursor) {
hasNextPage, pageInfo {
endCursor hasNextPage,
} endCursor
nodes { }
... on Issue { nodes {
title ... on Issue {
url title
url
}
} }
} }
} }'
}')" )"
echo "query_result=$result" >> $GITHUB_OUTPUT echo "query_result=$result" >> $GITHUB_OUTPUT

View File

@ -1,13 +1,12 @@
name: Filter stale issues name: Find stale issues
inputs: inputs:
token: github_token:
description: 'The GITHUB_TOKEN secret' description: 'GitHub API token'
required: true required: true
period: inactivity_period:
description: "The stale period in days" description: "The inactivity period in days"
required: false required: false
type: number type: number
default: 14
repo: repo:
description: "The target repository" description: "The target repository"
required: false required: false
@ -15,35 +14,38 @@ inputs:
default: "${{ github.repository_owner }}/${{ github.event.repository.name }}" default: "${{ github.repository_owner }}/${{ github.event.repository.name }}"
outputs: outputs:
result: result:
description: "The result of the query" description: "List of issue URLs. The list is in a format suitable for iteration with a shell loop, i.e. escaped and separated with whitespace."
value: ${{ steps.found_issues.outputs.result }} value: ${{ steps.found_issues.outputs.result }}
runs: runs:
using: "composite" using: "composite"
steps: steps:
- name: Get period date - name: Get a concrete cut-off date matching the inactivity period
id: date id: date
shell: bash shell: bash
run: | run: |
period_date=$(date --date "${{ inputs.period }} days ago" --utc +"%Y-%m-%dT%H:%M:%SZ") inactivity_period_date=$(date --date "${{ inputs.inactivity_period }} days ago" --utc +"%Y-%m-%dT%H:%M:%SZ")
echo "period=$period_date" >> $GITHUB_OUTPUT echo "inactivity_period=$inactivity_period_date" >> $GITHUB_OUTPUT
- name: Get inactive open issues - name: Get inactive open issues
id: stale_issues id: stale_issues
if: ${{ success() }} if: ${{ success() }}
uses: ethereum/solidity/.github/actions/query_issues@develop uses: ethereum/solidity/.github/actions/query_issues@develop
with: with:
token: ${{ inputs.token }} github_token: ${{ inputs.github_token }}
query: 'repo:${{ inputs.repo }} is:issue is:open updated:<${{ steps.date.outputs.period }}' query: 'repo:${{ inputs.repo }} is:issue is:open updated:<${{ steps.date.outputs.inactivity_period }}'
- name: Collect query result - name: Collect query result
id: found_issues id: found_issues
if: ${{ success() }} if: ${{ success() }}
shell: bash shell: bash
run: | run: |
filter_result=$( filter_result=$(
jq --raw-output \ jq \
--null-input \ --raw-output \
--argjson result '${{ steps.stale_issues.outputs.query_result }}' \ --null-input \
'[$result.data.search.nodes[].url] | @sh' \ --argjson result '${{ steps.stale_issues.outputs.query_result }}' \
| tr --delete \' '[$result.data.search.nodes[].url] | @sh' \
| tr --delete \'
) )
echo "result=$filter_result" >> $GITHUB_OUTPUT echo "result=$filter_result" >> $GITHUB_OUTPUT

View File

@ -1,4 +1,4 @@
name: Check stale issues name: Ping and close stale issues
on: on:
workflow_dispatch: # FIXME: remove workflow_dispatch: # FIXME: remove
@ -6,8 +6,8 @@ on:
- cron: '0 12 * * *' - cron: '0 12 * * *'
env: env:
PERIOD: 14 # in days INACTIVITY_PERIOD: 14 # in days
WAIT_FOR_INFO: "waiting for more input" WAIT_FOR_INFO_LABEL: "waiting for more input"
DRY_RUN: true DRY_RUN: true
jobs: jobs:
@ -16,12 +16,14 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Get inactive open issues - name: Get inactive open issues
id: stale_issues id: stale_issues
uses: ./.github/actions/stale_issues uses: ./.github/actions/stale_issues
with: with:
token: ${{ secrets.GITHUB_TOKEN }} github_token: ${{ secrets.GITHUB_TOKEN }}
period: ${{ env.PERIOD }} inactivity_period: ${{ env.INACTIVITY_PERIOD }}
- name: Comment on found issues - name: Comment on found issues
if: ${{ success() }} if: ${{ success() }}
env: env:
@ -29,10 +31,12 @@ jobs:
run: | run: |
for issue_url in ${{ steps.stale_issues.outputs.result }}; do for issue_url in ${{ steps.stale_issues.outputs.result }}; do
# Filter stale issues that were triaged and are not waiting for more information # Filter stale issues that were triaged and are not waiting for more information
stale_triaged=$(gh issue view $issue_url \ is_stale=$(
--json labels \ gh issue view $issue_url \
--jq '.labels | map(.name != "$WAIT_FOR_INFO") | all and length > 0') --json labels \
if [[ $stale_triaged == 'true' ]]; then --jq '.labels | map(.name != "$WAIT_FOR_INFO_LABEL") | all and length > 0'
)
if [[ $is_stale == 'true' ]]; then
if [[ $DRY_RUN == 'true' ]]; then if [[ $DRY_RUN == 'true' ]]; then
echo "Commenting on issue: $issue_url" echo "Commenting on issue: $issue_url"
else else