name: Stale

# yamllint disable-line rule:truthy
on:
  schedule:
    - cron: "0 * * * *"
  workflow_dispatch:

jobs:
  stale:
    if: github.repository_owner == 'home-assistant'
    runs-on: ubuntu-latest
    steps:
      # The 90 day stale policy
      # Used for:
      # - Issues & PRs
      # - No PRs marked as no-stale
      # - No issues marked as no-stale or help-wanted
      - name: 90 days stale issues & PRs policy
        uses: actions/stale@v5
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          days-before-stale: 90
          days-before-close: 7
          operations-per-run: 150
          remove-stale-when-updated: true
          stale-issue-label: "stale"
          exempt-issue-labels: "no-stale,help-wanted"
          stale-issue-message: >
            There hasn't been any activity on this issue recently. Due to the
            high number of incoming GitHub notifications, we have to clean some
            of the old issues, as many of them have already been resolved with
            the latest updates.

            Please make sure to update to the latest Home Assistant version and
            check if that solves the issue. Let us know if that works for you by
            adding a comment 👍

            This issue has now been marked as stale and will be closed if no
            further activity occurs. Thank you for your contributions.

          stale-pr-label: "stale"
          exempt-pr-labels: "no-stale"
          stale-pr-message: >
            There hasn't been any activity on this pull request recently. This
            pull request has been automatically marked as stale because of that
            and will be closed if no further activity occurs within 7 days.

            Thank you for your contributions.

      # The 30 day stale policy for PRS
      # Used for:
      # - PRs
      # - No PRs marked as no-stale or new-integrations
      # - No issues (-1)
      - name: 30 days stale PRs policy
        uses: actions/stale@v5
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          days-before-stale: 30
          days-before-close: 7
          days-before-issue-close: -1
          operations-per-run: 50
          remove-stale-when-updated: true
          stale-pr-label: "stale"
          # Exempt new integrations, these often take more time.
          # They will automatically be handled by the 90 day version above.
          exempt-pr-labels: "no-stale,new-integration"
          stale-pr-message: >
            There hasn't been any activity on this pull request recently. This
            pull request has been automatically marked as stale because of that
            and will be closed if no further activity occurs within 7 days.

            Thank you for your contributions.

      # The 30 day stale policy for issues
      # Used for:
      # - Issues that are pending more information (incomplete issues)
      # - No Issues marked as no-stale or help-wanted
      # - No PRs (-1)
      - name: Needs more information stale issues policy
        uses: actions/stale@v5
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          only-labels: "needs-more-information"
          days-before-stale: 14
          days-before-close: 7
          days-before-pr-close: -1
          operations-per-run: 50
          remove-stale-when-updated: true
          stale-issue-label: "stale"
          exempt-issue-labels: "no-stale,help-wanted"
          stale-issue-message: >
            There hasn't been any activity on this issue recently. Due to the
            high number of incoming GitHub notifications, we have to clean some
            of the old issues, as many of them have already been resolved with
            the latest updates.

            Please make sure to update to the latest Home Assistant version and
            check if that solves the issue. Let us know if that works for you by
            adding a comment 👍

            This issue has now been marked as stale and will be closed if no
            further activity occurs. Thank you for your contributions.
