Skip to content

Commit

Permalink
Add custom branch support to wp scaffold package-readme command (#206)
Browse files Browse the repository at this point in the history
Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
  • Loading branch information
wojsmol and swissspidy authored Aug 11, 2022
1 parent e5a4b7b commit 0a8d5d1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
27 changes: 27 additions & 0 deletions features/scaffold-package-readme.feature
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,33 @@ Feature: Scaffold a README.md file for an existing package
Success: Uninstalled package.
"""

Scenario: Scaffold a README.md based with custom repository branch
Given an empty directory

When I run `wp package path`
Then save STDOUT as {PACKAGE_PATH}

When I run `wp scaffold package wp-cli/custom-branch`
Then STDOUT should contain:
"""
Success: Created package readme.
"""
# `wp scaffold package-readme --force` returns a warning
And I try `wp scaffold package-readme {PACKAGE_PATH}/local/wp-cli/custom-branch --branch=custom --force`
And the {PACKAGE_PATH}/local/wp-cli/custom-branch/README.md file should exist
And the {PACKAGE_PATH}/local/wp-cli/custom-branch/README.md file should contain:
"""
Installing this package requires WP-CLI v2.5 or greater. Update to the latest stable release with `wp cli update`.
"""
And the {PACKAGE_PATH}/local/wp-cli/custom-branch/README.md file should contain:
"""
[![Build Status](https://travis-ci.org/wp-cli/custom-branch.svg?branch=custom)
"""
And the {PACKAGE_PATH}/local/wp-cli/custom-branch/README.md file should contain:
"""
*This README.md is generated dynamically from the project's codebase
"""

Scenario: Scaffold a README.md requiring a nightly build
Given an empty directory

Expand Down
10 changes: 7 additions & 3 deletions src/ScaffoldPackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ public function package( $args, $assoc_args ) {
* [--force]
* : Overwrite the readme if it already exists.
*
* [--branch=<branch>]
* : Name of default branch of the underlaying repository. Defaults to master.
*
* @when before_wp_load
* @subcommand package-readme
*/
Expand All @@ -230,7 +233,8 @@ public function package_readme( $args, $assoc_args ) {
WP_CLI::error( 'Invalid composer.json in package directory.' );
}

$force = Utils\get_flag_value( $assoc_args, 'force' );
$force = Utils\get_flag_value( $assoc_args, 'force' );
$branch = Utils\get_flag_value( $assoc_args, 'branch', 'master' );

$package_root = dirname( dirname( __FILE__ ) );
$template_path = $package_root . '/templates/';
Expand All @@ -256,10 +260,10 @@ public function package_readme( $args, $assoc_args ) {
$shields[] = "[![Testing](https://github.com/{$readme_args['package_name']}/actions/workflows/testing.yml/badge.svg)](https://github.com/{$readme_args['package_name']}/actions/workflows/testing.yml)";
}
if ( file_exists( $package_dir . '/.travis.yml' ) ) {
$shields[] = "[![Build Status](https://travis-ci.org/{$readme_args['package_name']}.svg?branch=master)](https://travis-ci.org/{$readme_args['package_name']})";
$shields[] = "[![Build Status](https://travis-ci.org/{$readme_args['package_name']}.svg?branch={$branch})](https://travis-ci.org/{$readme_args['package_name']})";
}
if ( file_exists( $package_dir . '/circle.yml' ) ) {
$shields[] = "[![CircleCI](https://circleci.com/gh/{$readme_args['package_name']}/tree/master.svg?style=svg)](https://circleci.com/gh/{$readme_args['package_name']}/tree/master)";
$shields[] = "[![CircleCI](https://circleci.com/gh/{$readme_args['package_name']}/tree/{$branch}.svg?style=svg)](https://circleci.com/gh/{$readme_args['package_name']}/tree/{$branch})";
}

if ( count( $shields ) ) {
Expand Down

0 comments on commit 0a8d5d1

Please sign in to comment.