Revision history for App-Codeowners.
+0.48 2020-01-21 10:13:14-07:00 MST7MDT
+ * Add rename_project and update_owners_by_project functions.
+ * No changes to the CLI.
+
0.47 2019-11-17 17:36:49-07:00 MST7MDT
* Configure git in unit tests to avoid unnecessary test failures.
* Compare long paths on win32 (thanks CPAN testers).
"provides" : {
"App::Codeowners" : {
"file" : "lib/App/Codeowners.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"App::Codeowners::Formatter" : {
"file" : "lib/App/Codeowners/Formatter.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"App::Codeowners::Formatter::CSV" : {
"file" : "lib/App/Codeowners/Formatter/CSV.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"App::Codeowners::Formatter::JSON" : {
"file" : "lib/App/Codeowners/Formatter/JSON.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"App::Codeowners::Formatter::String" : {
"file" : "lib/App/Codeowners/Formatter/String.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"App::Codeowners::Formatter::TSV" : {
"file" : "lib/App/Codeowners/Formatter/TSV.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"App::Codeowners::Formatter::Table" : {
"file" : "lib/App/Codeowners/Formatter/Table.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"App::Codeowners::Formatter::YAML" : {
"file" : "lib/App/Codeowners/Formatter/YAML.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"App::Codeowners::Options" : {
"file" : "lib/App/Codeowners/Options.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"App::Codeowners::Util" : {
"file" : "lib/App/Codeowners/Util.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"App::Codeowners::Util::Process" : {
"file" : "lib/App/Codeowners/Util.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"File::Codeowners" : {
"file" : "lib/File/Codeowners.pm",
- "version" : "0.47"
+ "version" : "0.48"
},
"Test::File::Codeowners" : {
"file" : "lib/Test/File/Codeowners.pm",
- "version" : "0.47"
+ "version" : "0.48"
}
},
"release_status" : "stable",
"web" : "https://github.com/chazmcgarvey/git-codeowners"
}
},
- "version" : "0.47",
+ "version" : "0.48",
"x_authority" : "cpan:CCM",
"x_generated_by_perl" : "v5.28.0",
"x_serialization_backend" : "Cpanel::JSON::XS version 4.15"
provides:
App::Codeowners:
file: lib/App/Codeowners.pm
- version: '0.47'
+ version: '0.48'
App::Codeowners::Formatter:
file: lib/App/Codeowners/Formatter.pm
- version: '0.47'
+ version: '0.48'
App::Codeowners::Formatter::CSV:
file: lib/App/Codeowners/Formatter/CSV.pm
- version: '0.47'
+ version: '0.48'
App::Codeowners::Formatter::JSON:
file: lib/App/Codeowners/Formatter/JSON.pm
- version: '0.47'
+ version: '0.48'
App::Codeowners::Formatter::String:
file: lib/App/Codeowners/Formatter/String.pm
- version: '0.47'
+ version: '0.48'
App::Codeowners::Formatter::TSV:
file: lib/App/Codeowners/Formatter/TSV.pm
- version: '0.47'
+ version: '0.48'
App::Codeowners::Formatter::Table:
file: lib/App/Codeowners/Formatter/Table.pm
- version: '0.47'
+ version: '0.48'
App::Codeowners::Formatter::YAML:
file: lib/App/Codeowners/Formatter/YAML.pm
- version: '0.47'
+ version: '0.48'
App::Codeowners::Options:
file: lib/App/Codeowners/Options.pm
- version: '0.47'
+ version: '0.48'
App::Codeowners::Util:
file: lib/App/Codeowners/Util.pm
- version: '0.47'
+ version: '0.48'
App::Codeowners::Util::Process:
file: lib/App/Codeowners/Util.pm
- version: '0.47'
+ version: '0.48'
File::Codeowners:
file: lib/File/Codeowners.pm
- version: '0.47'
+ version: '0.48'
Test::File::Codeowners:
file: lib/Test/File/Codeowners.pm
- version: '0.47'
+ version: '0.48'
recommends:
Pod::Usage: '0'
Term::Detect::Software: '0'
bugtracker: https://github.com/chazmcgarvey/git-codeowners/issues
homepage: https://github.com/chazmcgarvey/git-codeowners
repository: https://github.com/chazmcgarvey/git-codeowners.git
-version: '0.47'
+version: '0.48'
x_authority: cpan:CCM
x_generated_by_perl: v5.28.0
x_serialization_backend: 'YAML::Tiny version 1.73'
"Test::Exit" => 0,
"Test::More" => 0
},
- "VERSION" => "0.47",
+ "VERSION" => "0.48",
"test" => {
"TESTS" => "t/*.t"
}
VERSION
- version 0.47
+ version 0.48
SYNOPSIS
use App::Codeowners;
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
App::Codeowners->main(@ARGV);
=head1 VERSION
-version 0.47
+version 0.48
=head1 SYNOPSIS
use File::Codeowners;
use Path::Tiny;
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
sub main {
my $template = <<'END';
This file shows mappings between subdirs/files and the individuals and
teams who own them. You can read this file yourself or use tools to query it,
- so you can quickly determine who to speak with or send pull requests to. ❤️
+ so you can quickly determine who to speak with or send pull requests to.
Simply write a gitignore pattern followed by one or more names/emails/groups.
Examples:
=head1 VERSION
-version 0.47
+version 0.48
=head1 DESCRIPTION
use warnings;
use strict;
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
use Module::Load;
=head1 VERSION
-version 0.47
+version 0.48
=head1 SYNOPSIS
use warnings;
use strict;
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
use parent 'App::Codeowners::Formatter';
=head1 VERSION
-version 0.47
+version 0.48
=head1 DESCRIPTION
use warnings;
use strict;
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
use parent 'App::Codeowners::Formatter';
=head1 VERSION
-version 0.47
+version 0.48
=head1 DESCRIPTION
use warnings;
use strict;
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
use parent 'App::Codeowners::Formatter';
=head1 VERSION
-version 0.47
+version 0.48
=head1 DESCRIPTION
use warnings;
use strict;
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
use parent 'App::Codeowners::Formatter::CSV';
=head1 VERSION
-version 0.47
+version 0.48
=head1 DESCRIPTION
use warnings;
use strict;
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
use parent 'App::Codeowners::Formatter';
=head1 VERSION
-version 0.47
+version 0.48
=head1 DESCRIPTION
use warnings;
use strict;
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
use parent 'App::Codeowners::Formatter';
=head1 VERSION
-version 0.47
+version 0.48
=head1 DESCRIPTION
use Getopt::Long 2.39 ();
use Path::Tiny;
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
sub pod2usage {
eval { require Pod::Usage };
=head1 VERSION
-version 0.47
+version 0.48
=head1 METHODS
zip
);
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
sub find_nearest_codeowners {
=head1 VERSION
-version 0.47
+version 0.48
=head1 DESCRIPTION
use Scalar::Util qw(openhandle);
use Text::Gitignore qw(build_gitignore_matcher);
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
sub _croak { require Carp; Carp::croak(@_); }
sub _usage { _croak("Usage: @_\n") }
}
elsif ($line =~ /^\h*#(.*)/) {
my $comment = $1;
+ my $project;
if ($comment =~ /^\h*Project:\h*(.+?)\h*$/i) {
- $current_project = $1 || undef;
+ $project = $current_project = $1 || undef;
}
$lines[$lineno] = {
comment => $comment,
+ $project ? (project => $project) : (),
};
}
elsif ($line =~ /^\h*$/) {
$self->_clear;
+ my $count = 0;
+
for my $line (@{$self->_lines}) {
next if !$line->{pattern};
next if $pattern ne $line->{pattern};
$line->{owners} = [@$owners];
+ ++$count;
+ }
+
+ return $count;
+}
+
+
+sub update_owners_by_project {
+ my $self = shift;
+ my $project = shift;
+ my $owners = shift;
+ $project && $owners or _usage(q{$codeowners->update_owners_by_project($project => \@owners)});
+
+ $owners = [$owners] if ref($owners) ne 'ARRAY';
+
+ $self->_clear;
+
+ my $count = 0;
+
+ for my $line (@{$self->_lines}) {
+ next if !$line->{project} || !$line->{owners};
+ next if $project ne $line->{project};
+ $line->{owners} = [@$owners];
+ ++$count;
}
+
+ return $count;
+}
+
+
+sub rename_project {
+ my $self = shift;
+ my $old_project = shift;
+ my $new_project = shift;
+ $old_project && $new_project or _usage(q{$codeowners->rename_project($project => $new_project)});
+
+ $self->_clear;
+
+ my $count = 0;
+
+ for my $line (@{$self->_lines}) {
+ next if !exists $line->{project} || $old_project ne $line->{project};
+ $line->{project} = $new_project;
+ $line->{comment} = " Project: $new_project" if exists $line->{comment};
+ ++$count;
+ }
+
+ return $count;
}
=head1 VERSION
-version 0.47
+version 0.48
=head1 METHODS
Nothing happens if the file does not already have at least one such pattern.
+=head2 update_owners_by_project
+
+ $codeowners->update_owners_by_project($project => \@new_owners);
+
+Set a new set of owners for all patterns under the given project.
+
+Nothing happens if the file does not have a project with the given name.
+
+=head2 rename_project
+
+ $codeowners->rename_project($old_name => $new_name);
+
+Rename a project.
+
+Nothing happens if the file does not have a project with the old name.
+
=head2 append
$codeowners->append(comment => $str);
use File::Codeowners;
use Test::Builder;
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
my $Test = Test::Builder->new;
=head1 VERSION
-version 0.47
+version 0.48
=head1 SYNOPSIS
like($@, qr/^Parse error on line 1/, 'parse error');
};
+subtest 'handling projects', sub {
+ my $file = File::Codeowners->parse("$Bin/samples/kitchensink.CODEOWNERS");
+ my $r;
+
+ is_deeply($r = $file->projects, [
+ 'Transportation',
+ ], 'projects listed') or diag explain $r;
+
+ $file->rename_project('Transportation', 'Getting Around');
+ is_deeply($r = $file->projects, [
+ 'Getting Around',
+ ], 'project renamed') or diag explain $r;
+
+ is_deeply($r = [@{$file->_lines}[-3 .. -1]], [
+ {comment => ' Project: Getting Around', project => 'Getting Around'},
+ {},
+ {pattern => '/vehicles/**/batmobile.cad', 'owners' => ['@"Lucius Fox"'], project => 'Getting Around'},
+ ], 'renaming project properly modifies lines') or diag explain $r;
+
+ $file->update_owners_by_project('Getting Around', '@twoface');
+ ok( scalar grep { $_ eq '@twoface' } @{$file->owners}, 'updating owner adds new owner');
+ ok(!scalar grep { $_ eq '@"Lucius Fox"' } @{$file->owners}, 'updating owner removes old owner');
+};
+
subtest 'editing and writing files', sub {
my $file = File::Codeowners->parse("$Bin/samples/basic.CODEOWNERS");
my $r;