Skip to content
Latchkey

Close unknown-effort PRs workflow (stylelint/stylelint)

The Close unknown-effort PRs workflow from stylelint/stylelint, explained and optimized by Latchkey.

A

CI health: A - excellent

Run this on Latchkey for self-healing, caching, and up to 58% lower cost.

Grade your own workflow free or run it on Latchkey →
Source: stylelint/stylelint.github/workflows/close-unknown-effort-prs.ymlLicense MITView source

What it does

This is the Close unknown-effort PRs workflow from the stylelint/stylelint repository, a real project running GitHub Actions. It is shown here with attribution under its MIT license.

Below, Latchkey shows a faster, safer version produced by its optimization engine.

The workflow

workflow (.yml)
name: Close unknown-effort PRs

on:
  pull_request_target:
    types: [labeled]
  schedule:
    - cron: '0 0 * * *' # Every day at 00:00 UTC
  workflow_dispatch:

jobs:
  comment:
    runs-on: ubuntu-slim
    if: >-
      github.repository == 'stylelint/stylelint' &&
      github.event_name == 'pull_request_target' &&
      github.event.label.name == 'pr: unknown-effort'
    permissions:
      pull-requests: write
    steps:
      - name: Comment on unknown-effort PR
        run: gh pr comment "${PR_URL}" --body "${PR_COMMENT}"
        env:
          GH_REPO: ${{ github.repository }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PR_URL: ${{ github.event.pull_request.html_url }}
          PR_COMMENT: |-
            @${{ github.event.pull_request.user.login }} Thank you for your pull request. However, it does not follow our [contributing guide](https://stylelint.io/CONTRIBUTING).

            Please confirm that you:

            - have read the guide
            - can converse in English

            You're welcome to use an LLM to translate from your own language, but don't use one to fill in templates or respond to review comments.

            This pull request will automatically close if there is no activity within 2 days.

  close:
    runs-on: ubuntu-slim
    if: >-
      github.repository == 'stylelint/stylelint' &&
      github.event_name != 'pull_request_target'
    permissions:
      pull-requests: write
    steps:
      - name: Close stale unknown-effort PRs
        run: |
          two_days_ago=$(date --date '2 days ago' '+%Y-%m-%d')

          # For the search syntax, see https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests
          old_pr_urls=$(gh pr list \
            --search "is:open updated:<${two_days_ago} label:\"pr: unknown-effort\"" \
            --json 'url' \
            --jq '.[] | .url')

          for url in ${old_pr_urls}; do
            gh pr close "${url}"
          done
        env:
          GH_REPO: ${{ github.repository }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

The same workflow, on Latchkey

Removes redundant runs and caps runaway jobs. Added and changed lines are highlighted.

name: Close unknown-effort PRs
 
on:
  pull_request_target:
    types: [labeled]
  schedule:
    - cron: '0 0 * * *' # Every day at 00:00 UTC
  workflow_dispatch:
 
jobs:
  comment:
    timeout-minutes: 30
    runs-on: ubuntu-slim
    if: >-
      github.repository == 'stylelint/stylelint' &&
      github.event_name == 'pull_request_target' &&
      github.event.label.name == 'pr: unknown-effort'
    permissions:
      pull-requests: write
    steps:
      - name: Comment on unknown-effort PR
        run: gh pr comment "${PR_URL}" --body "${PR_COMMENT}"
        env:
          GH_REPO: ${{ github.repository }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          PR_URL: ${{ github.event.pull_request.html_url }}
          PR_COMMENT: |-
            @${{ github.event.pull_request.user.login }} Thank you for your pull request. However, it does not follow our [contributing guide](https://stylelint.io/CONTRIBUTING).
 
            Please confirm that you:
 
            - have read the guide
            - can converse in English
 
            You're welcome to use an LLM to translate from your own language, but don't use one to fill in templates or respond to review comments.
 
            This pull request will automatically close if there is no activity within 2 days.
 
  close:
    timeout-minutes: 30
    runs-on: ubuntu-slim
    if: >-
      github.repository == 'stylelint/stylelint' &&
      github.event_name != 'pull_request_target'
    permissions:
      pull-requests: write
    steps:
      - name: Close stale unknown-effort PRs
        run: |
          two_days_ago=$(date --date '2 days ago' '+%Y-%m-%d')
 
          # For the search syntax, see https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests
          old_pr_urls=$(gh pr list \
            --search "is:open updated:<${two_days_ago} label:\"pr: unknown-effort\"" \
            --json 'url' \
            --jq '.[] | .url')
 
          for url in ${old_pr_urls}; do
            gh pr close "${url}"
          done
        env:
          GH_REPO: ${{ github.repository }}
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
 

What changed

This workflow runs 2 jobs per trigger. On Latchkey the same minutes cost up to 58% less than GitHub-hosted, with zero queue time.