Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/CLI_REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6967,6 +6967,7 @@ devops gh api [OPTIONS] <endpoint>
| `--template`, `-t` | `string` | - | Format JSON output using a Go template |
| `--cache` | `boolean` | - | Cache response in-memory for subsequent reads |
| `--cache-ttl` | `float` | `15.0` | Cache TTL in seconds (default 15.0) |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

### `devops gh rate-limit`

Expand All @@ -6981,6 +6982,7 @@ devops gh rate-limit [OPTIONS]
| Option / Flag | Type | Default | Description |
|---|---|---|---|
| `--format`, `-f` | `string` | `table` | Output format type (table, json, yaml, markdown). |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

### `devops gh status`

Expand All @@ -6997,6 +6999,7 @@ devops gh status [OPTIONS]
| `--format`, `-f` | `string` | `table` | Output format type (table, json, yaml, markdown). |
| `--json` | `boolean` | - | Emit structured JSON service status summary |
| `--emit-telemetry` | `boolean` | - | Emit operational service status metrics over OpenTelemetry to Prometheus |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

### `devops gh metrics`

Expand All @@ -7017,6 +7020,7 @@ devops gh metrics [OPTIONS]
| `--format`, `-f` | `string` | `table` | Output format type (table, json, yaml, markdown). |
| `--json` | `boolean` | - | Emit structured JSON metrics report |
| `--emit-telemetry` | `boolean` | - | Emit project and velocity metrics over OpenTelemetry to Prometheus |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

### `devops gh labels`

Expand Down Expand Up @@ -7654,6 +7658,7 @@ devops gh branch-protection audit [OPTIONS]
| `--policy-file`, `-f` | `path` | `.github/branch-protection.yml` | Path to declarative branch protection policy YAML file. |
| `--format` | `string` | `table` | Output format type (table, json, yaml, markdown). |
| `--json` | `boolean` | - | Output findings or metrics as JSON. |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

#### `devops gh branch-protection sync`

Expand Down Expand Up @@ -7709,6 +7714,7 @@ devops gh secrets list [OPTIONS]
| Option / Flag | Type | Default | Description |
|---|---|---|---|
| `--repo`, `-R` | `string` | - | Target repository |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

### `devops gh pr`

Expand Down Expand Up @@ -9744,6 +9750,7 @@ devops status [OPTIONS]
| `--json`, `-j` | `boolean` | - | Output status details in JSON format |
| `--format`, `-f` | `string` | `table` | Output format (table, json, yaml, csv) |
| `--emit-telemetry` | `boolean` | - | Emit operational service status metrics over OpenTelemetry to Prometheus |
| `--dry-run` | `boolean` | - | Preview statuspage requests without HTTP calls |

---

Expand Down
1 change: 1 addition & 0 deletions docs/MCP_TOOLS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ Display GitHub REST and GraphQL API rate limits, quotas, and reset countdowns.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
| `output_format` | `string` | No | `table` | Output format type (table, json, yaml, markdown). |
| `dry_run` | `boolean` | No | `False` | Preview execution plan without mutating external state. |

### `gh_runs_list`

Expand Down
6 changes: 6 additions & 0 deletions docs/commands/gh.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ devops gh api [OPTIONS] <endpoint>
| `--template`, `-t` | `string` | - | Format JSON output using a Go template |
| `--cache` | `boolean` | - | Cache response in-memory for subsequent reads |
| `--cache-ttl` | `float` | `15.0` | Cache TTL in seconds (default 15.0) |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

---

Expand All @@ -44,6 +45,7 @@ devops gh rate-limit [OPTIONS]
| Option / Flag | Type | Default | Description |
|---|---|---|---|
| `--format`, `-f` | `string` | `table` | Output format type (table, json, yaml, markdown). |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

---

Expand All @@ -62,6 +64,7 @@ devops gh status [OPTIONS]
| `--format`, `-f` | `string` | `table` | Output format type (table, json, yaml, markdown). |
| `--json` | `boolean` | - | Emit structured JSON service status summary |
| `--emit-telemetry` | `boolean` | - | Emit operational service status metrics over OpenTelemetry to Prometheus |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

---

Expand All @@ -84,6 +87,7 @@ devops gh metrics [OPTIONS]
| `--format`, `-f` | `string` | `table` | Output format type (table, json, yaml, markdown). |
| `--json` | `boolean` | - | Emit structured JSON metrics report |
| `--emit-telemetry` | `boolean` | - | Emit project and velocity metrics over OpenTelemetry to Prometheus |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

---

Expand Down Expand Up @@ -737,6 +741,7 @@ devops gh branch-protection audit [OPTIONS]
| `--policy-file`, `-f` | `path` | `.github/branch-protection.yml` | Path to declarative branch protection policy YAML file. |
| `--format` | `string` | `table` | Output format type (table, json, yaml, markdown). |
| `--json` | `boolean` | - | Output findings or metrics as JSON. |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

### `devops gh branch-protection sync`

Expand Down Expand Up @@ -794,6 +799,7 @@ devops gh secrets list [OPTIONS]
| Option / Flag | Type | Default | Description |
|---|---|---|---|
| `--repo`, `-R` | `string` | - | Target repository |
| `--dry-run` | `boolean` | - | Preview execution plan without mutating external state. |

---

Expand Down
1 change: 1 addition & 0 deletions docs/commands/status.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ devops status [OPTIONS]
| `--json`, `-j` | `boolean` | - | Output status details in JSON format |
| `--format`, `-f` | `string` | `table` | Output format (table, json, yaml, csv) |
| `--emit-telemetry` | `boolean` | - | Emit operational service status metrics over OpenTelemetry to Prometheus |
| `--dry-run` | `boolean` | - | Preview statuspage requests without HTTP calls |

---
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Design

## Overview

Issue #2237 brings 9 `gh` and `status` commands under the owner dry-run rule. Each command gains `@dry_run_class("request-plan")`, declares `--dry-run` where missing, and outputs an ordered sequence of planned requests without sending external HTTP requests or starting child processes.

## Architecture & Module Flow

```
devops gh api / rate-limit / branch-protection / secrets / metrics / status / status
│
▼
is_dry_run() or --dry-run
│
├── Yes ──► Call request planners (e.g. branch_protection_sync_requests)
│ └── Return tuple of PlannedRequest objects
│ └── Output plan via render_request_plan or emit_serialized JSON
│ └── Exit 0 (zero external network / child processes)
│
└── No ──► Execute real workflow (run_gh, httpx2, etc.)
```

## Detailed Command Plans

1. **`gh api`**:
- Class: `request-plan`.
- Planned request: `PlannedRequest(method=method or "GET", target=f"repos/.../{endpoint}", argv=("gh", "api", ...))` matching arguments.

2. **`gh rate-limit`**:
- Class: `request-plan`.
- Planned request: `planned_gh(["api", "rate_limit"], "rate_limit")`.
- Formats: table plan or JSON structure `{"dry_run": true, "requests": [...]}`.

3. **`gh branch-protection audit`**:
- Class: `request-plan`.
- Planned requests: For each evaluated branch policy, planned GET for `repos/{repo}/branches/{branch}/protection`.

4. **`gh branch-protection sync`**:
- Class: `request-plan`.
- Planned requests: For each branch policy, planned PUT for `repos/{repo}/branches/{branch}/protection` with `--input -` and payload JSON.
- Eliminates external GitHub API calls during dry run.

5. **`gh metrics`**:
- Class: `request-plan`.
- Planned requests:
- `StoreRequests(repo).every_issue()`
- `gh run list --repo ... --limit ...`
- `gh api repos/{repo}/milestones`
- `gh label list --repo ...`
- `gh api repos/{repo}/traffic/popular/referrers`
- `gh api repos/{repo}/traffic/popular/paths`
- `gh api repos/{repo}`

6. **`gh secrets list`**:
- Class: `request-plan`.
- Planned request: `planned_gh(["api", f"repos/{repo}/actions/secrets"], f"repos/{repo}/actions/secrets")`.

7. **`gh secrets sync`**:
- Class: `request-plan`.
- Planned requests:
- `GET repos/{repo}/actions/secrets/public-key`
- For each secret name: `PUT repos/{repo}/actions/secrets/{name}` with sealed payload placeholder.
- Eliminates OS Keyring and Vault calls during dry run.

8. **`gh status`**:
- Class: `request-plan`.
- Planned request: `PlannedRequest(method="GET", target="GitHub Statuspage summary", argv=("curl", CONST_URL_GITHUB_STATUS_SUMMARY))`.

9. **`status`**:
- Class: `request-plan`.
- Planned requests for each target service (`github`, `cloudflare`):
- `PlannedRequest(method="GET", target=..., argv=("curl", ...))`.

## Gaps Fixture

Remove the 9 command keys from `tests/fixtures/dry_run_gaps.json`:
- `gh api`
- `gh branch-protection audit`
- `gh branch-protection sync`
- `gh metrics`
- `gh rate-limit`
- `gh secrets list`
- `gh secrets sync`
- `gh status`
- `status`
Decreasing remaining gaps from 407 to 398.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Proposal

## Why

Issue #2237: The owner dry-run rule states that a dry run makes no external request. External requests include GitHub API calls, cloud platforms, network endpoints, and child processes that access them. A dry run returns planned requests and the real result type. Currently, 9 `gh api`, `gh rate-limit`, `gh branch-protection`, `gh secrets`, `gh metrics`, `gh status`, and `status` commands do not obey this rule: they make external requests without returning an ordered request plan.

## What Changes

- Add `--dry-run` option where missing and `@dry_run_class("request-plan")` to the 9 external-request commands:
- `gh api`
- `gh branch-protection audit`
- `gh branch-protection sync`
- `gh metrics`
- `gh rate-limit`
- `gh secrets list`
- `gh secrets sync`
- `gh status`
- `status`
- Implement dry-run request builders for these 9 commands returning ordered `PlannedRequest` sequences without making external network or child-process calls.
- Render request plans through `render_request_plan` in CLI output, or return structured dry-run dictionaries when format is JSON.
- Remove all 9 commands from `tests/fixtures/dry_run_gaps.json`.
- Add test coverage in `tests/github/test_gh_api_status_branch_protection_secrets_dry_run.py` verifying request-plan accuracy, absence of external requests, and structured JSON output.

## Capabilities

### New Capabilities

None.

### Modified Capabilities

- `command-dry-run-class`: add dry-run request plans and classifications for 9 `gh api`, `gh rate-limit`, `gh branch-protection`, `gh secrets`, `gh metrics`, `gh status`, and `status` commands.

## Impact

- Users and agents running `devops <command> --dry-run` or `devops --dry-run <command>` on these 9 commands inspect planned requests safely.
- No network requests or child processes execute during dry-run mode.
- All 9 commands pass the ratchet invariant test.

## Feasibility

- Premise confirmed: all 9 commands exist in the codebase and are listed in `tests/fixtures/dry_run_gaps.json`.
- `PlannedRequest` and `render_request_plan` exist and handle formatting and structured output.
- All tests obey the test floor with no real subprocess or network access.

## Existing Tool Considered

Reuses existing `PlannedRequest` and `render_request_plan` primitives from `devops_cli.dry_run.requests` and `devops_cli.roadmap.request_plan`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# command-dry-run-class Specification

## ADDED Requirements

### Requirement: gh-api-status-branch-protection-secrets-request-plans
The nine external-request commands in `gh api`, `gh branch-protection audit`, `gh branch-protection sync`, `gh metrics`, `gh rate-limit`, `gh secrets list`, `gh secrets sync`, `gh status`, and `status` SHALL carry the `request-plan` dry-run class. Each command SHALL expose `--dry-run`, make zero external requests during a dry run, and output its planned requests.

#### Scenario: Dry run on gh api
- **WHEN** user executes `devops gh api repos/:owner/:repo/issues --dry-run`
- **THEN** no external request is made and the planned api request is printed

#### Scenario: Dry run on gh rate-limit
- **WHEN** user executes `devops gh rate-limit --dry-run`
- **THEN** no external request is made and the planned rate_limit request is printed

#### Scenario: Dry run on gh branch-protection sync
- **WHEN** user executes `devops gh branch-protection sync --dry-run`
- **THEN** no external request is made, no remote branch protection is fetched, and planned protection requests are printed

#### Scenario: Dry run on gh secrets sync
- **WHEN** user executes `devops gh secrets sync -n TOKEN --dry-run`
- **THEN** no external request is made, OS Keyring and Vault are not accessed, and planned secret upload requests are printed

#### Scenario: Dry run on status
- **WHEN** user executes `devops status --dry-run`
- **THEN** no external HTTP request is made and planned statuspage requests are printed
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Tasks

## Implementation Tasks

- [x] 1. Add failing tests in `tests/github/test_gh_api_status_branch_protection_secrets_dry_run.py` verifying dry run output and zero external calls for all 9 commands.
- [x] 2. Update `src/devops_cli/github/branch_protection.py` and `src/devops_cli/github/secrets.py` to add request planning builders.
- [x] 3. Update `src/devops_cli/github/metrics.py` and `src/devops_cli/telemetry/service_status.py` to add request planning builders.
- [x] 4. Wire `@dry_run_class("request-plan")`, `--dry-run` options, and request plan previews in `src/devops_cli/commands/gh.py` and `src/devops_cli/commands/status_cmd.py`.
- [x] 5. Remove the 9 command keys from `tests/fixtures/dry_run_gaps.json` and keep list sorted.
- [x] 6. Regenerate documentation with `uv run devops docs generate --sync-readme`.
- [x] 7. Verify all unit tests, ratchet invariant tests, and diff coverage >= 90%.
- [x] 8. Archive OpenSpec change folder with `uv run devops openspec archive 2237-gh-api-status-branch-protection-secrets`.
23 changes: 23 additions & 0 deletions openspec/specs/command-dry-run-class/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,26 @@ The 16 external-request commands in `gh issues`, `gh labels`, `gh milestones`, `
#### Scenario: Dry run on survey
- **WHEN** user executes `devops survey --dry-run`
- **THEN** no external request is made and the planned survey requests are printed

### Requirement: gh-api-status-branch-protection-secrets-request-plans
The nine external-request commands in `gh api`, `gh branch-protection audit`, `gh branch-protection sync`, `gh metrics`, `gh rate-limit`, `gh secrets list`, `gh secrets sync`, `gh status`, and `status` SHALL carry the `request-plan` dry-run class. Each command SHALL expose `--dry-run`, make zero external requests during a dry run, and output its planned requests.

#### Scenario: Dry run on gh api
- **WHEN** user executes `devops gh api repos/:owner/:repo/issues --dry-run`
- **THEN** no external request is made and the planned api request is printed

#### Scenario: Dry run on gh rate-limit
- **WHEN** user executes `devops gh rate-limit --dry-run`
- **THEN** no external request is made and the planned rate_limit request is printed

#### Scenario: Dry run on gh branch-protection sync
- **WHEN** user executes `devops gh branch-protection sync --dry-run`
- **THEN** no external request is made, no remote branch protection is fetched, and planned protection requests are printed

#### Scenario: Dry run on gh secrets sync
- **WHEN** user executes `devops gh secrets sync -n TOKEN --dry-run`
- **THEN** no external request is made, OS Keyring and Vault are not accessed, and planned secret upload requests are printed

#### Scenario: Dry run on status
- **WHEN** user executes `devops status --dry-run`
- **THEN** no external HTTP request is made and planned statuspage requests are printed
Loading