Skip to content

feat(actions): add open-pr-if-needed composite - #50

Merged
nsheaps merged 2 commits into
mainfrom
feat/open-pr-if-needed
May 29, 2026
Merged

nsheaps merged 2 commits into
mainfrom
feat/open-pr-if-needed

Conversation

@alex-nsheaps

@alex-nsheaps alex-nsheaps Bot commented May 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a new reusable composite action .github/actions/open-pr-if-needed that idempotently opens a pull request between two branches that already exist on the remote. Extracted from the pattern in nsheaps/.github/.github/workflows/sync-repo-settings.yaml (the "try direct push, fall back to PR" idiom) per Nate's review on PR #48.

Why

PR #48 inlines a "create PR if not already open" bash block in sync-main-to-edge.yaml. Nate's review noted this pattern should live in a shared composite action so the idempotency check + workflow-run-link convention are applied consistently across nsheaps workflows.

What's in this PR

  • .github/actions/open-pr-if-needed/action.yml — the composite
    • Inputs: title, body, base, head, repo (defaults to github.repository), token, labels, reviewers
    • Outputs: pr-number, pr-url, result (existing | opened | nodiff)
    • Behaviour:
      1. Skips if an open PR for head -> base already exists.
      2. Appends Workflow run: <server_url>/<repo>/actions/runs/<run_id> to the body (matches the nsheaps self-link convention used in check.yaml).
      3. Tolerates the "no diff between head and base" case as a no-op (result=nodiff) instead of failing the step.
  • .github/actions/open-pr-if-needed/README.md — usage docs + example.

Scope

Pre-condition: both head and base must already exist on the remote. This action does NOT push commits — for the "commit local changes then open PR" pattern, peter-evans/create-pull-request remains the right tool (and is still what sync-repo-settings.yaml uses).

Follow-up

Once this lands, PR #48 will be updated to call nsheaps/github-actions/.github/actions/open-pr-if-needed@main instead of its inline bash block.

Test plan

  • YAML parses (validated locally — python3 -c 'yaml.safe_load(open(...))')
  • CI green on this branch
  • Henry review
  • After merge: PR feat(sync-main-to-edge): open a PR when direct push can't fast-forward #48 follow-up commit swaps inline block for uses: ./.github/actions/open-pr-if-needed, then exercises the path by re-running the sync workflow against a diverged edge branch.

Idempotent "create PR if not already open" composite action, extracted from
the pattern in nsheaps/.github/.github/workflows/sync-repo-settings.yaml
(the "try direct push, fall back to PR" idiom).

Inputs: title, body, base, head, repo, token, labels, reviewers.
Outputs: pr-number, pr-url, result (existing|opened|nodiff).

Body is auto-suffixed with `Workflow run: <server_url>/<repo>/actions/runs/<run_id>`
matching the nsheaps self-link convention (see check.yaml).

Pre-condition: both head and base branches must already exist on remote.
For the "commit local changes + open PR" pattern, peter-evans/create-pull-request
is still the right tool — this action is for branches that already exist on
the remote (e.g. upstream-sync flows).

First consumer: sync-main-to-edge.yaml PR fallback step (PR #48 will be
updated in a follow-up commit once this lands).

Per Nate review on PR #48:
#48 (comment)

Co-Authored-By: Agent Alex Picard <alex-nsheaps[bot]@users.noreply.github.com>
@alex-nsheaps alex-nsheaps Bot added the review/agent-henry assign review to Henry (the AI agent) label May 29, 2026
@nsheaps
nsheaps merged commit 425a049 into main May 29, 2026
2 checks passed
@nsheaps
nsheaps deleted the feat/open-pr-if-needed branch May 29, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review/agent-henry assign review to Henry (the AI agent)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant