Skip to content

Commit 682874d

Browse files
Introduce wp scaffold package-github to scaffold GitHub templates
1 parent 77552bd commit 682874d

8 files changed

+137
-1
lines changed

.github/ISSUE_TEMPLATE

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!--
2+
3+
Thanks for creating a new issue!
4+
5+
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/
6+
7+
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
8+
9+
You can safely delete this comment.
10+
11+
-->

.github/PULL_REQUEST_TEMPLATE

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!--
2+
3+
Thanks for submitting a pull request!
4+
5+
Here's an overview to our process:
6+
7+
1. One of the project committers will soon provide a code review.
8+
2. You are expected to address the code review comments in a timely manner.
9+
3. Please make sure to include functional tests for your changes.
10+
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).
11+
12+
You can safely delete this comment.
13+
14+
-->

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"commands": [
3434
"scaffold package",
3535
"scaffold package-tests",
36-
"scaffold package-readme"
36+
"scaffold package-readme",
37+
"scaffold package-github"
3738
]
3839
}
3940
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Feature: Scaffold GitHub configuration for an existing package
2+
3+
Scenario: Fails when invalid package directory provided
4+
Given an empty directory
5+
6+
When I run `wp package path`
7+
Then save STDOUT as {PACKAGE_PATH}
8+
9+
When I try `wp scaffold package-github {PACKAGE_PATH}/local/wp-cli/default-github`
10+
Then STDERR should be:
11+
"""
12+
Error: Invalid package directory. composer.json file must be present.
13+
"""
14+
15+
Scenario: Scaffold GitHub configuration based on defaults
16+
Given an empty directory
17+
18+
When I run `wp package path`
19+
Then save STDOUT as {PACKAGE_PATH}
20+
21+
When I run `wp scaffold package wp-cli/default-github`
22+
Then the {PACKAGE_PATH}/local/wp-cli/default-github directory should exist
23+
24+
When I run `wp scaffold package-github {PACKAGE_PATH}/local/wp-cli/default-github`
25+
Then STDOUT should contain:
26+
"""
27+
Success: Created package GitHub configuration.
28+
"""
29+
And the {PACKAGE_PATH}/local/wp-cli/default-github/.github directory should exist
30+
And the {PACKAGE_PATH}/local/wp-cli/default-github/.github/ISSUE_TEMPLATE file should contain:
31+
"""
32+
Thanks for creating a new issue!
33+
"""
34+
And the {PACKAGE_PATH}/local/wp-cli/default-github/.github/PULL_REQUEST_TEMPLATE file should contain:
35+
"""
36+
Thanks for submitting a pull request!
37+
"""

scaffold-package-command.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
WP_CLI::add_command( 'scaffold package', array( 'WP_CLI\ScaffoldPackageCommand', 'package' ) );
1414
WP_CLI::add_command( 'scaffold package-readme', array( 'WP_CLI\ScaffoldPackageCommand', 'package_readme' ) );
1515
WP_CLI::add_command( 'scaffold package-tests', array( 'WP_CLI\ScaffoldPackageCommand', 'package_tests' ) );
16+
WP_CLI::add_command( 'scaffold package-github', array( 'WP_CLI\ScaffoldPackageCommand', 'package_github' ) );
1617
};
1718

1819
// Only use command hooks in versions that support them.

src/ScaffoldPackageCommand.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,53 @@ public function package_readme( $args, $assoc_args ) {
366366
}
367367
}
368368

369+
/**
370+
* Generate GitHub configuration files for your command.
371+
*
372+
* Creates a variety of files to better manage your project on GitHub. These
373+
* files include:
374+
*
375+
* * `.github/ISSUE_TEMPLATE` - Text displayed when a user opens a new issue.
376+
* * `.github/PULL_REQUEST_TEMPLATE` - Text displayed when a user submits a pull request.
377+
*
378+
* ## OPTIONS
379+
*
380+
* <dir>
381+
* : The package directory to generate GitHub configuration for.
382+
*
383+
* [--force]
384+
* : Overwrite files that already exist.
385+
*
386+
* @when before_wp_load
387+
* @subcommand package-github
388+
*/
389+
public function package_github( $args, $assoc_args ) {
390+
list( $package_dir ) = $args;
391+
392+
if ( is_file( $package_dir ) ) {
393+
$package_dir = dirname( $package_dir );
394+
} else if ( is_dir( $package_dir ) ) {
395+
$package_dir = rtrim( $package_dir, '/' );
396+
}
397+
398+
if ( ! is_dir( $package_dir ) || ! file_exists( $package_dir . '/composer.json' ) ) {
399+
WP_CLI::error( "Invalid package directory. composer.json file must be present." );
400+
}
401+
$force = Utils\get_flag_value( $assoc_args, 'force' );
402+
$template_path = dirname( dirname( __FILE__ ) ) . '/templates';
403+
404+
$create_files = array(
405+
"{$package_dir}/.github/ISSUE_TEMPLATE" => Utils\mustache_render( "{$template_path}/github-issue-template.mustache" ),
406+
"{$package_dir}/.github/PULL_REQUEST_TEMPLATE" => Utils\mustache_render( "{$template_path}/github-pull-request-template.mustache" ),
407+
);
408+
$files_written = $this->create_files( $create_files, $force );
409+
if ( empty( $files_written ) ) {
410+
WP_CLI::log( 'Package GitHub configuration generation skipped.' );
411+
} else {
412+
WP_CLI::success( 'Created package GitHub configuration.' );
413+
}
414+
}
415+
369416
/**
370417
* Generate files needed for writing Behat tests for your command.
371418
*
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!--
2+
3+
Thanks for creating a new issue!
4+
5+
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/
6+
7+
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
8+
9+
You can safely delete this comment.
10+
11+
-->
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!--
2+
3+
Thanks for submitting a pull request!
4+
5+
Here's an overview to our process:
6+
7+
1. One of the project committers will soon provide a code review.
8+
2. You are expected to address the code review comments in a timely manner.
9+
3. Please make sure to include functional tests for your changes.
10+
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).
11+
12+
You can safely delete this comment.
13+
14+
-->

0 commit comments

Comments
 (0)