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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
schema: spec-driven
created: 2026-11-25
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Design

## Decisions
- Add `declared_labels_for_refs(store, *, ref, head)` in `src/devops_cli/roadmap/pull_labels.py` and call it from both `read_title_labels` and `declared_label_set`, catching only `GitHubFileNotFoundError` when a second ref exists and propagating YAML, schema, and API errors immediately.
- Add optional keyword `labels_source: str | None = None` to `title_problems` so one `form_title_scope` message renders checkout mode (`.github/labels.yml`), `--repo` only (`.github/labels.yml on <base>`), and `--repo` + `--head` (`.github/labels.yml on <base> or <head>`) without duplicating message strings.
- Pass `head=head if repo is not None else None` through `_form_checked`, `_finish_created_pr`, `_labels_recorded`, and `_plan_title_labels`, and share label request planning via `plan_pr_title_labels` in `src/devops_cli/github/pr_plans.py`.

## Rejected alternatives
- Reword the `--repo` refusal without reading `head`: refuses valid cross-repo pull requests that add a new scope label on their branch.
- Duplicate `form_title_scope` into separate message fields: creates drift between modes.
- Swallow all `GitHubOperationError` exceptions when reading `head`: hides invalid YAML or API failures.

## Security
No new trust boundary, secret, or permission scope. Only reads `.github/labels.yml` from user-specified `--base` and `--head` refs via the existing `RoadmapStore.repository_file` API and propagates non-not-found errors explicitly.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Proposal: #6469

## Why
`devops pr create --repo OWNER/NAME --head BRANCH` previously checked the title scope against `.github/labels.yml` on the base branch only, so pull requests that add a new scope label on the head branch were refused and received a misleading checkout-only refusal message.

## What Changes
- Read `.github/labels.yml` from both the base ref and the `--head` ref when `--repo` and `--head` are both set, in both the form check and post-create PR labeling, while keeping non-not-found errors fatal if either ref is unreadable.
- Allow either ref to lack `.github/labels.yml` when the other ref declares it, and raise when both refs lack the file.
- Pass the checked ref location (`labels_source`) into `title_problems` so refusal messages name the base ref and `--head` ref when `--repo` + `--head` are set, the base ref only when `--repo` is set without `--head`, and `.github/labels.yml` only in checkout mode.
- Include the `--head` `.github/labels.yml` read in `plan_pr_title_labels` and `plan_pr_create` dry-run request plans when `--repo` and `--head` are set.

## Capabilities

### Modified Capabilities
- `pull-request-form`: Read `.github/labels.yml` from `--head` in addition to `--base` when `--repo` and `--head` are set, and report the checked refs in the scope refusal message.

## Impact
- `src/devops_cli/roadmap/pull_labels.py`, `src/devops_cli/roadmap/pull_describe.py`, `src/devops_cli/roadmap/pull_form.py`, `src/devops_cli/github/pr_plans.py`, and `src/devops_cli/commands/pr.py`
- No external dependency added.

## Feasibility
Confirmed against `src/devops_cli/commands/pr.py`, `src/devops_cli/roadmap/pull_describe.py`, `src/devops_cli/roadmap/pull_labels.py`, and `src/devops_cli/roadmap/pull_form.py`. `InMemoryRoadmapStore.repository_file` and `GitHubStore.repository_file` both accept `ref=head` and raise `GitHubFileNotFoundError` when absent on a single ref.

## Existing Tool Considered
Alternatives check recorded verdict `none`: no external tool reads `.github/labels.yml` at git refs inside `devops pr create`'s own form check. Cost to build in place: ~50 lines across existing PR/roadmap modules plus unit tests (~4,000 tokens, <1h elapsed).
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## MODIFIED Requirements

### Requirement: devops pr create refuses a pull request that breaks the form
Before opening a pull request, `devops pr create` SHALL check `--title`, and `--body` where OpenSpec is active, and exit 1 on any violation. Scope labels SHALL be checked against `.github/labels.yml` on the base branch, plus `--head` when `--repo` and `--head` are set, or the checkout when `--repo` is omitted. Refusals SHALL name the checked refs only when `--repo` is set. Passing pull requests SHALL open as drafts.

#### Scenario: A title and a body in the form
- **WHEN** `devops pr create` is given a title and a body in the form
- **THEN** it sends the create request with `--draft`, and stderr is empty

#### Scenario: A title not in the form
- **WHEN** the title is `A plain title`
- **THEN** the exit status is 1, no create request is sent, and stderr says that the title is not in the form

#### Scenario: Every problem at once
- **WHEN** the title is `feat(zzz)!: ` followed by 61 characters and the body is empty
- **THEN** stderr names the `!`, the scope `zzz`, the limit 60, the missing `Closes` line and the missing `Change:` line

#### Scenario: A body that is not given
- **WHEN** `devops pr create` is given a title in the form and no body, in a repository with `openspec/config.yaml`
- **THEN** the exit status is 1 and no create request is sent

#### Scenario: The base branch declares fewer scopes
- **WHEN** the labels file on `--base` does not declare `scope/pr`
- **THEN** the exit status is 1, no create request is sent, and stderr names `scope/pr` and `--base`

#### Scenario: A label declared only on the head ref with --repo
- **WHEN** `--repo` and `--head` are both set, the base ref declares no `scope/tools` label, and the head ref declares it
- **THEN** `devops pr create` accepts the title, opens the draft, and applies `scope/tools` to the pull request

#### Scenario: A label declared only on the base ref with --head
- **WHEN** `--repo` and `--head` are both set, the base ref declares `scope/pr`, and the head ref declares no `scope/pr` label
- **THEN** `devops pr create` accepts the title and opens the draft

#### Scenario: Neither ref declares the scope label with --repo and --head
- **WHEN** `--repo` and `--head` are both set, and neither the base ref nor the head ref declares `scope/tools`
- **THEN** the exit status is 1, no create request is sent, and stderr names the base ref, `--head`, and the instruction to declare the label in the same pull request

#### Scenario: Only the base ref is read with --repo and no --head
- **WHEN** `--repo` is set without `--head`, and the base ref declares no `scope/tools` label
- **THEN** the exit status is 1, no create request is sent, and stderr names only the base ref

#### Scenario: A scope that only the checkout declares
- **WHEN** `--repo` is not given, the checkout declares `scope/newscope` and the base branch does not
- **THEN** a title with the scope `newscope` passes the check and the pull request opens

#### Scenario: The check-out mode keeps its message on refusal
- **WHEN** `--repo` is not given and `.github/labels.yml` does not declare `scope/tools`
- **THEN** the exit status is 1, no create request is sent, and stderr prints `.github/labels.yml does not declare \`scope/tools\`` with the instruction to declare the label in the same pull request

#### Scenario: A labels file that cannot be read
- **WHEN** the base branch has no `.github/labels.yml` (and `--head` also lacks it when set)
- **THEN** the exit status is 1, no create request is sent, and stderr names `.github/labels.yml`

#### Scenario: A refused pull request does not reach the fallback
- **WHEN** the title is `A plain title`
- **THEN** the REST fallback is not called
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Tasks

## 1. Behavior

- [x] 1.1 Add failing tests covering head-only scope labels, base-only scope labels with `--head`, ref-qualified scope refusal messages across `--repo`+`--head`, `--repo` without `--head`, checkout mode, post-create labeling from `--head`, malformed head `labels.yml`, and dry-run plans
- Verification: `$ .venv/bin/pytest -n 0 tests/commands/test_pr_form_check.py tests/commands/test_pr_title_labels.py tests/roadmap/test_roadmap_pull_form.py`
- [x] 1.2 Implement `declared_labels_for_refs`, `labels_source` in `title_problems`, `plan_pr_title_labels`, and pass `head` across `_form_checked`, `_labels_recorded`, and `_plan_title_labels`
- Verification: `$ .venv/bin/pytest -n 0 tests/commands/test_pr_form_check.py tests/commands/test_pr_title_labels.py tests/commands/test_pr_other_repository.py tests/commands/test_pr_dry_run.py tests/commands/test_pr_cmd.py tests/commands/test_pr_describe.py tests/roadmap/test_roadmap_pull_form.py`

## 2. Documents

- [x] 2.1 Update `pull-request-form` spec and OpenSpec artifacts
- Verification: `$ .venv/bin/devops openspec check`
26 changes: 23 additions & 3 deletions openspec/specs/pull-request-form/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ The builders of the title and the body SHALL return the text as given, or raise
- **THEN** the exit status is 1 and stderr says that the issue is no item

### Requirement: devops pr create refuses a pull request that breaks the form
Before it sends the create request, `devops pr create` SHALL check `--title`, and `--body` in a repository with OpenSpec, with these rules. When there is a problem, it SHALL print every problem to stderr, exit 1, and open nothing, by `gh` or by the REST fallback. It SHALL check the scope against the labels file on the base branch and, without `--repo`, also against that of the checkout. A pull request that passes SHALL open as a draft, and the command SHALL have no option for another state.
Before opening a pull request, `devops pr create` SHALL check `--title`, and `--body` where OpenSpec is active, and exit 1 on any violation. Scope labels SHALL be checked against `.github/labels.yml` on the base branch, plus `--head` when `--repo` and `--head` are set, or the checkout when `--repo` is omitted. Refusals SHALL name the checked refs only when `--repo` is set. Passing pull requests SHALL open as drafts.

#### Scenario: A title and a body in the form
- **WHEN** `devops pr create` is given a title and a body in the form
Expand All @@ -199,14 +199,34 @@ Before it sends the create request, `devops pr create` SHALL check `--title`, an

#### Scenario: The base branch declares fewer scopes
- **WHEN** the labels file on `--base` does not declare `scope/pr`
- **THEN** the exit status is 1, no create request is sent, and stderr names `scope/pr`
- **THEN** the exit status is 1, no create request is sent, and stderr names `scope/pr` and `--base`

#### Scenario: A label declared only on the head ref with --repo
- **WHEN** `--repo` and `--head` are both set, the base ref declares no `scope/tools` label, and the head ref declares it
- **THEN** `devops pr create` accepts the title, opens the draft, and applies `scope/tools` to the pull request

#### Scenario: A label declared only on the base ref with --head
- **WHEN** `--repo` and `--head` are both set, the base ref declares `scope/pr`, and the head ref declares no `scope/pr` label
- **THEN** `devops pr create` accepts the title and opens the draft

#### Scenario: Neither ref declares the scope label with --repo and --head
- **WHEN** `--repo` and `--head` are both set, and neither the base ref nor the head ref declares `scope/tools`
- **THEN** the exit status is 1, no create request is sent, and stderr names the base ref, `--head`, and the instruction to declare the label in the same pull request

#### Scenario: Only the base ref is read with --repo and no --head
- **WHEN** `--repo` is set without `--head`, and the base ref declares no `scope/tools` label
- **THEN** the exit status is 1, no create request is sent, and stderr names only the base ref

#### Scenario: A scope that only the checkout declares
- **WHEN** `--repo` is not given, the checkout declares `scope/newscope` and the base branch does not
- **THEN** a title with the scope `newscope` passes the check and the pull request opens

#### Scenario: The check-out mode keeps its message on refusal
- **WHEN** `--repo` is not given and `.github/labels.yml` does not declare `scope/tools`
- **THEN** the exit status is 1, no create request is sent, and stderr prints `.github/labels.yml does not declare \`scope/tools\`` with the instruction to declare the label in the same pull request

#### Scenario: A labels file that cannot be read
- **WHEN** the base branch has no `.github/labels.yml`
- **WHEN** the base branch has no `.github/labels.yml` (and `--head` also lacks it when set)
- **THEN** the exit status is 1, no create request is sent, and stderr names `.github/labels.yml`

#### Scenario: A refused pull request does not reach the fallback
Expand Down
Loading
Loading