# =pr-ready [owner/repo#N | N]: is this PR ready to merge? One GO / NO-GO
# verdict row with reasons, then a row per blocker and per check. Reads the
# PR with `gh pr view`, the CI checks with `gh pr checks --json`, and the
# unresolved review threads with one read-only GraphQL query, all in
# parallel: CI status counts, review decision, requested reviewers, conflict
# state, open threads, size. With nothing typed, Bolt picks the most recently committed repo with a
# GitHub remote among your project folders and checks the PR of its checked-out
# branch, naming the repo in the first row. Type N for another PR in that repo, or owner/repo#N.
# Network call to GitHub through gh (runs as you, stores no token). Read-only.
#
# Sample data: `=pr-ready demo` always shows a fabricated NO-GO check so you can
# see the layout without gh. When you typed nothing and nothing real can run (gh not
# installed or not signed in, no project folders, no repo with a GitHub remote in
# them, or no PR for that repo's checked-out branch), the list
# opens with a "Try with sample data" row followed by the same fabricated rows.
# Every sample row says SAMPLE DATA and carries no URL. A typed PR that fails
# gets an honest error row, never a fabricated verdict. If gh answers, only the
# real verdict is shown.
#
# There is deliberately no top-level `detect:` gate: it would hide the chip
# whenever gh is missing, and then the sample-data offer could not be reached.
schema_version: 1
runtime: bridge
id: pr-ready
chip: pr-ready
title: PR ready check
icon: git-pull-request
description: "Network call: GO or NO-GO for merging one PR: CI, review, conflicts, open threads, size. Enter = the PR of your most recently committed GitHub repo's branch. =pr-ready demo shows sample data"
placeholder_examples:
  - "123"
  - "cli/cli#14783"
  - "demo"
emits: Document

args:
  - { name: pr, from: "query.word(0)", default: "" }

dispatch:
  confirm_label: 'Check PR {{query}}'
  confirm_hint: "Press Enter to check · empty uses the latest-committed GitHub repo's branch PR (named in the first row) · demo shows sample data"

bridge:
  command:
    macos: "python3 {{scripts_dir}}/bolt-pr-ready.py {{pr}}"
    linux: "python3 {{scripts_dir}}/bolt-pr-ready.py {{pr}}"
    windows: "python {{scripts_dir}}/bolt-pr-ready.py {{pr}}"
  parse: json
  env_passthrough: [GH_TOKEN, GITHUB_TOKEN, GH_HOST, GH_ENTERPRISE_TOKEN, GITHUB_ENTERPRISE_TOKEN, GH_CONFIG_DIR, HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY]
  timeout_seconds: 40

presentation:
  widget: list
  title_field: title
  subtitle_field: subtitle
  searchable: true
  right_widget:
    kind: entity_preview
    mode: selected_row
    bind:
      title: "{{row.title}}"
      subtitle: "{{row.repo}} #{{row.number}}"
      fields:
        - { label: State, value: "{{row.status}}", kind: badge }
        - { label: Kind, value: "{{row.kind}}" }
        - { label: Data, value: "{{row.data}}" }
        - { label: URL, value: "{{row.url}}" }
      body: "{{row.body}}"
      actions: [open, copy, copy-url]

actions:
  - { id: open, kind: url, target: row, label: Open PR, url_template: "{{row.url}}", primary: true }
  - { id: copy, kind: composer, target: row, label: Copy text, insert: "{{row.value}}" }
  - { id: copy-url, kind: composer, target: row, label: Copy URL, insert: "{{row.url}}" }
