---
name: Close Stale Discussions

'on':
  schedule:
    - cron: '0 0 * * 1'
  workflow_dispatch:
    inputs:
      days-before-close:
        description: 'days-before-close: number of days of inactivity before closing a discussion'
        required: false
        default: '0'
        type: string
      dry-run:
        description: 'dry-run: when checked, no discussions will be closed'
        default: true
        type: boolean

permissions:
  discussions: write

jobs:
  close-stale-discussions:
    runs-on: ubuntu-latest
    steps:
      - name: resolve-answered
        uses: zenoprax/stalesweeper@c9c72ef0504f835bf9bf8ed7319d3bc149539291 # v1.1.2
        env:
          DAYS_BEFORE_CLOSE: ${{ github.event_name == 'schedule' && '90' || github.event.inputs.days-before-close }}
          DRY_RUN: ${{ github.event_name == 'schedule' && 'false' || github.event.inputs.dry-run }}
        with:
          categories: 'Q&A,General'
          close-reason: 'RESOLVED'
          days-before-close: '${{ env.DAYS_BEFORE_CLOSE}}'
          dry-run: ${{ env.DRY_RUN }}
          message: >-
            This discussion was automatically closed because it is answered and has had no further activity in ${{ env.DAYS_BEFORE_CLOSE}} days.
            If the topic is still relevant, please start a new discussion.
      - name: close-unanswered
        uses: zenoprax/stalesweeper@c9c72ef0504f835bf9bf8ed7319d3bc149539291 # v1.1.2
        env:
          DAYS_BEFORE_CLOSE: ${{ github.event_name == 'schedule' && '180' || github.event.inputs.days-before-close }}
          DRY_RUN: ${{ github.event_name == 'schedule' && 'false' || github.event.inputs.dry-run }}
        with:
          close-reason: 'OUTDATED'
          close-unanswered: 'true'
          days-before-close: '${{ env.DAYS_BEFORE_CLOSE}}'
          dry-run: ${{ env.DRY_RUN }}
          exempt-labels: 'documentation gap'
          message: >-
            This discussion was automatically closed because it has been inactive for ${{ env.DAYS_BEFORE_CLOSE}} days.
            If the topic is still relevant, please reference this in a new discussion with more context or detail.
