Skip to content

Commit 57454d3

Browse files
committed
Adding support for folder and a filter for registering custom repositories via filter
1 parent 9bcebb8 commit 57454d3

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

backends/class-phpcs-diff-svn.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,15 @@ function __construct( $repo, $options = array() ) {
3636
# Add new repos here. See details at the top of this file.
3737
}
3838

39+
$repositories = apply_filters( 'phpcs_diff_svn_repositories', array() );
40+
if ( true === is_array( $repositories ) && true === array_key_exists( $repo, $repositories ) ) {
41+
$this->repo_url = $repositories[$repo];
42+
}
43+
3944
$this->repo = $repo;
4045
}
4146

42-
public function get_diff( $end_revision, $start_revision = null, $options = array() ) {
47+
public function get_diff( $folder, $end_revision, $start_revision = null, $options = array() ) {
4348
$summarize = false;
4449
$xml = false;
4550
$ignore_space_change = false;
@@ -66,7 +71,7 @@ public function get_diff( $end_revision, $start_revision = null, $options = arra
6671
$start_revision = 1;
6772
}
6873

69-
$repo_url = esc_url_raw( trailingslashit( $this->repo_url ) );
74+
$repo_url = esc_url_raw( trailingslashit( $this->repo_url ) . urlencode( sanitize_title( $folder ) ) );
7075

7176
$diff = shell_exec(
7277
sprintf( 'svn diff %s --non-interactive --no-auth-cache --username %s --password %s -r %d:%d %s %s %s',

inc/class-phpcs-diff.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@ public function set_excluded_extensions( $excluded_exts ) {
6161
$this->excluded_extensions = $excluded_exts;
6262
}
6363

64-
public function run( $oldest_rev, $newest_rev ) {
64+
public function run( $oldest_rev, $newest_rev, $folder = '' ) {
6565

6666
$oldest_rev = absint( $oldest_rev );
6767
$newest_rev = absint( $newest_rev );
68+
$folder = sanitize_title( $folder );
6869

69-
$cache_key = md5( 'phpcs_' . $this->version_control->repo . $oldest_rev . $newest_rev );
70+
$cache_key = md5( 'phpcs_' . $this->version_control->repo . $folder . $oldest_rev . $newest_rev );
7071
$cache_group = 'vip-phpcs';
7172

7273
if ( true !== $this->nocache ) {
@@ -76,7 +77,7 @@ public function run( $oldest_rev, $newest_rev ) {
7677
}
7778
}
7879

79-
$diff = trim( $this->version_control->get_diff( $newest_rev, $oldest_rev, array( 'ignore-space-change' => true ) ) );
80+
$diff = trim( $this->version_control->get_diff( $folder, $newest_rev, $oldest_rev, array( 'ignore-space-change' => true ) ) );
8081

8182
$this->stop_the_insanity();
8283

@@ -109,7 +110,7 @@ public function run( $oldest_rev, $newest_rev ) {
109110
} else {
110111
$is_new_file = false;
111112
}
112-
$processed_file = $this->process_file( $repo . '/' . $filename, $oldest_rev, $newest_rev, $is_new_file );
113+
$processed_file = $this->process_file( $folder . '/' . $filename, $oldest_rev, $newest_rev, $is_new_file );
113114
if ( false === $processed_file || true === empty( $processed_file ) ) {
114115
continue;
115116
}

wp-cli-command.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,14 @@ class PHPCS_Diff_CLI_Command extends WP_CLI_Command {
3737
* [--excluded-exts=<excluded-exts>]
3838
* : Ignore specified extensions. Use comma for separating multiple extensions
3939
*
40+
* [--folder=<folder>]
41+
* : Process files in specific folder
42+
*
4043
* ## EXAMPLES
4144
* wp phpcs-diff --repo="hello-dolly" --start_revision=99998 --end_revision=100000
4245
*
4346
* @subcommand phpcs-diff
44-
* @synopsis --repo=<repo> --start_revision=<start-revision> --end_revision=<end-revision> [--standard=<standard>] [--format=<format>] [--nocache] [--ignore-diff-too-big] [--excluded-exts=<excluded-exts>]
47+
* @synopsis --repo=<repo> --start_revision=<start-revision> --end_revision=<end-revision> [--standard=<standard>] [--format=<format>] [--nocache] [--ignore-diff-too-big] [--excluded-exts=<excluded-exts>] [--folder=<folder>]
4548
*/
4649
public function __invoke( $args, $assoc_args ) {
4750

@@ -58,6 +61,11 @@ public function __invoke( $args, $assoc_args ) {
5861
if ( true === array_key_exists( 'excluded-exts', $assoc_args ) && false === empty( $assoc_args['excluded-exts'] ) ) {
5962
$excluded_exts = array_map( 'sanitize_text_field', explode( ',', $assoc_args['excluded-exts'] ) );
6063
}
64+
if ( true === array_key_exists( 'folder', $assoc_args ) ) {
65+
$folder = sanitize_title( $assoc_args['folder'] );
66+
} else {
67+
$folder = '';
68+
}
6169

6270
// @todo: replace SVN version control backend with any other parser you might want to use - eg.: git
6371
require_once( PHPCS_DIFF_PLUGIN_DIR . 'backends/class-phpcs-diff-svn.php' );
@@ -77,7 +85,7 @@ public function __invoke( $args, $assoc_args ) {
7785
if ( true === isset( $excluded_exts ) && false === empty( $excluded_exts ) && true === is_array( $excluded_exts ) ) {
7886
$phpcs->set_excluded_extensions( $excluded_exts );
7987
}
80-
$found_issues = $phpcs->run( $start_revision, $end_revision );
88+
$found_issues = $phpcs->run( $start_revision, $end_revision, $folder );
8189

8290
if ( is_wp_error( $found_issues ) ) {
8391
WP_CLI::error( $found_issues->get_error_message(), true );

0 commit comments

Comments
 (0)