# =ci [owner/repo]: failing and recent GitHub Actions runs, via the `gh` CLI.
# Network call to GitHub through gh (runs as you, stores no token). Failing runs
# sort first. With no repo typed, Bolt picks the most recently committed repo with a
# GitHub remote among your project folders and names it in the first row.
#
# Sample data: `=ci demo` always shows a fabricated set of runs so you can see
# the layout without gh. When you typed no repo and nothing real can run (gh not
# installed or not signed in, no project folders, or no repo with a GitHub remote in them), the list opens with a "Try with
# sample data" row followed by the same fabricated runs. Every sample row says
# SAMPLE DATA in its subtitle, its Data field and its detail pane. A typed repo
# that fails gets an honest error row, never sample data. If gh answers, only
# real runs are shown.
#
# There is deliberately no top-level `detect:` gate: a gate would hide the chip
# whenever gh is missing, and then the sample-data offer could never be reached.
schema_version: 1
runtime: bridge
id: ci
chip: ci
title: CI runs
icon: git-pull-request
description: "Network call: failing and recent GitHub Actions runs. Enter = your most recently committed repo with a GitHub remote, or type owner/repo. =ci demo shows sample data"
placeholder_examples:
  - "cli/cli"
  - "owner/repo"
  - "demo"
emits: Document

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

dispatch:
  confirm_label: 'List CI runs: {{query}}'
  confirm_hint: "Press Enter to run · empty uses your latest-committed GitHub repo (named in the first row) · demo shows sample data"

bridge:
  command:
    macos: "python3 {{scripts_dir}}/bolt-ci.py {{repo}}"
    linux: "python3 {{scripts_dir}}/bolt-ci.py {{repo}}"
    windows: "python {{scripts_dir}}/bolt-ci.py {{repo}}"
  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: 28

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.detail}}"
      fields:
        - { label: Status, value: "{{row.status}}", kind: badge }
        - { label: Workflow, value: "{{row.workflow}}" }
        - { label: Branch, value: "{{row.branch}}", kind: branch }
        - { label: Event, value: "{{row.event}}" }
        - { label: Age, value: "{{row.age}}" }
        - { 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 run, url_template: "{{row.url}}", primary: true }
  - { id: copy, kind: composer, target: row, label: Copy title, insert: "{{title}}" }
  - { id: copy-url, kind: composer, target: row, label: Copy URL, insert: "{{row.url}}" }
