|
# Seeded by the repo-improver-rotation Cowork job into cowork/improve-* branches. |
|
# Opens a PR automatically when such a branch is pushed (sandbox cannot reach |
|
# the GitHub API directly; this runs server-side with the repo's GITHUB_TOKEN). |
|
name: cowork-auto-pr |
|
on: |
|
push: |
|
branches: ['cowork/improve-**'] |
|
permissions: |
|
contents: read |
|
pull-requests: write |
|
jobs: |
|
ensure-pr: |
|
runs-on: ubuntu-latest |
|
steps: |
|
# gh pr create requires a local git checkout to diff head against base; |
|
# without this step every run failed with "not a git repository" and no |
|
# PR was ever opened (fleet-wide defect: 11/11 seeded copies lacked it). |
|
- name: Check out the pushed branch |
|
uses: actions/checkout@v4 |
|
with: |
|
ref: ${{ github.ref_name }} |
|
fetch-depth: 0 |
|
- name: Open PR for this branch if none exists |
|
env: |
|
GH_TOKEN: ${{ github.token }} |
|
run: | |
|
set -eu |
|
existing=$(gh pr list --repo "$GITHUB_REPOSITORY" --head "$GITHUB_REF_NAME" --state open --json number --jq 'length') |
|
if [ "$existing" = "0" ]; then |
|
gh pr create --repo "$GITHUB_REPOSITORY" \ |
|
--head "$GITHUB_REF_NAME" \ |
|
--title "cowork-bot: automated improvements ($GITHUB_REF_NAME)" \ |
|
--body "Automated improvement PR from the Cowork repo-improver rotation (one coherent senior-dev improvement per run; see individual commit messages). Subsequent runs push additional commits to this PR rather than opening new ones." |
|
else |
|
echo "Open PR already exists for $GITHUB_REF_NAME — nothing to do." |
|
fi |