diff --git a/.claude/skills/update-bundle/SKILL.md b/.claude/skills/update-bundle/SKILL.md new file mode 100644 index 0000000..bac7531 --- /dev/null +++ b/.claude/skills/update-bundle/SKILL.md @@ -0,0 +1,317 @@ +--- +name: update-bundle +description: Release every bundled WP-CLI package that has unreleased changes, then refresh the wp-cli/wp-cli-bundle lockfile and the automated tests until they are green. Use when asked to "update the bundle", cut package releases across the bundle, or refresh the bundle's lock files. Asks the maintainer every milestone question in one go, then gets a single approval before tagging anything. +--- + +# Update the bundle + +Takes the bundle from "packages have unreleased changes" to "every package is +tagged, the bundle lockfile ships those tags, and the automated tests are +green". Stops and hands over to the maintainer when something bigger than a +routine fix turns up. + +Run everything from the root of this `wp-cli-dev` checkout, where any `wp` +executable picks up the `wp maintenance` commands through `wp-cli.yml`. Set +`NO_COLOR=1` for every command whose output you read back. + +The run has four phases. **Nothing is written to GitHub before the +maintainer's answers in phase 2. Nothing is tagged before their approval in +phase 3.** + +1. Survey (read-only) +2. Milestone questions, then milestone changes +3. Release proposal, approval, then tagging +4. Lockfiles and tests: framework, bundle, automated tests + +Keep a running log in a scratch file, such as `update-bundle-state.md` in the +session's scratch or temp folder (not in this repository). Record the answers, +the tags created, and the PRs and workflow runs you are watching. Re-read it +after a context compaction instead of re-asking the maintainer. `$SCRATCH` +below stands for that folder. + +## Phase 1: Survey + +```bash +wp maintenance doctor +wp maintenance release plan --bundle --format=json > "$SCRATCH/plan.json" +``` + +Stop if `doctor` reports a failed check. Stop as well if it reports `gh`, +`jq` or `composer` as missing: `doctor` only warns about them, but this skill +needs all three, and finding out in phase 4 would leave tags without lockfile +updates. The plan takes a few hundred API requests, so the rate limit `doctor` +shows should leave room for that. + +`--bundle` covers every package in the composer.lock of wp-cli/wp-cli-bundle: +the `*-command` packages, plus wp-cli-tests, php-cli-tools, spyc and +wp-config-transformer. The wp-cli/wp-cli framework is not tagged here. The +bundle tracks its `main` branch, see phase 4. + +For each repository, the JSON holds: + +| Field | Meaning | +| --- | --- | +| `status` | `up_to_date`, `ready` (`release.tag` can be generated as is) or `needs_human` | +| `latest_tag` | The tag the default branch is compared against | +| `pull_requests` | Merged since `latest_tag` that call for a release. Leaves out Dependabot and GitHub Actions PRs unless they are on a milestone, and PRs that only touch `.github/`, `README.md`, `AGENTS.md`, `.actrc` or `.editorconfig`. | +| `blockers` | What `needs_human` is about, by `code`, see below | +| `open_items` | Issues/PRs still open on the milestone the unreleased changes are on | +| `open_pull_requests` | Open, non-draft, non-bot PRs that have no open milestone | +| `direct_commits` | Commits pushed without a PR that change more than those development files. `null` when there are too many commits since `latest_tag` for GitHub to compare; check those by hand | +| `open_milestones` | Open milestones that are a version newer than `latest_tag`, lowest first | + +## Phase 2: Milestone questions + +Work out every question first, across all repositories. Then ask them all, +grouped into as few `AskUserQuestion` calls as possible: up to 4 questions +per call and up to 4 options per question, with "Other" always added +automatically. Put the repository and PR numbers in every question, since the +maintainer may see only the dialog. Only start the next call once the previous +one has its answers, and make no change until every question is answered. + +Name the milestones like this: + +- **R**, the release milestone of a repository: `release.milestone` when + `ready`. Otherwise the milestone the unreleased `pull_requests` are on. + Otherwise the lowest of `open_milestones`. Otherwise a new milestone, one + patch version above `latest_tag`. +- **N**, the next milestone after R: the lowest of `open_milestones` above R. + Otherwise a new milestone, one patch version above R. + +Choosing a version is the maintainer's call. Propose the patch bump, and offer +a minor bump as a second option when a merged PR adds a command, a subcommand +or a flag. + +Questions by blocker or field: + +- **`no_milestone`** (merged PRs without one): "Ship #A, #B of `` in R?" + The options are *Put on R* or *Skip this repo's release*. They are merged + already, so a tag ships them either way, and leaving them off R only drops + them from the release notes. +- **`released_milestone`** (merged PRs on a milestone that is closed or tagged + already): the same question. Answering *Put on R* moves them. +- **`open_items`**: "`` R still has #X (open PR, by …) open. Wait for it + or defer it?" The options are *Defer to N and release R now* or *Wait, so + no release of ``*. Mention drafts and issues as such. +- **`several_milestones`**: "The unreleased changes of `` are on X and + Y. Which one should the release be?" The options are each milestone, plus + *Skip*. All the PRs end up on the chosen one. +- **`open_pull_requests`**: one multi-select question per repository, with up + to 4 PRs per question (split longer lists): "Which open PRs of `` + should go on M?" M is N when R is released in this run, and R otherwise. + Leaving a PR unchecked leaves it alone. Open PRs never block a release. +- **`direct_commits`**: "`` has commits pushed without a PR, which R + would ship without mentioning them: ` `. Release anyway?" A + *no* excludes the repository from phase 3, even though its plan stays + `ready`. Record the exclusion in the log. If a repository has direct commits + but no merged PR, `release generate` can't release it. Report it for the + maintainer to handle by hand. +- **`invalid_version`, `no_version_tag`**: no question. List them in the final + report as needing manual attention. + +Then apply the answers. One call puts any number of items on a milestone, and +creates it if needed: + +```bash +wp maintenance milestone assign ... --create +``` + +Then re-run `wp maintenance release plan ... --format=json` for the +repositories you changed. A repository the maintainer wanted released that is +still not `ready` points to a misread answer or a new blocker. Ask about it +instead of working around it. + +## Phase 3: Release proposal and approval + +Every repository that is now `ready` and that the maintainer did not exclude +in phase 2 gets a proposal. Save its plan JSON in the log as the approved +snapshot. Gather all of them +before asking. For each one, preview the notes: + +```bash +wp maintenance release-notes --source=pull-request +``` + +Then show a single overview as a table, with these columns: repository, +`latest_tag` → new tag, number of PRs, a one-line summary of the notes, and +anything notable such as direct commits or deferred items. Below it, list what +phase 4 will do. Then ask for approval in one `AskUserQuestion` call, which +also settles how to merge in phase 4: + +1. "Tag and release these N packages?" *Release all* / *Release all except… + (say which in Other)* / *Cancel*. +2. "The bundle requires a review before merging. How should the lockfile PRs + be merged once green?" *Approve the bot's PR and merge; admin-merge my own* + / *Approve the bot's PR and merge; ask a reviewer for mine* / *Leave all + merges to me*. + +Then release each approved package. Right before each one, re-run +`wp maintenance release plan --format=json` and compare it with the +approved snapshot: the same `latest_tag`, `release`, `pull_requests` and +`direct_commits`. If anything was merged or pushed since, don't tag it. Ask +again about that repository once the others are released. + +```bash +wp maintenance release generate --milestone= --yes +``` + +The command re-checks the plan and skips the release, with a warning, if +anything changed in the meantime. Report every skip. Do not force it. Check +each release afterwards with `gh release view v --repo `. + +Before phase 4, wait until Packagist lists every new version, or Composer +won't find them. It usually takes a minute or two: + +```bash +curl -fsS "https://repo.packagist.org/p2/wp-cli/.json" | jq -r '.packages[][].version' | head -3 +``` + +The package name can differ from the repository: wp-cli/spyc is +`wp-cli/mustangostang-spyc`. If a version is missing after about 15 minutes, +report it to the maintainer. + +## Phase 4: Lockfiles and tests + +Do the steps in this order. Each one updates `composer.lock` of the bundle, +and running them at the same time makes the PRs conflict. + +### 4a. Framework: the "Update wp-cli framework" workflow of the bundle + +The wp-cli/wp-cli repository has no lockfile of its own. Its "lock refresh" is +the `update-framework.yml` workflow of wp-cli/wp-cli-bundle. It runs +`composer update wp-cli/wp-cli --with-all-dependencies`, which also brings in +new releases of php-cli-tools and spyc, and opens or updates the +`update-framework` PR. It runs daily and on every push to the bundle's `main`. + +First note the commit the lockfile should end up with: + +```bash +gh api repos/wp-cli/wp-cli/commits/main --jq .sha +``` + +Then pick a run that started after the last tag from phase 3, active or +finished. If there is none, trigger one: + +```bash +gh run list --repo wp-cli/wp-cli-bundle --workflow update-framework.yml --limit 5 \ + --json databaseId,event,status,conclusion,createdAt +gh workflow run update-framework.yml --repo wp-cli/wp-cli-bundle --ref main +``` + +Either way, wait for that run to finish, and look at nothing else until it +does. A run still in progress may be rewriting the PR. If it fails, read its +log and bring the maintainer in. + +Once it has succeeded, find the PR with `gh pr list --repo +wp-cli/wp-cli-bundle --head update-framework --state open`. Check that its +lockfile pins `wp-cli/wp-cli` at the commit you noted, or main's lockfile +does when there is no PR: + +```bash +gh api "repos/wp-cli/wp-cli-bundle/contents/composer.lock?ref=" \ + --jq '.content | @base64d | fromjson | .packages[] | select(.name == "wp-cli/wp-cli") | .source.reference' +``` + +A run's start time does not prove it saw a commit, since a commit can reach +`main` after the run started even when it is dated earlier. So if the pinned +commit differs, trigger one more run and repeat. No PR, with the commit you +noted on main, means the lockfile was up to date already. Otherwise babysit +the PR, see below. + +### 4b. Bundle: bundled packages in the bundle's composer.lock + +Start this only after the framework PR is merged or turned out to be +unnecessary. Nothing in the bundle updates the bundled packages as a whole on +its own. Dependabot opens one PR per package, and they close themselves once +the lockfile has caught up. Preview, then open the PR: + +```bash +.maintenance/refresh-bundle-lock.sh --dry-run +.maintenance/refresh-bundle-lock.sh +``` + +The script moves only the `wp-cli/*` packages, never the framework or +third-party dependencies, and only touches `composer.lock`. If its +`update-bundled-packages` PR is open already, the script updates that PR and +prints its URL. No output on stdout means the lockfile is up to date already. +Each package should end up on the tag created in phase 3. If one doesn't, +find out why before merging, usually a constraint in the bundle's +`composer.json`. + +If Composer cannot resolve the update, for example because a new release +needs a newer third-party dependency, that is a bigger issue. Stop and report +it. + +### 4c. Automated tests: wp-cli/automated-tests + +Check `config.lock` in its `composer.json` first. + +- **`false`, as is the case today**: there is no lockfile. Every run resolves + the bundle's `dev-main` afresh, so refreshing means running the suite once + the bundle PR is merged: + + ```bash + gh workflow run testing.yml --repo wp-cli/automated-tests --ref main + ``` + + Then babysit that run the way a PR is babysat. It fans out to about 150 jobs + and takes a while. +- **A committed `composer.lock`**: update it on a branch with + `composer update 'wp-cli/*' --no-install`, open a PR, and babysit it. + +## Babysitting a PR or run + +**Waiting.** Use the harness's own facility to watch PRs or wait on background +work if it has one. Otherwise run `gh pr checks --repo --watch`, or +`gh run watch --repo --exit-status`, in the background. Don't +poll in a tight loop. + +**Triaging each failing check.** Read the job log first, with `gh run view + --repo --log-failed`, and classify the failure: + +- **Pre-existing**: the same check fails on the latest run of the default + branch too, so the PR didn't cause it. Example: "Audit locked dependencies" + flagging an advisory in a third-party package. To tell, compare + `wp maintenance dependencies audit --ref=` with a run of the + same command against the default branch. It also shows whether the affected + packages ship in the Phar or are only needed for development. Ask the + maintainer whether to merge anyway. Don't fix it as part of this run. +- **Flaky**: a network timeout, a failed download from WordPress.org or + GitHub, MySQL not starting, a rate limit, or a runner lost mid-job. Re-run + the failed jobs once with `gh run rerun --repo --failed`. A + second identical failure is real. +- **Minor, fix it**: the PR is out of date or conflicts with `main`, which + re-running the workflow or the script fixes. Also small fixes confined to + the PR's own files. Push the fix to the PR branch. +- **Bigger, rope the human in**: a Behat or PHPUnit failure in a package's + behaviour, which may be a regression in a new release, a Composer + resolution failure, an audit failure that would need a third-party update + past the Dependabot cooldown, or anything that needs a code change in + another repository or another release. + + Stop the run there. Report the PR or run link, the failing jobs, a short + log excerpt, the package and PR most likely responsible, and the fixes you + see. Phases that don't depend on the blocked one may go on, but 4a → 4b → + 4c depend on each other. + +**Merging.** Only with every required check green, or with the maintainer's +explicit go-ahead on a pre-existing failure. Follow the merge choice from +phase 3: + +```bash +gh pr review --repo --approve # bot-authored PRs only +gh pr merge --repo --squash # add --admin only for the maintainer's own PRs, if allowed +``` + +Never approve a PR the authenticated account wrote itself. If merging is left +to the maintainer, or a reviewer is needed, say so in the report and wait. + +## Final report + +End with: + +- the releases, with tags and links, and every repository skipped, with the + reason, +- the milestone changes made, +- the PRs merged and the automated-tests run, with links and conclusions, +- anything waiting on the maintainer, and what exactly is needed. diff --git a/.gitignore b/.gitignore index b511fd4..2ef21e7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,15 @@ # Exclude all subfolders... /*/ # except for the following. +!/.claude/ !/.github/ !/.maintenance/ !/.readme-partials/ !/tests/ +# Only the skills of .claude/ are shared. +/.claude/* +!/.claude/skills/ + composer.lock *.log diff --git a/.maintenance/bootstrap.php b/.maintenance/bootstrap.php index fc3868e..6f461b7 100644 --- a/.maintenance/bootstrap.php +++ b/.maintenance/bootstrap.php @@ -9,6 +9,7 @@ WP_CLI::add_command( 'maintenance contrib-list', 'WP_CLI\Maintenance\Contrib_List_Command' ); WP_CLI::add_command( 'maintenance dependencies', 'WP_CLI\Maintenance\Dependencies_Command' ); WP_CLI::add_command( 'maintenance doctor', 'WP_CLI\Maintenance\Doctor_Command' ); +WP_CLI::add_command( 'maintenance milestone', 'WP_CLI\Maintenance\Milestone_Command' ); WP_CLI::add_command( 'maintenance milestones-after', 'WP_CLI\Maintenance\Milestones_After_Command' ); WP_CLI::add_command( 'maintenance milestones-since', 'WP_CLI\Maintenance\Milestones_Since_Command' ); WP_CLI::add_command( 'maintenance release', 'WP_CLI\Maintenance\Release_Command' ); diff --git a/.maintenance/refresh-bundle-lock.sh b/.maintenance/refresh-bundle-lock.sh new file mode 100755 index 0000000..378d271 --- /dev/null +++ b/.maintenance/refresh-bundle-lock.sh @@ -0,0 +1,97 @@ +#!/usr/bin/env bash +# +# Updates the bundled packages in the composer.lock of wp-cli/wp-cli-bundle to +# their latest releases, and opens a pull request with the change, or updates +# the one that is open already: +# +# .maintenance/refresh-bundle-lock.sh [--dry-run] +# +# Only the wp-cli/* packages move, within the constraints of composer.json, and +# only composer.lock changes. The wp-cli/wp-cli framework is left alone, as the +# "Update wp-cli framework" workflow of the bundle takes care of it. So are +# third-party dependencies, which Dependabot updates after a cooldown. +# +# With --dry-run, prints the changes without pushing anything. Prints the URL of +# the pull request otherwise, or nothing when the lockfile is up to date. +# + +set -euo pipefail + +REPO="wp-cli/wp-cli-bundle" +BRANCH="update-bundled-packages" +TITLE="Update bundled packages to their latest releases" + +DRY_RUN=false +case "${1:-}" in + "") ;; + --dry-run) DRY_RUN=true ;; + *) + echo "Usage: refresh-bundle-lock.sh [--dry-run]" >&2 + exit 1 + ;; +esac + +WORKDIR=$(mktemp -d) +trap 'rm -rf "${WORKDIR}"' EXIT + +gh repo clone "${REPO}" "${WORKDIR}/bundle" -- --depth 1 --quiet +cd "${WORKDIR}/bundle" +DEFAULT_BRANCH=$(git rev-parse --abbrev-ref HEAD) +cp composer.lock "${WORKDIR}/before.lock" + +mapfile -t PACKAGES < <( + jq --raw-output '(.packages + ."packages-dev")[].name | select(startswith("wp-cli/") and . != "wp-cli/wp-cli")' composer.lock +) + +echo "Updating ${#PACKAGES[@]} packages in the composer.lock of ${REPO}..." >&2 +COMPOSER_ROOT_VERSION="dev-${DEFAULT_BRANCH}" composer update "${PACKAGES[@]}" \ + --no-install --no-scripts --no-plugins --no-interaction --no-progress >&2 + +if git diff --quiet -- composer.lock; then + echo "The composer.lock of ${REPO} is up to date." >&2 + exit 0 +fi + +# One "- name: old → new" line per package whose version or commit changed. +CHANGES=$( + jq --null-input --raw-output \ + --slurpfile before "${WORKDIR}/before.lock" \ + --slurpfile after composer.lock ' + def versions: (.packages + ."packages-dev") | map({ key: .name, value: (.version + " (" + .source.reference[0:7] + ")") }) | from_entries; + ($before[0] | versions) as $old + | ($after[0] | versions) as $new + | ($old + $new | keys[]) + | select($old[.] != $new[.]) + | "- `\(.)`: \($old[.] // "new") → \($new[.] // "removed")" + ' +) + +echo "${CHANGES}" >&2 + +if [[ "${DRY_RUN}" == true ]]; then + exit 0 +fi + +BODY=$( + cat <<-EOF + Updates \`composer.lock\` so the bundle ships the latest release of every bundled package: + + ${CHANGES} + + Generated with \`.maintenance/refresh-bundle-lock.sh\` from wp-cli/wp-cli-dev. Only \`composer.lock\` changes. + EOF +) + +git checkout --quiet -b "${BRANCH}" +git add composer.lock +git commit --quiet -m "${TITLE}" +git push --quiet --force origin "${BRANCH}" + +PR_NUMBER=$(gh pr list --repo "${REPO}" --head "${BRANCH}" --state open --json number --jq '.[0].number // empty') +if [[ -z "${PR_NUMBER}" ]]; then + gh pr create --repo "${REPO}" --base "${DEFAULT_BRANCH}" --head "${BRANCH}" \ + --title "${TITLE}" --body "${BODY}" --label "scope:distribution" +else + gh pr edit "${PR_NUMBER}" --repo "${REPO}" --title "${TITLE}" --body "${BODY}" >/dev/null + gh pr view "${PR_NUMBER}" --repo "${REPO}" --json url --jq .url +fi diff --git a/.maintenance/src/GitHub.php b/.maintenance/src/GitHub.php index 3813104..bc8d3f1 100644 --- a/.maintenance/src/GitHub.php +++ b/.maintenance/src/GitHub.php @@ -370,13 +370,15 @@ public static function get_tags( $project ) { * @param string $project * @param string $tag Tag to compare the branch against. * @param string $branch Branch the pull requests were merged into. + * @param object|null $comparison Comparison of the tag and the branch, when + * fetched already. * * @return array Pull requests, most recently updated first. */ - public static function get_pull_requests_merged_since( $project, $tag, $branch ) { - list( $comparison ) = self::request( - self::API_ROOT . "repos/{$project}/compare/" . rawurlencode( $tag ) . '...' . rawurlencode( $branch ) - ); + public static function get_pull_requests_merged_since( $project, $tag, $branch, $comparison = null ) { + if ( null === $comparison ) { + $comparison = self::get_comparison( $project, $tag, $branch ); + } $commits = []; foreach ( $comparison->commits as $commit ) { @@ -425,6 +427,149 @@ public static function get_pull_requests_merged_since( $project, $tag, $branch ) return $pull_requests; } + /** + * Compares two refs of a repository. + * + * @param string $project + * @param string $base + * @param string $head + * + * @return object Comparison, listing at most 250 of its commits. + */ + public static function get_comparison( $project, $base, $head ) { + list( $comparison ) = self::request( + self::API_ROOT . "repos/{$project}/compare/" . rawurlencode( $base ) . '...' . rawurlencode( $head ) + ); + + return $comparison; + } + + /** + * Gets the commits on a branch since a given tag that no pull request + * brought in, such as the files synced from wp-cli/.github. + * + * @param string $project + * @param object $comparison Comparison of the tag and the branch. + * @param object[] $pull_requests Pull requests merged since the tag. + * + * @return object[]|null Commits with their `files`, oldest first. Null when + * the comparison is too long to tell. + */ + public static function get_direct_commits( $project, $comparison, array $pull_requests ) { + if ( count( $comparison->commits ) < $comparison->total_commits ) { + return null; + } + + $merged = []; + foreach ( $pull_requests as $pull_request ) { + $merged[ $pull_request->merge_commit_sha ] = true; + } + + $direct = []; + foreach ( $comparison->commits as $commit ) { + if ( isset( $merged[ $commit->sha ] ) ) { + continue; + } + + // Commits of a pull request that was merged with a merge commit + // are listed as well, and belong to that pull request. + list( $associated ) = self::request( self::API_ROOT . "repos/{$project}/commits/{$commit->sha}/pulls" ); + if ( $associated ) { + continue; + } + + list( $direct[] ) = self::request( self::API_ROOT . "repos/{$project}/commits/{$commit->sha}" ); + } + + return $direct; + } + + /** + * Gets the open pull requests against a branch. + * + * @param string $project + * @param string $branch + * + * @return object[] + */ + public static function get_open_pull_requests( $project, $branch ) { + return self::request_all( + self::API_ROOT . "repos/{$project}/pulls", + [ + 'state' => 'open', + 'base' => $branch, + ] + ); + } + + /** + * Gets the names of the files a pull request changes, including the + * previous names of renamed files. + * + * @param string $project + * @param int $number + * + * @return string[] + */ + public static function get_pull_request_files( $project, $number ) { + return self::file_names( self::request_all( self::API_ROOT . "repos/{$project}/pulls/{$number}/files" ) ); + } + + /** + * Gets the names of changed files, including the previous names of + * renamed files. + * + * @param object[] $files Files of a pull request or commit, with + * `filename` and maybe `previous_filename`. + * + * @return string[] + */ + public static function file_names( array $files ) { + $names = []; + foreach ( $files as $file ) { + $names[] = $file->filename; + if ( isset( $file->previous_filename ) ) { + $names[] = $file->previous_filename; + } + } + + return $names; + } + + /** + * Creates a milestone. + * + * @param string $project + * @param string $title + * + * @return object + */ + public static function create_milestone( $project, $title ) { + list( $milestone ) = self::request( + self::API_ROOT . "repos/{$project}/milestones", + [ 'title' => (string) $title ], + 'POST' + ); + + return $milestone; + } + + /** + * Puts an issue or pull request on a milestone, replacing the one it was + * on. + * + * @param string $project + * @param int $issue + * @param int $milestone Milestone number. + */ + public static function set_milestone( $project, $issue, $milestone ) { + self::request( + self::API_ROOT . "repos/{$project}/issues/{$issue}", + [ 'milestone' => (int) $milestone ], + 'PATCH' + ); + } + /** * Gets the default branch of a repository. * diff --git a/.maintenance/src/Milestone_Command.php b/.maintenance/src/Milestone_Command.php new file mode 100644 index 0000000..2df370c --- /dev/null +++ b/.maintenance/src/Milestone_Command.php @@ -0,0 +1,92 @@ + + * : Name of the repository. If no user/org was provided, 'wp-cli' org is + * assumed. + * + * + * : Title of the milestone, such as 3.0.4. + * + * ... + * : Numbers of the issues or pull requests. + * + * [--create] + * : Create the milestone when the repository has none with that title. + * + * ## EXAMPLES + * + * # Defer an open pull request to the next patch release. + * $ wp maintenance milestone assign i18n-command 3.0.4 503 --create + * Created milestone '3.0.4' in wp-cli/i18n-command. + * Added #503 to milestone '3.0.4'. + * Success: Put 1 issue(s) or pull request(s) on milestone '3.0.4'. + * + * @when before_wp_load + */ + public function assign( $args, $assoc_args ) { + $repo = GitHub::qualify_repo( array_shift( $args ) ); + $title = (string) array_shift( $args ); + $create = Utils\get_flag_value( $assoc_args, 'create', false ); + $numbers = []; + + foreach ( $args as $arg ) { + $number = filter_var( ltrim( trim( $arg ), '#' ), FILTER_VALIDATE_INT, [ 'options' => [ 'min_range' => 1 ] ] ); + if ( false === $number ) { + WP_CLI::error( "'{$arg}' is not the number of an issue or pull request." ); + } + $numbers[] = $number; + } + + $milestone = self::find( GitHub::get_project_milestones( $repo, [ 'state' => 'all' ] ), $title ); + + if ( null === $milestone ) { + if ( ! $create ) { + WP_CLI::error( "{$repo} has no milestone '{$title}'. Pass --create to create it." ); + } + + $milestone = GitHub::create_milestone( $repo, $title ); + WP_CLI::log( "Created milestone '{$title}' in {$repo}." ); + } elseif ( 'open' !== $milestone->state ) { + WP_CLI::error( "Milestone '{$title}' of {$repo} is closed." ); + } + + foreach ( $numbers as $number ) { + GitHub::set_milestone( $repo, $number, $milestone->number ); + WP_CLI::log( "Added #{$number} to milestone '{$title}'." ); + } + + WP_CLI::success( sprintf( "Put %d issue(s) or pull request(s) on milestone '%s'.", count( $numbers ), $title ) ); + } + + /** + * Finds a milestone by its title. + * + * @param object[] $milestones Milestones with a `title`. + * @param string $title Title to look for. + * + * @return object|null + */ + public static function find( array $milestones, $title ) { + foreach ( $milestones as $milestone ) { + if ( $milestone->title === $title ) { + return $milestone; + } + } + + return null; + } +} diff --git a/.maintenance/src/Release_Command.php b/.maintenance/src/Release_Command.php index e263d71..cca1028 100644 --- a/.maintenance/src/Release_Command.php +++ b/.maintenance/src/Release_Command.php @@ -310,7 +310,16 @@ static function ( $milestone ) use ( $only_milestone ) { * which milestone a pull request belongs to. The blockers say what. * * Routine pull requests by Dependabot or GitHub Actions only count when - * they are on a milestone. + * they are on a milestone, and so do pull requests that only change + * workflows, the README or other files synced from wp-cli/.github. + * + * The JSON also lists what a maintainer may want to look at before a + * release without it blocking one: `open_pull_requests` without an open + * milestone, the `open_items` still on the milestone of the unreleased + * changes, `direct_commits` that no pull request brought in and that + * change more than those development files (null when there are more + * commits since the latest tag than GitHub compares), and the + * `open_milestones` that could still be released. * * Makes no changes. * diff --git a/.maintenance/src/Release_Plan.php b/.maintenance/src/Release_Plan.php index fce1bd8..e77585e 100644 --- a/.maintenance/src/Release_Plan.php +++ b/.maintenance/src/Release_Plan.php @@ -28,12 +28,19 @@ final class Release_Plan { 'github-actions[bot]', ]; + /** + * Files that only matter for developing a package, not for using it: + * the files synced from wp-cli/.github and the generated README. + */ + const ROUTINE_PATHS = '#^(\.github/|\.actrc$|\.editorconfig$|AGENTS\.md$|README\.md$)#'; + /** * Gathers what the plan needs to know about a repository from GitHub. * * @param string $repo Repository name, including the org. * - * @return array Plan, see assess(). + * @return array Plan, see assess(), with the `open_items` of the + * milestones the unreleased changes are on. */ public static function fetch( $repo ) { $tags = array_map( @@ -44,13 +51,60 @@ static function ( $tag ) { ); $milestones = GitHub::get_project_milestones( $repo, [ 'state' => 'all' ] ); $latest_tag = self::latest_version_tag( $tags ); + $branch = GitHub::get_default_branch( $repo ); - $pull_requests = []; + $pull_requests = []; + $direct_commits = []; if ( null !== $latest_tag ) { - $pull_requests = GitHub::get_pull_requests_merged_since( $repo, $latest_tag, GitHub::get_default_branch( $repo ) ); + $comparison = GitHub::get_comparison( $repo, $latest_tag, $branch ); + $pull_requests = GitHub::get_pull_requests_merged_since( $repo, $latest_tag, $branch, $comparison ); + + // Only a pull request without a milestone can be routine because + // of the files it changes, see is_change(). + foreach ( $pull_requests as $pull_request ) { + if ( empty( $pull_request->milestone ) && ! self::is_routine_author( $pull_request ) ) { + $pull_request->files = GitHub::get_pull_request_files( $repo, $pull_request->number ); + } + } + + $direct_commits = GitHub::get_direct_commits( $repo, $comparison, $pull_requests ); + } + + $plan = self::assess( + $repo, + $tags, + $milestones, + $pull_requests, + $direct_commits, + GitHub::get_open_pull_requests( $repo, $branch ) + ); + + $targets = array_filter( array_column( $plan['pull_requests'], 'milestone' ) ); + foreach ( $milestones as $milestone ) { + if ( 'open' !== $milestone->state || $milestone->open_issues < 1 || ! in_array( $milestone->title, $targets, true ) ) { + continue; + } + + $items = GitHub::get_issues( + $repo, + [ + 'milestone' => $milestone->number, + 'state' => 'open', + ] + ); + + foreach ( $items as $item ) { + $plan['open_items'][] = [ + 'number' => $item->number, + 'title' => $item->title, + 'type' => empty( $item->pull_request ) ? 'issue' : 'pull_request', + 'draft' => ! empty( $item->draft ), + 'milestone' => $milestone->title, + ]; + } } - return self::assess( $repo, $tags, $milestones, $pull_requests ); + return $plan; } /** @@ -63,11 +117,23 @@ static function ( $tag ) { * `title`, `state` and `open_issues`. * @param object[] $pull_requests Pull requests merged into the default * branch since the latest version tag, with - * `number`, `title`, `user` and `milestone`. + * `number`, `title`, `user` and `milestone`, + * and the names of the `files` they change + * when known. + * @param object[]|null $direct_commits Commits on the default branch + * since the latest version tag that no + * pull request brought in, with `sha`, + * `commit`, `author` and `files`. Null + * when there are too many commits to + * tell. + * @param object[] $open_pull_requests Open pull requests against the + * default branch, with `number`, + * `title`, `user`, `draft` and + * `milestone`. * - * @return array{repo: string, status: string, latest_tag: string|null, release: array|null, pull_requests: array, blockers: array} + * @return array{repo: string, status: string, latest_tag: string|null, release: array|null, pull_requests: array, blockers: array, direct_commits: array|null, open_pull_requests: array, open_items: array, open_milestones: array} */ - public static function assess( $repo, array $tags, array $milestones, array $pull_requests ) { + public static function assess( $repo, array $tags, array $milestones, array $pull_requests, $direct_commits = [], array $open_pull_requests = [] ) { $latest_tag = self::latest_version_tag( $tags ); $changes = array_values( array_filter( $pull_requests, [ __CLASS__, 'is_change' ] ) ); @@ -80,6 +146,41 @@ public static function assess( $repo, array $tags, array $milestones, array $pul 'blockers' => [], ]; + $plan['direct_commits'] = null === $direct_commits ? null : array_values( array_map( [ __CLASS__, 'describe_commit' ], array_filter( $direct_commits, [ __CLASS__, 'is_direct_change' ] ) ) ); + $plan['open_pull_requests'] = []; + $plan['open_items'] = []; + $plan['open_milestones'] = []; + + foreach ( $open_pull_requests as $pull_request ) { + if ( ! empty( $pull_request->draft ) || self::is_routine_author( $pull_request ) ) { + continue; + } + + if ( ! empty( $pull_request->milestone ) + && 'open' === $pull_request->milestone->state + && ! self::has_tag( $tags, $pull_request->milestone->title ) ) { + continue; + } + + $plan['open_pull_requests'][] = self::describe_pull_request( $pull_request ); + } + + foreach ( $milestones as $milestone ) { + if ( 'open' === $milestone->state && self::TAGGABLE === self::get_tag_status( $milestone->title, [], $tags ) ) { + $plan['open_milestones'][] = [ + 'title' => $milestone->title, + 'open_issues' => $milestone->open_issues, + ]; + } + } + + usort( + $plan['open_milestones'], + static function ( $a, $b ) { + return version_compare( ltrim( $a['title'], 'v' ), ltrim( $b['title'], 'v' ) ); + } + ); + if ( null === $latest_tag ) { $plan['status'] = self::NEEDS_HUMAN; $plan['blockers'][] = self::blocker( 'no_version_tag', 'The repository has no version tag to compare the default branch against.' ); @@ -228,16 +329,70 @@ public static function has_tag( array $tags, $version ) { } /** - * Checks whether a merged pull request calls for a release. Routine - * automated updates only do when a maintainer put them on a milestone. + * Checks whether a merged pull request calls for a release. One by a + * maintainer always does when they put it on a milestone. Otherwise, + * routine automated updates and changes to development files only, such + * as workflows or the README, do not. * - * @param object $pull_request Pull request with `user` and `milestone`. + * @param object $pull_request Pull request with `user` and `milestone`, + * and `files` when known. * * @return bool */ private static function is_change( $pull_request ) { - return ! empty( $pull_request->milestone ) - || ! in_array( $pull_request->user->login, self::ROUTINE_AUTHORS, true ); + if ( ! empty( $pull_request->milestone ) ) { + return true; + } + + if ( self::is_routine_author( $pull_request ) ) { + return false; + } + + return ! isset( $pull_request->files ) || ! self::are_routine_files( $pull_request->files ); + } + + /** + * Checks whether a commit that no pull request brought in changes more + * than development files. + * + * @param object $commit Commit with `files`. + * + * @return bool + */ + private static function is_direct_change( $commit ) { + return ! self::are_routine_files( GitHub::file_names( (array) $commit->files ) ); + } + + /** + * Checks whether a list of files only holds development files, see + * ROUTINE_PATHS. + * + * @param string[] $files File names, relative to the repository root. + * + * @return bool + */ + public static function are_routine_files( array $files ) { + foreach ( $files as $file ) { + if ( ! preg_match( self::ROUTINE_PATHS, $file ) ) { + return false; + } + } + + return true; + } + + private static function is_routine_author( $pull_request ) { + return in_array( $pull_request->user->login, self::ROUTINE_AUTHORS, true ); + } + + private static function describe_commit( $commit ) { + $message = explode( "\n", $commit->commit->message, 2 ); + + return [ + 'sha' => $commit->sha, + 'message' => $message[0], + 'author' => empty( $commit->author ) ? $commit->commit->author->name : $commit->author->login, + ]; } private static function describe_pull_request( $pull_request ) { diff --git a/.readme-partials/DEVELOPMENT.md b/.readme-partials/DEVELOPMENT.md index 67b84a4..d6241dc 100644 --- a/.readme-partials/DEVELOPMENT.md +++ b/.readme-partials/DEVELOPMENT.md @@ -16,3 +16,5 @@ The `wp maintenance` commands don't need the full environment: any `wp` executab To find out which packages have unreleased changes, run `wp maintenance release plan --bundle`. It makes no changes, and for each package it says whether a milestone is ready for `wp maintenance release generate` or what a maintainer still needs to decide, such as which milestone a merged pull request belongs to. To check the locked dependencies of the bundle for security advisories, run `wp maintenance dependencies audit`. It runs `composer audit` against the composer.lock as committed, so it reports what the Code Quality workflow fails on, and marks the packages that are only needed for development, as they don't ship in the Phar. + +To release everything that is ready across the bundle and refresh its lockfile in one go, ask Claude Code to "update the bundle" or run `/update-bundle` from this folder. The skill in `.claude/skills/update-bundle` asks you about every open milestone question first, gets your approval before tagging anything, and then babysits the lockfile pull requests and the automated tests. diff --git a/composer.json b/composer.json index d2cf4da..8dc2aed 100644 --- a/composer.json +++ b/composer.json @@ -279,6 +279,8 @@ "maintenance", "maintenance contrib-list", "maintenance doctor", + "maintenance milestone", + "maintenance milestone assign", "maintenance milestones-after", "maintenance milestones-since", "maintenance release", diff --git a/tests/GitHubApiTest.php b/tests/GitHubApiTest.php index d28b6ff..2ee363a 100644 --- a/tests/GitHubApiTest.php +++ b/tests/GitHubApiTest.php @@ -191,4 +191,27 @@ private function pull_request( $index, $number, $updated_at, $merged_at, $merge_ ] ); } + + public function test_direct_commits_are_unknown_for_a_truncated_comparison(): void { + $comparison = $this->fixture( 'comparison' ); + $comparison->total_commits = 300; + + $this->assertNull( GitHub::get_direct_commits( 'wp-cli/block-command', $comparison, [] ) ); + $this->assertSame( [], $this->requests ); + } + + public function test_file_names_include_the_previous_name_of_a_renamed_file(): void { + $this->assertSame( + [ 'src/New.php', '.github/new.yml', 'src/Old.php' ], + GitHub::file_names( + [ + (object) [ 'filename' => 'src/New.php' ], + (object) [ + 'filename' => '.github/new.yml', + 'previous_filename' => 'src/Old.php', + ], + ] + ) + ); + } } diff --git a/tests/MilestoneCommandTest.php b/tests/MilestoneCommandTest.php new file mode 100644 index 0000000..05b927c --- /dev/null +++ b/tests/MilestoneCommandTest.php @@ -0,0 +1,133 @@ +respond( + 'GET', + self::REPO . '/milestones?state=all', + array_map( + function ( $milestone ) { + return $this->fixture_object( 'milestone', null, $milestone ); + }, + $milestones + ) + ); + } + + /** + * @return array Write requests and their data. + */ + private function writes() { + $writes = []; + foreach ( $this->requests as $index => $request ) { + if ( 0 !== strpos( $request, 'GET ' ) ) { + $writes[] = [ $request, $this->sent_data[ $index ] ]; + } + } + + return $writes; + } + + public function test_assign_puts_items_on_an_existing_milestone(): void { + $this->milestones( + [ + [ + 'number' => 4, + 'title' => '1.0.4', + 'state' => 'closed', + ], + [ + 'number' => 5, + 'title' => '1.0.5', + 'state' => 'open', + ], + ] + ); + $this->respond( 'PATCH', self::REPO . '/issues/19', $this->fixture( 'issues' )[0] ); + $this->respond( 'PATCH', self::REPO . '/issues/20', $this->fixture( 'issues' )[0] ); + + ( new Milestone_Command() )->assign( [ 'block-command', '1.0.5', '19', '#20' ], [] ); + + $this->assertEquals( + [ + [ 'PATCH https://api.github.com/repos/wp-cli/block-command/issues/19', (object) [ 'milestone' => 5 ] ], + [ 'PATCH https://api.github.com/repos/wp-cli/block-command/issues/20', (object) [ 'milestone' => 5 ] ], + ], + $this->writes() + ); + $this->assertStringContainsString( "Put 2 issue(s) or pull request(s) on milestone '1.0.5'.", $this->logger->stdout ); + } + + public function test_assign_creates_a_missing_milestone_when_asked(): void { + $this->milestones( [] ); + $this->respond( + 'POST', + self::REPO . '/milestones', + $this->fixture_object( + 'milestone', + null, + [ + 'number' => 6, + 'title' => '1.0.6', + 'state' => 'open', + ] + ) + ); + $this->respond( 'PATCH', self::REPO . '/issues/19', $this->fixture( 'issues' )[0] ); + + ( new Milestone_Command() )->assign( [ 'block-command', '1.0.6', '19' ], [ 'create' => true ] ); + + $this->assertEquals( + [ + [ 'POST https://api.github.com/repos/wp-cli/block-command/milestones', (object) [ 'title' => '1.0.6' ] ], + [ 'PATCH https://api.github.com/repos/wp-cli/block-command/issues/19', (object) [ 'milestone' => 6 ] ], + ], + $this->writes() + ); + } + + private function assert_refused( array $args, array $assoc_args, $message ) { + $this->milestones( + [ + [ + 'number' => 4, + 'title' => '1.0.4', + 'state' => 'closed', + ], + ] + ); + + try { + ( new Milestone_Command() )->assign( $args, $assoc_args ); + $this->fail( 'The command should have stopped.' ); + } catch ( ExitException $exception ) { + $this->assertSame( 1, $exception->getCode() ); + } + + $this->assertSame( [], $this->writes() ); + $this->assertStringContainsString( $message, $this->logger->stderr ); + } + + public function test_assign_needs_create_for_a_missing_milestone(): void { + $this->assert_refused( [ 'block-command', '1.0.5', '19' ], [], "has no milestone '1.0.5'. Pass --create" ); + } + + public function test_assign_refuses_a_closed_milestone(): void { + $this->assert_refused( [ 'block-command', '1.0.4', '19' ], [ 'create' => true ], "Milestone '1.0.4' of wp-cli/block-command is closed." ); + } + + public function test_assign_needs_numbers(): void { + $this->assert_refused( [ 'block-command', '1.0.4', 'abc' ], [], "'abc' is not the number" ); + } + + public function test_assign_checks_every_number_before_any_write(): void { + $this->assert_refused( [ 'block-command', '1.0.5', '19', '0' ], [ 'create' => true ], "'0' is not the number" ); + } +} diff --git a/tests/ReleaseCommandTest.php b/tests/ReleaseCommandTest.php index 8c7dfcf..8831f28 100644 --- a/tests/ReleaseCommandTest.php +++ b/tests/ReleaseCommandTest.php @@ -56,7 +56,9 @@ function ( $tag ) { ] ); } - $this->respond( 'GET', self::REPO . '/pulls', $pull_requests ); + $this->respond( 'GET', self::REPO . '/pulls?state=open', [] ); + $this->respond( 'GET', self::REPO . '/pulls?state=closed', $pull_requests ); + $this->commits( $comparison ); $open = []; foreach ( $milestones as $number => $title ) { @@ -83,6 +85,44 @@ function ( $tag ) { $this->respond( 'POST', self::REPO . '/releases', $this->fixture( 'release' ) ); } + /** + * Answers which pull request each commit of a comparison belongs to. + * Commits that no pull request brought in are recorded sync commits, + * changing the given files. + * + * @param object $comparison Recorded comparison. + * @param array $direct Commit SHA => changed files. + */ + private function commits( $comparison, array $direct = [] ) { + foreach ( $comparison->commits as $commit ) { + if ( ! isset( $direct[ $commit->sha ] ) ) { + $this->respond( 'GET', self::REPO . "/commits/{$commit->sha}/pulls", $this->fixture( 'commit-pulls' ) ); + continue; + } + + $files = array_map( + static function ( $file ) { + return [ 'filename' => $file ]; + }, + $direct[ $commit->sha ] + ); + + $this->respond( 'GET', self::REPO . "/commits/{$commit->sha}/pulls", $this->fixture( 'commit-direct' ) ); + $this->respond( + 'GET', + self::REPO . "/commits/{$commit->sha}", + $this->fixture_object( + 'commit', + null, + [ + 'sha' => $commit->sha, + 'files' => $files, + ] + ) + ); + } + } + /** * @return array Write requests, as "METHOD URL". */ @@ -212,9 +252,11 @@ public function test_plan_reports_a_ready_milestone(): void { ); $this->respond( 'GET', self::REPO, $this->fixture( 'repository' ) ); $this->respond( 'GET', self::REPO . '/compare/v1.0.1...main', $comparison ); + $this->respond( 'GET', self::REPO . '/pulls?state=open', [] ); + $this->commits( $comparison ); $this->respond( 'GET', - self::REPO . '/pulls', + self::REPO . '/pulls?state=closed', [ $this->fixture_object( 'pull-requests', @@ -242,4 +284,134 @@ public function test_plan_reports_a_ready_milestone(): void { ); $this->assertSame( [ 18 ], array_column( $plan['pull_requests'], 'number' ) ); } + + public function test_plan_lists_what_a_maintainer_still_has_to_decide(): void { + $comparison = $this->fixture( 'comparison' ); + $commits = $comparison->commits; + + $this->respond( 'GET', self::REPO . '/tags', [ $this->fixture_object( 'tags-page-1', 0, [ 'name' => 'v1.0.1' ] ) ] ); + $this->respond( + 'GET', + self::REPO . '/milestones?state=all', + [ + $this->fixture_object( + 'milestone', + null, + [ + 'number' => 5, + 'title' => '1.0.2', + 'state' => 'open', + 'open_issues' => 1, + ] + ), + ] + ); + $this->respond( 'GET', self::REPO, $this->fixture( 'repository' ) ); + $this->respond( 'GET', self::REPO . '/compare/v1.0.1...main', $comparison ); + $this->respond( 'GET', self::REPO . '/issues?milestone=5&state=open', array_slice( $this->fixture( 'issues' ), 0, 1 ) ); + + $open_milestone = [ + 'title' => '1.0.2', + 'state' => 'open', + ]; + $open = [ + [ + 'number' => 40, + 'user' => [ 'login' => 'octocat' ], + 'milestone' => null, + ], + [ + 'number' => 41, + 'user' => [ 'login' => 'octocat' ], + 'milestone' => null, + 'draft' => true, + ], + [ + 'number' => 42, + 'user' => [ 'login' => 'octocat' ], + 'milestone' => $open_milestone, + ], + [ + 'number' => 43, + 'user' => [ 'login' => 'dependabot[bot]' ], + 'milestone' => null, + ], + ]; + $this->respond( + 'GET', + self::REPO . '/pulls?state=open', + array_map( + function ( $overrides ) { + return $this->fixture_object( 'pull-requests', 0, $overrides + [ 'draft' => false ] ); + }, + $open + ) + ); + $this->respond( + 'GET', + self::REPO . '/pulls?state=closed', + [ + $this->fixture_object( + 'pull-requests', + 0, + [ + 'number' => 18, + 'updated_at' => '2026-09-01T00:00:00Z', + 'merged_at' => '2026-09-01T00:00:00Z', + 'merge_commit_sha' => $commits[0]->sha, + 'milestone' => $open_milestone, + ] + ), + $this->fixture_object( + 'pull-requests', + 0, + [ + 'number' => 17, + 'user' => [ 'login' => 'octocat' ], + 'updated_at' => '2026-09-01T00:00:00Z', + 'merged_at' => '2026-09-01T00:00:00Z', + 'merge_commit_sha' => $commits[1]->sha, + 'milestone' => null, + ] + ), + ] + ); + $this->respond( 'GET', self::REPO . '/pulls/17/files', $this->fixture( 'pull-files' ) ); + $this->commits( + $comparison, + [ + $commits[2]->sha => [ '.github/workflows/testing.yml', 'AGENTS.md' ], + $commits[3]->sha => [ 'src/Block_Command.php' ], + ] + ); + + $plan = Release_Plan::fetch( 'wp-cli/block-command' ); + + $this->assertSame( Release_Plan::NEEDS_HUMAN, $plan['status'] ); + $this->assertSame( [ 18 ], array_column( $plan['pull_requests'], 'number' ), 'A pull request that only changes the README is routine.' ); + $this->assertSame( [ $commits[3]->sha ], array_column( $plan['direct_commits'], 'sha' ) ); + $this->assertSame( 'swissspidy', $plan['direct_commits'][0]['author'] ); + $this->assertSame( [ 40 ], array_column( $plan['open_pull_requests'], 'number' ) ); + $this->assertSame( + [ + [ + 'number' => 19, + 'title' => 'Fix PHPCS errors in Behat test files', + 'type' => 'pull_request', + 'draft' => false, + 'milestone' => '1.0.2', + ], + ], + $plan['open_items'] + ); + $this->assertSame( + [ + [ + 'title' => '1.0.2', + 'open_issues' => 1, + ], + ], + $plan['open_milestones'] + ); + } } diff --git a/tests/ReleasePlanTest.php b/tests/ReleasePlanTest.php index 12b8e48..33efad3 100644 --- a/tests/ReleasePlanTest.php +++ b/tests/ReleasePlanTest.php @@ -178,4 +178,139 @@ public function test_tag_status_of_a_milestone(): void { public function test_a_first_release_can_be_tagged(): void { $this->assertSame( Release_Plan::TAGGABLE, Release_Plan::get_tag_status( '1.0.0', [], [] ) ); } + + public function test_pull_requests_that_only_change_development_files_need_no_release(): void { + $workflow = $this->pull_request( 60 ); + $workflow->files = [ '.github/workflows/testing.yml', 'README.md' ]; + $code = $this->pull_request( 61 ); + $code->files = [ '.github/workflows/testing.yml', 'src/Eval_Command.php' ]; + $planned = $this->pull_request( 62, '3.0.2' ); + $planned->files = [ 'README.md' ]; + + $plan = Release_Plan::assess( 'wp-cli/eval-command', [ 'v3.0.1' ], [ $this->milestone( '3.0.2' ) ], [ $workflow ] ); + $this->assertSame( Release_Plan::UP_TO_DATE, $plan['status'] ); + + $plan = Release_Plan::assess( 'wp-cli/eval-command', [ 'v3.0.1' ], [ $this->milestone( '3.0.2' ) ], [ $workflow, $code, $planned ] ); + $this->assertSame( [ 61, 62 ], array_column( $plan['pull_requests'], 'number' ) ); + $this->assertSame( [ 'no_milestone' => [ 61 ] ], $this->blockers( $plan ) ); + } + + public function test_routine_files(): void { + $this->assertTrue( Release_Plan::are_routine_files( [ '.github/dependabot.yml', '.actrc', '.editorconfig', 'AGENTS.md', 'README.md' ] ) ); + $this->assertFalse( Release_Plan::are_routine_files( [ 'README.md', 'composer.json' ] ) ); + $this->assertFalse( Release_Plan::are_routine_files( [ 'features/README.md' ] ) ); + } + + public function test_lists_the_open_pull_requests_that_need_a_milestone(): void { + $closed = $this->pull_request( 70, '3.0.1' ); + $closed->milestone = (object) [ + 'title' => '3.0.1', + 'state' => 'closed', + ]; + $tagged = $this->pull_request( 71 ); + $tagged->milestone = (object) [ + 'title' => '3.0.0', + 'state' => 'open', + ]; + $planned = $this->pull_request( 72 ); + $planned->milestone = (object) [ + 'title' => '3.0.2', + 'state' => 'open', + ]; + $draft = $this->pull_request( 73 ); + $draft->draft = true; + + $plan = Release_Plan::assess( + 'wp-cli/db-command', + [ 'v3.0.0', 'v3.0.1' ], + [], + [], + [], + [ $closed, $tagged, $planned, $draft, $this->pull_request( 74 ), $this->pull_request( 75, null, 'dependabot[bot]' ) ] + ); + + $this->assertSame( [ 70, 71, 74 ], array_column( $plan['open_pull_requests'], 'number' ) ); + $this->assertSame( Release_Plan::UP_TO_DATE, $plan['status'] ); + } + + public function test_lists_the_open_milestones_that_can_still_be_released(): void { + $plan = Release_Plan::assess( + 'wp-cli/db-command', + [ 'v3.0.1' ], + [ + $this->milestone( '3.1.0', 'open', 2 ), + $this->milestone( '3.0.1' ), + $this->milestone( '3.0.2' ), + $this->milestone( '3.0.0', 'closed' ), + $this->milestone( 'Future' ), + ], + [] + ); + + $this->assertSame( [ '3.0.2', '3.1.0' ], array_column( $plan['open_milestones'], 'title' ) ); + } + + public function test_commits_without_a_pull_request_are_listed_unless_routine(): void { + $commit = static function ( $sha, array $files ) { + return (object) [ + 'sha' => $sha, + 'commit' => (object) [ + 'message' => "Commit {$sha}\n\nWith a body.", + 'author' => (object) [ 'name' => 'Jane Doe' ], + ], + 'author' => null, + 'files' => array_map( + static function ( $file ) { + return (object) [ 'filename' => $file ]; + }, + $files + ), + ]; + }; + + $plan = Release_Plan::assess( + 'wp-cli/db-command', + [ 'v3.0.1' ], + [], + [], + [ $commit( 'aaa', [ '.github/workflows/testing.yml' ] ), $commit( 'bbb', [ 'src/DB_Command.php' ] ) ] + ); + + $this->assertSame( + [ + [ + 'sha' => 'bbb', + 'message' => 'Commit bbb', + 'author' => 'Jane Doe', + ], + ], + $plan['direct_commits'] + ); + } + + public function test_moving_code_into_development_files_is_a_change(): void { + $renamed = (object) [ + 'sha' => 'ccc', + 'commit' => (object) [ + 'message' => 'Move the command', + 'author' => (object) [ 'name' => 'Jane Doe' ], + ], + 'author' => null, + 'files' => [ + (object) [ + 'filename' => '.github/Legacy_Command.php', + 'previous_filename' => 'src/Legacy_Command.php', + ], + ], + ]; + + $plan = Release_Plan::assess( 'wp-cli/db-command', [ 'v3.0.1' ], [], [], [ $renamed ] ); + + $this->assertSame( [ 'ccc' ], array_column( $plan['direct_commits'], 'sha' ) ); + } + + public function test_direct_commits_stay_unknown_when_github_cannot_tell(): void { + $this->assertNull( Release_Plan::assess( 'wp-cli/db-command', [ 'v3.0.1' ], [], [], null )['direct_commits'] ); + $this->assertSame( [], Release_Plan::assess( 'wp-cli/db-command', [ 'v3.0.1' ], [], [], [] )['direct_commits'] ); + } } diff --git a/tests/fixtures/github/commit-direct.json b/tests/fixtures/github/commit-direct.json new file mode 100644 index 0000000..ff21477 --- /dev/null +++ b/tests/fixtures/github/commit-direct.json @@ -0,0 +1,6 @@ +{ + "request": "GET /repos/wp-cli/block-command/commits/0354f94deba582b6c0549cb2788eb7201ac00d0d/pulls", + "status": 200, + "headers": {}, + "body": [] +} diff --git a/tests/fixtures/github/commit-pulls.json b/tests/fixtures/github/commit-pulls.json new file mode 100644 index 0000000..fcbe2ea --- /dev/null +++ b/tests/fixtures/github/commit-pulls.json @@ -0,0 +1,370 @@ +{ + "request": "GET /repos/wp-cli/block-command/commits/0219166f30bb4164e4bfc783ae692e913364e7ff/pulls", + "status": 200, + "headers": {}, + "body": [ + { + "url": "https://api.github.com/repos/wp-cli/block-command/pulls/17", + "id": 4042939388, + "node_id": "PR_kwDOQl0QSc7w-lv8", + "html_url": "https://github.com/wp-cli/block-command/pull/17", + "diff_url": "https://github.com/wp-cli/block-command/pull/17.diff", + "patch_url": "https://github.com/wp-cli/block-command/pull/17.patch", + "issue_url": "https://api.github.com/repos/wp-cli/block-command/issues/17", + "number": 17, + "state": "closed", + "locked": false, + "title": "Regenerate README file", + "user": { + "login": "github-actions[bot]", + "id": 41898282, + "node_id": "MDM6Qm90NDE4OTgyODI=", + "avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/github-actions%5Bbot%5D", + "html_url": "https://github.com/apps/github-actions", + "followers_url": "https://api.github.com/users/github-actions%5Bbot%5D/followers", + "following_url": "https://api.github.com/users/github-actions%5Bbot%5D/following{/other_user}", + "gists_url": "https://api.github.com/users/github-actions%5Bbot%5D/gists{/gist_id}", + "starred_url": "https://api.github.com/users/github-actions%5Bbot%5D/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/github-actions%5Bbot%5D/subscriptions", + "organizations_url": "https://api.github.com/users/github-actions%5Bbot%5D/orgs", + "repos_url": "https://api.github.com/users/github-actions%5Bbot%5D/repos", + "events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}", + "received_events_url": "https://api.github.com/users/github-actions%5Bbot%5D/received_events", + "type": "Bot", + "user_view_type": "public", + "site_admin": false + }, + "body": "**This is an automated pull-request**\n\nRefreshes the `README.md` file with the latest changes to the docblocks in the source code.\n", + "created_at": "2026-07-13T08:48:09Z", + "updated_at": "2026-07-13T10:00:50Z", + "closed_at": "2026-07-13T10:00:50Z", + "merged_at": "2026-07-13T10:00:50Z", + "merge_commit_sha": "0219166f30bb4164e4bfc783ae692e913364e7ff", + "assignees": [], + "requested_reviewers": [], + "requested_teams": [], + "labels": [ + { + "id": 9801693960, + "node_id": "LA_kwDOQl0QSc8AAAACSDn7CA", + "url": "https://api.github.com/repos/wp-cli/block-command/labels/scope:documentation", + "name": "scope:documentation", + "color": "FEF2C0", + "default": false, + "description": "Related to documentation", + "archived_at": null, + "archived_by": null + } + ], + "milestone": null, + "draft": false, + "commits_url": "https://api.github.com/repos/wp-cli/block-command/pulls/17/commits", + "review_comments_url": "https://api.github.com/repos/wp-cli/block-command/pulls/17/comments", + "review_comment_url": "https://api.github.com/repos/wp-cli/block-command/pulls/comments{/number}", + "comments_url": "https://api.github.com/repos/wp-cli/block-command/issues/17/comments", + "statuses_url": "https://api.github.com/repos/wp-cli/block-command/statuses/cf34db132a42caaa764e59a03c5b87453a8fb76f", + "head": { + "label": "wp-cli:regenerate-readme", + "ref": "regenerate-readme", + "sha": "cf34db132a42caaa764e59a03c5b87453a8fb76f", + "user": { + "login": "wp-cli", + "id": 1570774, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjE1NzA3NzQ=", + "avatar_url": "https://avatars.githubusercontent.com/u/1570774?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/wp-cli", + "html_url": "https://github.com/wp-cli", + "followers_url": "https://api.github.com/users/wp-cli/followers", + "following_url": "https://api.github.com/users/wp-cli/following{/other_user}", + "gists_url": "https://api.github.com/users/wp-cli/gists{/gist_id}", + "starred_url": "https://api.github.com/users/wp-cli/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/wp-cli/subscriptions", + "organizations_url": "https://api.github.com/users/wp-cli/orgs", + "repos_url": "https://api.github.com/users/wp-cli/repos", + "events_url": "https://api.github.com/users/wp-cli/events{/privacy}", + "received_events_url": "https://api.github.com/users/wp-cli/received_events", + "type": "Organization", + "user_view_type": "public", + "site_admin": false + }, + "repo": { + "id": 1113395273, + "node_id": "R_kgDOQl0QSQ", + "name": "block-command", + "full_name": "wp-cli/block-command", + "private": false, + "owner": { + "login": "wp-cli", + "id": 1570774, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjE1NzA3NzQ=", + "avatar_url": "https://avatars.githubusercontent.com/u/1570774?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/wp-cli", + "html_url": "https://github.com/wp-cli", + "followers_url": "https://api.github.com/users/wp-cli/followers", + "following_url": "https://api.github.com/users/wp-cli/following{/other_user}", + "gists_url": "https://api.github.com/users/wp-cli/gists{/gist_id}", + "starred_url": "https://api.github.com/users/wp-cli/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/wp-cli/subscriptions", + "organizations_url": "https://api.github.com/users/wp-cli/orgs", + "repos_url": "https://api.github.com/users/wp-cli/repos", + "events_url": "https://api.github.com/users/wp-cli/events{/privacy}", + "received_events_url": "https://api.github.com/users/wp-cli/received_events", + "type": "Organization", + "user_view_type": "public", + "site_admin": false + }, + "html_url": "https://github.com/wp-cli/block-command", + "description": "Manages WordPress block editor blocks and related entities.", + "fork": false, + "url": "https://api.github.com/repos/wp-cli/block-command", + "forks_url": "https://api.github.com/repos/wp-cli/block-command/forks", + "keys_url": "https://api.github.com/repos/wp-cli/block-command/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/wp-cli/block-command/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/wp-cli/block-command/teams", + "hooks_url": "https://api.github.com/repos/wp-cli/block-command/hooks", + "issue_events_url": "https://api.github.com/repos/wp-cli/block-command/issues/events{/number}", + "events_url": "https://api.github.com/repos/wp-cli/block-command/events", + "assignees_url": "https://api.github.com/repos/wp-cli/block-command/assignees{/user}", + "branches_url": "https://api.github.com/repos/wp-cli/block-command/branches{/branch}", + "tags_url": "https://api.github.com/repos/wp-cli/block-command/tags", + "blobs_url": "https://api.github.com/repos/wp-cli/block-command/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/wp-cli/block-command/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/wp-cli/block-command/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/wp-cli/block-command/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/wp-cli/block-command/statuses/{sha}", + "languages_url": "https://api.github.com/repos/wp-cli/block-command/languages", + "stargazers_url": "https://api.github.com/repos/wp-cli/block-command/stargazers", + "contributors_url": "https://api.github.com/repos/wp-cli/block-command/contributors", + "subscribers_url": "https://api.github.com/repos/wp-cli/block-command/subscribers", + "subscription_url": "https://api.github.com/repos/wp-cli/block-command/subscription", + "commits_url": "https://api.github.com/repos/wp-cli/block-command/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/wp-cli/block-command/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/wp-cli/block-command/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/wp-cli/block-command/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/wp-cli/block-command/contents/{+path}", + "compare_url": "https://api.github.com/repos/wp-cli/block-command/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/wp-cli/block-command/merges", + "archive_url": "https://api.github.com/repos/wp-cli/block-command/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/wp-cli/block-command/downloads", + "issues_url": "https://api.github.com/repos/wp-cli/block-command/issues{/number}", + "pulls_url": "https://api.github.com/repos/wp-cli/block-command/pulls{/number}", + "milestones_url": "https://api.github.com/repos/wp-cli/block-command/milestones{/number}", + "notifications_url": "https://api.github.com/repos/wp-cli/block-command/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/wp-cli/block-command/labels{/name}", + "releases_url": "https://api.github.com/repos/wp-cli/block-command/releases{/id}", + "deployments_url": "https://api.github.com/repos/wp-cli/block-command/deployments", + "created_at": "2025-12-09T23:20:52Z", + "updated_at": "2026-11-09T04:24:06Z", + "pushed_at": "2026-11-09T04:24:03Z", + "git_url": "git://github.com/wp-cli/block-command.git", + "ssh_url": "git@github.com:wp-cli/block-command.git", + "clone_url": "https://github.com/wp-cli/block-command.git", + "svn_url": "https://github.com/wp-cli/block-command", + "homepage": "", + "size": 113, + "stargazers_count": 2, + "watchers_count": 2, + "language": "PHP", + "has_issues": true, + "has_projects": false, + "has_downloads": false, + "has_wiki": false, + "has_pages": false, + "has_discussions": false, + "forks_count": 1, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 3, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "has_pull_requests": true, + "pull_request_creation_policy": "all", + "topics": [], + "visibility": "public", + "forks": 1, + "open_issues": 3, + "watchers": 2, + "default_branch": "main" + } + }, + "base": { + "label": "wp-cli:main", + "ref": "main", + "sha": "e7a945c8b974457926a50df67d5f509220c6535a", + "user": { + "login": "wp-cli", + "id": 1570774, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjE1NzA3NzQ=", + "avatar_url": "https://avatars.githubusercontent.com/u/1570774?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/wp-cli", + "html_url": "https://github.com/wp-cli", + "followers_url": "https://api.github.com/users/wp-cli/followers", + "following_url": "https://api.github.com/users/wp-cli/following{/other_user}", + "gists_url": "https://api.github.com/users/wp-cli/gists{/gist_id}", + "starred_url": "https://api.github.com/users/wp-cli/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/wp-cli/subscriptions", + "organizations_url": "https://api.github.com/users/wp-cli/orgs", + "repos_url": "https://api.github.com/users/wp-cli/repos", + "events_url": "https://api.github.com/users/wp-cli/events{/privacy}", + "received_events_url": "https://api.github.com/users/wp-cli/received_events", + "type": "Organization", + "user_view_type": "public", + "site_admin": false + }, + "repo": { + "id": 1113395273, + "node_id": "R_kgDOQl0QSQ", + "name": "block-command", + "full_name": "wp-cli/block-command", + "private": false, + "owner": { + "login": "wp-cli", + "id": 1570774, + "node_id": "MDEyOk9yZ2FuaXphdGlvbjE1NzA3NzQ=", + "avatar_url": "https://avatars.githubusercontent.com/u/1570774?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/wp-cli", + "html_url": "https://github.com/wp-cli", + "followers_url": "https://api.github.com/users/wp-cli/followers", + "following_url": "https://api.github.com/users/wp-cli/following{/other_user}", + "gists_url": "https://api.github.com/users/wp-cli/gists{/gist_id}", + "starred_url": "https://api.github.com/users/wp-cli/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/wp-cli/subscriptions", + "organizations_url": "https://api.github.com/users/wp-cli/orgs", + "repos_url": "https://api.github.com/users/wp-cli/repos", + "events_url": "https://api.github.com/users/wp-cli/events{/privacy}", + "received_events_url": "https://api.github.com/users/wp-cli/received_events", + "type": "Organization", + "user_view_type": "public", + "site_admin": false + }, + "html_url": "https://github.com/wp-cli/block-command", + "description": "Manages WordPress block editor blocks and related entities.", + "fork": false, + "url": "https://api.github.com/repos/wp-cli/block-command", + "forks_url": "https://api.github.com/repos/wp-cli/block-command/forks", + "keys_url": "https://api.github.com/repos/wp-cli/block-command/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/wp-cli/block-command/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/wp-cli/block-command/teams", + "hooks_url": "https://api.github.com/repos/wp-cli/block-command/hooks", + "issue_events_url": "https://api.github.com/repos/wp-cli/block-command/issues/events{/number}", + "events_url": "https://api.github.com/repos/wp-cli/block-command/events", + "assignees_url": "https://api.github.com/repos/wp-cli/block-command/assignees{/user}", + "branches_url": "https://api.github.com/repos/wp-cli/block-command/branches{/branch}", + "tags_url": "https://api.github.com/repos/wp-cli/block-command/tags", + "blobs_url": "https://api.github.com/repos/wp-cli/block-command/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/wp-cli/block-command/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/wp-cli/block-command/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/wp-cli/block-command/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/wp-cli/block-command/statuses/{sha}", + "languages_url": "https://api.github.com/repos/wp-cli/block-command/languages", + "stargazers_url": "https://api.github.com/repos/wp-cli/block-command/stargazers", + "contributors_url": "https://api.github.com/repos/wp-cli/block-command/contributors", + "subscribers_url": "https://api.github.com/repos/wp-cli/block-command/subscribers", + "subscription_url": "https://api.github.com/repos/wp-cli/block-command/subscription", + "commits_url": "https://api.github.com/repos/wp-cli/block-command/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/wp-cli/block-command/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/wp-cli/block-command/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/wp-cli/block-command/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/wp-cli/block-command/contents/{+path}", + "compare_url": "https://api.github.com/repos/wp-cli/block-command/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/wp-cli/block-command/merges", + "archive_url": "https://api.github.com/repos/wp-cli/block-command/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/wp-cli/block-command/downloads", + "issues_url": "https://api.github.com/repos/wp-cli/block-command/issues{/number}", + "pulls_url": "https://api.github.com/repos/wp-cli/block-command/pulls{/number}", + "milestones_url": "https://api.github.com/repos/wp-cli/block-command/milestones{/number}", + "notifications_url": "https://api.github.com/repos/wp-cli/block-command/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/wp-cli/block-command/labels{/name}", + "releases_url": "https://api.github.com/repos/wp-cli/block-command/releases{/id}", + "deployments_url": "https://api.github.com/repos/wp-cli/block-command/deployments", + "created_at": "2025-12-09T23:20:52Z", + "updated_at": "2026-11-09T04:24:06Z", + "pushed_at": "2026-11-09T04:24:03Z", + "git_url": "git://github.com/wp-cli/block-command.git", + "ssh_url": "git@github.com:wp-cli/block-command.git", + "clone_url": "https://github.com/wp-cli/block-command.git", + "svn_url": "https://github.com/wp-cli/block-command", + "homepage": "", + "size": 113, + "stargazers_count": 2, + "watchers_count": 2, + "language": "PHP", + "has_issues": true, + "has_projects": false, + "has_downloads": false, + "has_wiki": false, + "has_pages": false, + "has_discussions": false, + "forks_count": 1, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 3, + "license": { + "key": "mit", + "name": "MIT License", + "spdx_id": "MIT", + "url": "https://api.github.com/licenses/mit", + "node_id": "MDc6TGljZW5zZTEz" + }, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "has_pull_requests": true, + "pull_request_creation_policy": "all", + "topics": [], + "visibility": "public", + "forks": 1, + "open_issues": 3, + "watchers": 2, + "default_branch": "main" + } + }, + "_links": { + "self": { + "href": "https://api.github.com/repos/wp-cli/block-command/pulls/17" + }, + "html": { + "href": "https://github.com/wp-cli/block-command/pull/17" + }, + "issue": { + "href": "https://api.github.com/repos/wp-cli/block-command/issues/17" + }, + "comments": { + "href": "https://api.github.com/repos/wp-cli/block-command/issues/17/comments" + }, + "review_comments": { + "href": "https://api.github.com/repos/wp-cli/block-command/pulls/17/comments" + }, + "review_comment": { + "href": "https://api.github.com/repos/wp-cli/block-command/pulls/comments{/number}" + }, + "commits": { + "href": "https://api.github.com/repos/wp-cli/block-command/pulls/17/commits" + }, + "statuses": { + "href": "https://api.github.com/repos/wp-cli/block-command/statuses/cf34db132a42caaa764e59a03c5b87453a8fb76f" + } + }, + "author_association": "CONTRIBUTOR", + "auto_merge": null, + "assignee": null, + "active_lock_reason": null + } + ] +} diff --git a/tests/fixtures/github/commit.json b/tests/fixtures/github/commit.json new file mode 100644 index 0000000..632d267 --- /dev/null +++ b/tests/fixtures/github/commit.json @@ -0,0 +1,106 @@ +{ + "request": "GET /repos/wp-cli/block-command/commits/0354f94deba582b6c0549cb2788eb7201ac00d0d", + "status": 200, + "headers": {}, + "body": { + "sha": "0354f94deba582b6c0549cb2788eb7201ac00d0d", + "node_id": "C_kwDOQl0QSdoAKDAzNTRmOTRkZWJhNTgyYjZjMDU0OWNiMjc4OGViNzIwMWFjMDBkMGQ", + "commit": { + "author": { + "name": "swissspidy", + "email": "swissspidy@users.noreply.github.com", + "date": "2026-04-22T08:45:37Z" + }, + "committer": { + "name": "swissspidy", + "email": "swissspidy@users.noreply.github.com", + "date": "2026-04-22T08:45:37Z" + }, + "message": "Update file(s) from wp-cli/.github", + "tree": { + "sha": "18e32df3e1da81ba076caf85d3e19913563fb830", + "url": "https://api.github.com/repos/wp-cli/block-command/git/trees/18e32df3e1da81ba076caf85d3e19913563fb830" + }, + "url": "https://api.github.com/repos/wp-cli/block-command/git/commits/0354f94deba582b6c0549cb2788eb7201ac00d0d", + "comment_count": 0, + "verification": { + "verified": false, + "reason": "unsigned", + "signature": null, + "payload": null, + "verified_at": null + } + }, + "url": "https://api.github.com/repos/wp-cli/block-command/commits/0354f94deba582b6c0549cb2788eb7201ac00d0d", + "html_url": "https://github.com/wp-cli/block-command/commit/0354f94deba582b6c0549cb2788eb7201ac00d0d", + "comments_url": "https://api.github.com/repos/wp-cli/block-command/commits/0354f94deba582b6c0549cb2788eb7201ac00d0d/comments", + "author": { + "login": "swissspidy", + "id": 841956, + "node_id": "MDQ6VXNlcjg0MTk1Ng==", + "avatar_url": "https://avatars.githubusercontent.com/u/841956?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/swissspidy", + "html_url": "https://github.com/swissspidy", + "followers_url": "https://api.github.com/users/swissspidy/followers", + "following_url": "https://api.github.com/users/swissspidy/following{/other_user}", + "gists_url": "https://api.github.com/users/swissspidy/gists{/gist_id}", + "starred_url": "https://api.github.com/users/swissspidy/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/swissspidy/subscriptions", + "organizations_url": "https://api.github.com/users/swissspidy/orgs", + "repos_url": "https://api.github.com/users/swissspidy/repos", + "events_url": "https://api.github.com/users/swissspidy/events{/privacy}", + "received_events_url": "https://api.github.com/users/swissspidy/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "committer": { + "login": "swissspidy", + "id": 841956, + "node_id": "MDQ6VXNlcjg0MTk1Ng==", + "avatar_url": "https://avatars.githubusercontent.com/u/841956?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/swissspidy", + "html_url": "https://github.com/swissspidy", + "followers_url": "https://api.github.com/users/swissspidy/followers", + "following_url": "https://api.github.com/users/swissspidy/following{/other_user}", + "gists_url": "https://api.github.com/users/swissspidy/gists{/gist_id}", + "starred_url": "https://api.github.com/users/swissspidy/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/swissspidy/subscriptions", + "organizations_url": "https://api.github.com/users/swissspidy/orgs", + "repos_url": "https://api.github.com/users/swissspidy/repos", + "events_url": "https://api.github.com/users/swissspidy/events{/privacy}", + "received_events_url": "https://api.github.com/users/swissspidy/received_events", + "type": "User", + "user_view_type": "public", + "site_admin": false + }, + "parents": [ + { + "sha": "259b8da86f84a386e262189be3f4b912183f563d", + "url": "https://api.github.com/repos/wp-cli/block-command/commits/259b8da86f84a386e262189be3f4b912183f563d", + "html_url": "https://github.com/wp-cli/block-command/commit/259b8da86f84a386e262189be3f4b912183f563d" + } + ], + "stats": { + "total": 8, + "additions": 7, + "deletions": 1 + }, + "files": [ + { + "sha": "bba7cddcd9ac914b48344f1e75ef8e772a61d141", + "filename": ".github/workflows/copilot-setup-steps.yml", + "status": "modified", + "additions": 7, + "deletions": 1, + "changes": 8, + "blob_url": "https://github.com/wp-cli/block-command/blob/0354f94deba582b6c0549cb2788eb7201ac00d0d/.github%2Fworkflows%2Fcopilot-setup-steps.yml", + "raw_url": "https://github.com/wp-cli/block-command/raw/0354f94deba582b6c0549cb2788eb7201ac00d0d/.github%2Fworkflows%2Fcopilot-setup-steps.yml", + "contents_url": "https://api.github.com/repos/wp-cli/block-command/contents/.github%2Fworkflows%2Fcopilot-setup-steps.yml?ref=0354f94deba582b6c0549cb2788eb7201ac00d0d", + "patch": "@@ -9,15 +9,21 @@ on:\n paths:\n - .github/workflows/copilot-setup-steps.yml\n \n+permissions:\n+ contents: read\n+\n jobs:\n copilot-setup-steps:\n+ name: Setup environment\n runs-on: ubuntu-latest\n permissions:\n contents: read\n \n steps:\n - name: Checkout code\n uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6\n+ with:\n+ persist-credentials: false\n \n - name: Check existence of composer.json file\n id: check_composer_file\n@@ -36,6 +42,6 @@ jobs:\n \n - name: Install Composer dependencies & cache dependencies\n if: steps.check_composer_file.outputs.files_exists == 'true'\n- uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # v4\n+ uses: ramsey/composer-install@65e4f84970763564f46a70b8a54b90d033b3bdda # 4.0.0\n env:\n COMPOSER_ROOT_VERSION: dev-${{ github.event.repository.default_branch }}" + } + ] + } +} diff --git a/tests/fixtures/github/pull-files.json b/tests/fixtures/github/pull-files.json new file mode 100644 index 0000000..1fbcb4a --- /dev/null +++ b/tests/fixtures/github/pull-files.json @@ -0,0 +1,19 @@ +{ + "request": "GET /repos/wp-cli/block-command/pulls/17/files", + "status": 200, + "headers": {}, + "body": [ + { + "sha": "102bd8455e80ed6dad671eaae71073b984e4dee5", + "filename": "README.md", + "status": "modified", + "additions": 1, + "deletions": 1, + "changes": 2, + "blob_url": "https://github.com/wp-cli/block-command/blob/cf34db132a42caaa764e59a03c5b87453a8fb76f/README.md", + "raw_url": "https://github.com/wp-cli/block-command/raw/cf34db132a42caaa764e59a03c5b87453a8fb76f/README.md", + "contents_url": "https://api.github.com/repos/wp-cli/block-command/contents/README.md?ref=cf34db132a42caaa764e59a03c5b87453a8fb76f", + "patch": "@@ -1215,7 +1215,7 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file\n \n ## Support\n \n-GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support\n+GitHub issues aren't for general support questions. For support resources and next steps, see the WP-CLI Support page: https://make.wordpress.org/cli/handbook/support/\n \n \n *This README.md is generated dynamically from the project's codebase using `wp scaffold package-readme` ([doc](https://github.com/wp-cli/scaffold-package-command#wp-scaffold-package-readme)). To suggest changes, please submit a pull request against the corresponding part of the codebase.*" + } + ] +} diff --git a/tests/fixtures/github/update.php b/tests/fixtures/github/update.php index 6aba7f6..7063436 100644 --- a/tests/fixtures/github/update.php +++ b/tests/fixtures/github/update.php @@ -25,6 +25,10 @@ 'issues' => 'repos/wp-cli/block-command/issues?milestone=4&state=all', 'pull-requests' => 'repos/wp-cli/block-command/pulls?state=closed&base=main&sort=created&direction=asc&per_page=3', 'comparison' => 'repos/wp-cli/block-command/compare/v1.0.1...v1.0.3', + 'commit' => 'repos/wp-cli/block-command/commits/0354f94deba582b6c0549cb2788eb7201ac00d0d', + 'commit-direct' => 'repos/wp-cli/block-command/commits/0354f94deba582b6c0549cb2788eb7201ac00d0d/pulls', + 'commit-pulls' => 'repos/wp-cli/block-command/commits/0219166f30bb4164e4bfc783ae692e913364e7ff/pulls', + 'pull-files' => 'repos/wp-cli/block-command/pulls/17/files', 'release' => 'repos/wp-cli/block-command/releases/tags/v1.0.4', 'release-absent' => 'repos/wp-cli/block-command/releases/tags/v0.0.0', ];