Skip to content

Commit

Permalink
Merge pull request #107 from wp-cli/85-github-tempaltes
Browse files Browse the repository at this point in the history
Introduce `wp scaffold package-github` to scaffold GitHub templates
  • Loading branch information
schlessera authored May 25, 2017
2 parents 77552bd + 9cedc37 commit fedf3ff
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--

Thanks for creating a new issue!

Found a bug or want to suggest an enhancement? Before completing your issue, please review our best practices: https://make.wordpress.org/cli/handbook/bug-reports/

Need help with something? GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support

You can safely delete this comment.

-->
14 changes: 14 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--

Thanks for submitting a pull request!

Here's an overview to our process:

1. One of the project committers will soon provide a code review.
2. You are expected to address the code review comments in a timely manner.
3. Please make sure to include functional tests for your changes.
4. The reviewing committer will merge your pull request as soon as it passes code review (and provided it fits within the scope of the project).

You can safely delete this comment.

-->
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,30 @@ In this example:
[--force]
Overwrite the readme if it already exists.



### wp scaffold package-github

Generate GitHub configuration files for your command.

~~~
wp scaffold package-github <dir> [--force]
~~~

Creates a variety of files to better manage your project on GitHub. These
files include:

* `.github/ISSUE_TEMPLATE` - Text displayed when a user opens a new issue.
* `.github/PULL_REQUEST_TEMPLATE` - Text displayed when a user submits a pull request.

**OPTIONS**

<dir>
The package directory to generate GitHub configuration for.

[--force]
Overwrite files that already exist.

## Installing

Installing this package requires WP-CLI v0.23.0 or greater. Update to the latest stable release with `wp cli update`.
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
"psr-4": { "WP_CLI\\": "src" },
"files": [ "scaffold-package-command.php" ]
},
"require": {
"wp-cli/wp-cli": "*"
},
"require": {},
"require-dev": {
"wp-cli/wp-cli": "*",
"behat/behat": "~2.5"
},
"extra": {
Expand All @@ -33,7 +32,8 @@
"commands": [
"scaffold package",
"scaffold package-tests",
"scaffold package-readme"
"scaffold package-readme",
"scaffold package-github"
]
}
}
37 changes: 37 additions & 0 deletions features/scaffold-package-github.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
Feature: Scaffold GitHub configuration for an existing package

Scenario: Fails when invalid package directory provided
Given an empty directory

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

When I try `wp scaffold package-github {PACKAGE_PATH}/local/wp-cli/default-github`
Then STDERR should be:
"""
Error: Invalid package directory. composer.json file must be present.
"""

Scenario: Scaffold GitHub configuration based on defaults
Given an empty directory

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

When I run `wp scaffold package wp-cli/default-github`
Then the {PACKAGE_PATH}/local/wp-cli/default-github directory should exist

When I run `wp scaffold package-github {PACKAGE_PATH}/local/wp-cli/default-github`
Then STDOUT should contain:
"""
Success: Created package GitHub configuration.
"""
And the {PACKAGE_PATH}/local/wp-cli/default-github/.github directory should exist
And the {PACKAGE_PATH}/local/wp-cli/default-github/.github/ISSUE_TEMPLATE file should contain:
"""
Thanks for creating a new issue!
"""
And the {PACKAGE_PATH}/local/wp-cli/default-github/.github/PULL_REQUEST_TEMPLATE file should contain:
"""
Thanks for submitting a pull request!
"""
1 change: 1 addition & 0 deletions scaffold-package-command.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
WP_CLI::add_command( 'scaffold package', array( 'WP_CLI\ScaffoldPackageCommand', 'package' ) );
WP_CLI::add_command( 'scaffold package-readme', array( 'WP_CLI\ScaffoldPackageCommand', 'package_readme' ) );
WP_CLI::add_command( 'scaffold package-tests', array( 'WP_CLI\ScaffoldPackageCommand', 'package_tests' ) );
WP_CLI::add_command( 'scaffold package-github', array( 'WP_CLI\ScaffoldPackageCommand', 'package_github' ) );
};

// Only use command hooks in versions that support them.
Expand Down
47 changes: 47 additions & 0 deletions src/ScaffoldPackageCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,53 @@ public function package_readme( $args, $assoc_args ) {
}
}

/**
* Generate GitHub configuration files for your command.
*
* Creates a variety of files to better manage your project on GitHub. These
* files include:
*
* * `.github/ISSUE_TEMPLATE` - Text displayed when a user opens a new issue.
* * `.github/PULL_REQUEST_TEMPLATE` - Text displayed when a user submits a pull request.
*
* ## OPTIONS
*
* <dir>
* : The package directory to generate GitHub configuration for.
*
* [--force]
* : Overwrite files that already exist.
*
* @when before_wp_load
* @subcommand package-github
*/
public function package_github( $args, $assoc_args ) {
list( $package_dir ) = $args;

if ( is_file( $package_dir ) ) {
$package_dir = dirname( $package_dir );
} else if ( is_dir( $package_dir ) ) {
$package_dir = rtrim( $package_dir, '/' );
}

if ( ! is_dir( $package_dir ) || ! file_exists( $package_dir . '/composer.json' ) ) {
WP_CLI::error( "Invalid package directory. composer.json file must be present." );
}
$force = Utils\get_flag_value( $assoc_args, 'force' );
$template_path = dirname( dirname( __FILE__ ) ) . '/templates';

$create_files = array(
"{$package_dir}/.github/ISSUE_TEMPLATE" => Utils\mustache_render( "{$template_path}/github-issue-template.mustache" ),
"{$package_dir}/.github/PULL_REQUEST_TEMPLATE" => Utils\mustache_render( "{$template_path}/github-pull-request-template.mustache" ),
);
$files_written = $this->create_files( $create_files, $force );
if ( empty( $files_written ) ) {
WP_CLI::log( 'Package GitHub configuration generation skipped.' );
} else {
WP_CLI::success( 'Created package GitHub configuration.' );
}
}

/**
* Generate files needed for writing Behat tests for your command.
*
Expand Down
11 changes: 11 additions & 0 deletions templates/github-issue-template.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!--
Thanks for creating a new issue!
Found a bug or want to suggest an enhancement? Before completing your issue, please review our best practices: https://make.wordpress.org/cli/handbook/bug-reports/
Need help with something? GitHub issues aren't for general support questions, but there are other venues you can try: https://wp-cli.org/#support
You can safely delete this comment.
-->
14 changes: 14 additions & 0 deletions templates/github-pull-request-template.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--
Thanks for submitting a pull request!
Here's an overview to our process:
1. One of the project committers will soon provide a code review.
2. You are expected to address the code review comments in a timely manner.
3. Please make sure to include functional tests for your changes.
4. The reviewing committer will merge your pull request as soon as it passes code review (and provided it fits within the scope of the project).
You can safely delete this comment.
-->

0 comments on commit fedf3ff

Please sign in to comment.