From 2ce4094a9656c27b2b83442e11b86e44306525bf Mon Sep 17 00:00:00 2001 From: Charles McGarvey Date: Sun, 22 Mar 2020 01:32:07 -0600 Subject: [PATCH] Version 0.49 --- Changes | 6 ++- MANIFEST | 2 +- META.json | 33 ++++++++-------- META.yml | 31 +++++++-------- Makefile.PL | 4 +- README | 2 +- bin/git-codeowners | 4 +- lib/App/Codeowners.pm | 7 ++-- lib/App/Codeowners/Formatter.pm | 4 +- lib/App/Codeowners/Formatter/CSV.pm | 7 ++-- lib/App/Codeowners/Formatter/JSON.pm | 6 +-- lib/App/Codeowners/Formatter/String.pm | 7 ++-- lib/App/Codeowners/Formatter/TSV.pm | 4 +- lib/App/Codeowners/Formatter/Table.pm | 7 ++-- lib/App/Codeowners/Formatter/YAML.pm | 4 +- lib/App/Codeowners/Options.pm | 8 +++- lib/App/Codeowners/Util.pm | 4 +- lib/File/Codeowners.pm | 53 +++++++++++++++++++++----- lib/Test/File/Codeowners.pm | 4 +- 19 files changed, 119 insertions(+), 78 deletions(-) diff --git a/Changes b/Changes index dc5ce0f..5b4e5ce 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,11 @@ Revision history for App-Codeowners. +0.49 2020-03-22 01:30:54-06:00 MST7MDT + * Fix an encoding issue with the YAML formatter. + * Add rename_owner methods. + 0.48 2020-01-21 10:13:14-07:00 MST7MDT - * Add rename_project and update_owners_by_project functions. + * Add rename_project and update_owners_by_project methods. * No changes to the CLI. 0.47 2019-11-17 17:36:49-07:00 MST7MDT diff --git a/MANIFEST b/MANIFEST index 8d701ef..0db697f 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1,4 +1,4 @@ -# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.012. +# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.014. Changes LICENSE MANIFEST diff --git a/META.json b/META.json index cbfbafd..10d7765 100644 --- a/META.json +++ b/META.json @@ -4,7 +4,7 @@ "Charles McGarvey " ], "dynamic_config" : 0, - "generated_by" : "Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010", + "generated_by" : "Dist::Zilla version 6.014, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], @@ -114,55 +114,55 @@ "provides" : { "App::Codeowners" : { "file" : "lib/App/Codeowners.pm", - "version" : "0.48" + "version" : "0.49" }, "App::Codeowners::Formatter" : { "file" : "lib/App/Codeowners/Formatter.pm", - "version" : "0.48" + "version" : "0.49" }, "App::Codeowners::Formatter::CSV" : { "file" : "lib/App/Codeowners/Formatter/CSV.pm", - "version" : "0.48" + "version" : "0.49" }, "App::Codeowners::Formatter::JSON" : { "file" : "lib/App/Codeowners/Formatter/JSON.pm", - "version" : "0.48" + "version" : "0.49" }, "App::Codeowners::Formatter::String" : { "file" : "lib/App/Codeowners/Formatter/String.pm", - "version" : "0.48" + "version" : "0.49" }, "App::Codeowners::Formatter::TSV" : { "file" : "lib/App/Codeowners/Formatter/TSV.pm", - "version" : "0.48" + "version" : "0.49" }, "App::Codeowners::Formatter::Table" : { "file" : "lib/App/Codeowners/Formatter/Table.pm", - "version" : "0.48" + "version" : "0.49" }, "App::Codeowners::Formatter::YAML" : { "file" : "lib/App/Codeowners/Formatter/YAML.pm", - "version" : "0.48" + "version" : "0.49" }, "App::Codeowners::Options" : { "file" : "lib/App/Codeowners/Options.pm", - "version" : "0.48" + "version" : "0.49" }, "App::Codeowners::Util" : { "file" : "lib/App/Codeowners/Util.pm", - "version" : "0.48" + "version" : "0.49" }, "App::Codeowners::Util::Process" : { "file" : "lib/App/Codeowners/Util.pm", - "version" : "0.48" + "version" : "0.49" }, "File::Codeowners" : { "file" : "lib/File/Codeowners.pm", - "version" : "0.48" + "version" : "0.49" }, "Test::File::Codeowners" : { "file" : "lib/Test/File/Codeowners.pm", - "version" : "0.48" + "version" : "0.49" } }, "release_status" : "stable", @@ -177,9 +177,10 @@ "web" : "https://github.com/chazmcgarvey/git-codeowners" } }, - "version" : "0.48", + "version" : "0.49", "x_authority" : "cpan:CCM", "x_generated_by_perl" : "v5.28.0", - "x_serialization_backend" : "Cpanel::JSON::XS version 4.15" + "x_serialization_backend" : "Cpanel::JSON::XS version 4.15", + "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" } diff --git a/META.yml b/META.yml index e4aa077..30c0c55 100644 --- a/META.yml +++ b/META.yml @@ -15,7 +15,7 @@ build_requires: configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 -generated_by: 'Dist::Zilla version 6.012, CPAN::Meta::Converter version 2.150010' +generated_by: 'Dist::Zilla version 6.014, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -31,43 +31,43 @@ no_index: provides: App::Codeowners: file: lib/App/Codeowners.pm - version: '0.48' + version: '0.49' App::Codeowners::Formatter: file: lib/App/Codeowners/Formatter.pm - version: '0.48' + version: '0.49' App::Codeowners::Formatter::CSV: file: lib/App/Codeowners/Formatter/CSV.pm - version: '0.48' + version: '0.49' App::Codeowners::Formatter::JSON: file: lib/App/Codeowners/Formatter/JSON.pm - version: '0.48' + version: '0.49' App::Codeowners::Formatter::String: file: lib/App/Codeowners/Formatter/String.pm - version: '0.48' + version: '0.49' App::Codeowners::Formatter::TSV: file: lib/App/Codeowners/Formatter/TSV.pm - version: '0.48' + version: '0.49' App::Codeowners::Formatter::Table: file: lib/App/Codeowners/Formatter/Table.pm - version: '0.48' + version: '0.49' App::Codeowners::Formatter::YAML: file: lib/App/Codeowners/Formatter/YAML.pm - version: '0.48' + version: '0.49' App::Codeowners::Options: file: lib/App/Codeowners/Options.pm - version: '0.48' + version: '0.49' App::Codeowners::Util: file: lib/App/Codeowners/Util.pm - version: '0.48' + version: '0.49' App::Codeowners::Util::Process: file: lib/App/Codeowners/Util.pm - version: '0.48' + version: '0.49' File::Codeowners: file: lib/File/Codeowners.pm - version: '0.48' + version: '0.49' Test::File::Codeowners: file: lib/Test/File/Codeowners.pm - version: '0.48' + version: '0.49' recommends: Pod::Usage: '0' Term::Detect::Software: '0' @@ -93,7 +93,8 @@ resources: 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.48' +version: '0.49' x_authority: cpan:CCM x_generated_by_perl: v5.28.0 x_serialization_backend: 'YAML::Tiny version 1.73' +x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' diff --git a/Makefile.PL b/Makefile.PL index 100341a..ca1bb2b 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -1,4 +1,4 @@ -# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.012. +# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.014. use strict; use warnings; @@ -47,7 +47,7 @@ my %WriteMakefileArgs = ( "Test::Exit" => 0, "Test::More" => 0 }, - "VERSION" => "0.48", + "VERSION" => "0.49", "test" => { "TESTS" => "t/*.t" } diff --git a/README b/README index 9d0b26e..4d522a7 100644 --- a/README +++ b/README @@ -4,7 +4,7 @@ NAME VERSION - version 0.48 + version 0.49 SYNOPSIS diff --git a/bin/git-codeowners b/bin/git-codeowners index 178f874..9fffa25 100755 --- a/bin/git-codeowners +++ b/bin/git-codeowners @@ -10,7 +10,7 @@ use strict; use App::Codeowners; -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION App::Codeowners->main(@ARGV); @@ -26,7 +26,7 @@ git-codeowners - A tool for managing CODEOWNERS files =head1 VERSION -version 0.48 +version 0.49 =head1 SYNOPSIS diff --git a/lib/App/Codeowners.pm b/lib/App/Codeowners.pm index 5715354..f33dfb8 100644 --- a/lib/App/Codeowners.pm +++ b/lib/App/Codeowners.pm @@ -10,11 +10,10 @@ use App::Codeowners::Formatter; use App::Codeowners::Options; use App::Codeowners::Util qw(find_codeowners_in_directory run_git git_ls_files git_toplevel); use Color::ANSI::Util 0.03 qw(ansifg); -use Encode qw(encode); use File::Codeowners; use Path::Tiny; -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION sub main { @@ -29,6 +28,8 @@ sub main { my $command = $opts->command; my $handler = $self->can("_command_$command") or die "Unknown command: $command\n"; + + binmode(STDOUT, ':encoding(UTF-8)'); $self->$handler($opts); exit 0; @@ -218,7 +219,7 @@ App::Codeowners - A tool for managing CODEOWNERS files =head1 VERSION -version 0.48 +version 0.49 =head1 DESCRIPTION diff --git a/lib/App/Codeowners/Formatter.pm b/lib/App/Codeowners/Formatter.pm index efb516c..5c908d4 100644 --- a/lib/App/Codeowners/Formatter.pm +++ b/lib/App/Codeowners/Formatter.pm @@ -5,7 +5,7 @@ package App::Codeowners::Formatter; use warnings; use strict; -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION use Module::Load; @@ -120,7 +120,7 @@ App::Codeowners::Formatter - Base class for formatting codeowners output =head1 VERSION -version 0.48 +version 0.49 =head1 SYNOPSIS diff --git a/lib/App/Codeowners/Formatter/CSV.pm b/lib/App/Codeowners/Formatter/CSV.pm index 3913700..b4aff63 100644 --- a/lib/App/Codeowners/Formatter/CSV.pm +++ b/lib/App/Codeowners/Formatter/CSV.pm @@ -5,12 +5,11 @@ package App::Codeowners::Formatter::CSV; use warnings; use strict; -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION use parent 'App::Codeowners::Formatter'; use App::Codeowners::Util qw(stringify); -use Encode qw(encode); sub start { my $self = shift; @@ -22,7 +21,7 @@ sub stream { my $self = shift; my $result = shift; - $self->text_csv->print($self->handle, [map { encode('UTF-8', stringify($_)) } @$result]); + $self->text_csv->print($self->handle, [map { stringify($_) } @$result]); } @@ -63,7 +62,7 @@ App::Codeowners::Formatter::CSV - Format codeowners output as comma-separated va =head1 VERSION -version 0.48 +version 0.49 =head1 DESCRIPTION diff --git a/lib/App/Codeowners/Formatter/JSON.pm b/lib/App/Codeowners/Formatter/JSON.pm index a8a4509..e4d8332 100644 --- a/lib/App/Codeowners/Formatter/JSON.pm +++ b/lib/App/Codeowners/Formatter/JSON.pm @@ -5,7 +5,7 @@ package App::Codeowners::Formatter::JSON; use warnings; use strict; -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION use parent 'App::Codeowners::Formatter'; @@ -21,7 +21,7 @@ sub finish { my %options; $options{pretty} = 1 if lc($self->format) eq 'pretty'; - my $json = JSON::MaybeXS->new(canonical => 1, utf8 => 1, %options); + my $json = JSON::MaybeXS->new(canonical => 1, %options); my $columns = $self->columns; $results = [map { +{zip @$columns, @$_} } @$results]; @@ -42,7 +42,7 @@ App::Codeowners::Formatter::JSON - Format codeowners output as JSON =head1 VERSION -version 0.48 +version 0.49 =head1 DESCRIPTION diff --git a/lib/App/Codeowners/Formatter/String.pm b/lib/App/Codeowners/Formatter/String.pm index c613b47..14b07a4 100644 --- a/lib/App/Codeowners/Formatter/String.pm +++ b/lib/App/Codeowners/Formatter/String.pm @@ -5,13 +5,12 @@ package App::Codeowners::Formatter::String; use warnings; use strict; -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION use parent 'App::Codeowners::Formatter'; use App::Codeowners::Util qw(stringf zip); use Color::ANSI::Util 0.03 qw(ansifg); -use Encode qw(encode); sub stream { my $self = shift; @@ -27,7 +26,7 @@ sub stream { ); my $text = stringf($self->format, %info); - print { $self->handle } encode('UTF-8', $text), "\n"; + print { $self->handle } $text, "\n"; } sub _expand_filter_args { @@ -136,7 +135,7 @@ App::Codeowners::Formatter::String - Format codeowners output using printf-like =head1 VERSION -version 0.48 +version 0.49 =head1 DESCRIPTION diff --git a/lib/App/Codeowners/Formatter/TSV.pm b/lib/App/Codeowners/Formatter/TSV.pm index bcc90aa..2ba0f53 100644 --- a/lib/App/Codeowners/Formatter/TSV.pm +++ b/lib/App/Codeowners/Formatter/TSV.pm @@ -5,7 +5,7 @@ package App::Codeowners::Formatter::TSV; use warnings; use strict; -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION use parent 'App::Codeowners::Formatter::CSV'; @@ -25,7 +25,7 @@ App::Codeowners::Formatter::TSV - Format codeowners output as tab-separated valu =head1 VERSION -version 0.48 +version 0.49 =head1 DESCRIPTION diff --git a/lib/App/Codeowners/Formatter/Table.pm b/lib/App/Codeowners/Formatter/Table.pm index cba5147..2309e6a 100644 --- a/lib/App/Codeowners/Formatter/Table.pm +++ b/lib/App/Codeowners/Formatter/Table.pm @@ -5,12 +5,11 @@ package App::Codeowners::Formatter::Table; use warnings; use strict; -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION use parent 'App::Codeowners::Formatter'; use App::Codeowners::Util qw(stringify); -use Encode qw(encode); sub finish { my $self = shift; @@ -23,7 +22,7 @@ sub finish { rows => [$self->columns, map { [map { stringify($_) } @$_] } @$results], backend => $ENV{PERL_TEXT_TABLE}, ); - print { $self->handle } encode('UTF-8', $table); + print { $self->handle } $table; } 1; @@ -40,7 +39,7 @@ App::Codeowners::Formatter::Table - Format codeowners output as a table =head1 VERSION -version 0.48 +version 0.49 =head1 DESCRIPTION diff --git a/lib/App/Codeowners/Formatter/YAML.pm b/lib/App/Codeowners/Formatter/YAML.pm index 16ef44d..079eae5 100644 --- a/lib/App/Codeowners/Formatter/YAML.pm +++ b/lib/App/Codeowners/Formatter/YAML.pm @@ -5,7 +5,7 @@ package App::Codeowners::Formatter::YAML; use warnings; use strict; -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION use parent 'App::Codeowners::Formatter'; @@ -36,7 +36,7 @@ App::Codeowners::Formatter::YAML - Format codeowners output as YAML =head1 VERSION -version 0.48 +version 0.49 =head1 DESCRIPTION diff --git a/lib/App/Codeowners/Options.pm b/lib/App/Codeowners/Options.pm index 0cfdf4b..db7261e 100644 --- a/lib/App/Codeowners/Options.pm +++ b/lib/App/Codeowners/Options.pm @@ -5,10 +5,11 @@ use v5.10.1; use warnings; use strict; +use Encode qw(decode); use Getopt::Long 2.39 (); use Path::Tiny; -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION sub pod2usage { eval { require Pod::Usage }; @@ -82,6 +83,9 @@ sub new { my $class = shift; my @args = @_; + # assume UTF-8 args if non-ASCII + @args = map { decode('UTF-8', $_) } @args if grep { /\P{ASCII}/ } @args; + my $self = bless {}, $class; my @args_copy = @args; @@ -299,7 +303,7 @@ App::Codeowners::Options - Getopt and shell completion for App::Codeowners =head1 VERSION -version 0.48 +version 0.49 =head1 METHODS diff --git a/lib/App/Codeowners/Util.pm b/lib/App/Codeowners/Util.pm index 8a0b886..57e154d 100644 --- a/lib/App/Codeowners/Util.pm +++ b/lib/App/Codeowners/Util.pm @@ -23,7 +23,7 @@ our @EXPORT_OK = qw( zip ); -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION sub find_nearest_codeowners { @@ -280,7 +280,7 @@ App::Codeowners::Util - Grab bag of utility subs for Codeowners modules =head1 VERSION -version 0.48 +version 0.49 =head1 DESCRIPTION diff --git a/lib/File/Codeowners.pm b/lib/File/Codeowners.pm index ee50d99..183208b 100644 --- a/lib/File/Codeowners.pm +++ b/lib/File/Codeowners.pm @@ -10,7 +10,7 @@ use Path::Tiny 0.089; use Scalar::Util qw(openhandle); use Text::Gitignore qw(build_gitignore_matcher); -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION sub _croak { require Carp; Carp::croak(@_); } sub _usage { _croak("Usage: @_\n") } @@ -137,31 +137,33 @@ sub write_to_filepath { my $self = shift; my $path = shift or _usage(q{$codeowners->write_to_filepath($filepath)}); - path($path)->spew_utf8([map { "$_\n" } @{$self->write_to_array('')}]); + path($path)->spew_utf8([map { "$_\n" } @{$self->write_to_array}]); } sub write_to_fh { - my $self = shift; - my $fh = shift or _usage(q{$codeowners->write_to_fh($fh)}); + my $self = shift; + my $fh = shift or _usage(q{$codeowners->write_to_fh($fh)}); + my $charset = shift; - for my $line (@{$self->write_to_array}) { + for my $line (@{$self->write_to_array($charset)}) { print $fh "$line\n"; } } sub write_to_string { - my $self = shift; + my $self = shift; + my $charset = shift; - my $str = join("\n", @{$self->write_to_array}) . "\n"; + my $str = join("\n", @{$self->write_to_array($charset)}) . "\n"; return \$str; } sub write_to_array { my $self = shift; - my $charset = shift // 'UTF-8'; + my $charset = shift; my @format; @@ -187,7 +189,7 @@ sub write_to_array { } } - if ($charset) { + if (defined $charset) { $_ = encode($charset, $_) for @format; } return \@format; @@ -316,6 +318,29 @@ sub update_owners_by_project { } +sub rename_owner { + my $self = shift; + my $old_owner = shift; + my $new_owner = shift; + $old_owner && $new_owner or _usage(q{$codeowners->rename_owner($owner => $new_owner)}); + + $self->_clear; + + my $count = 0; + + for my $line (@{$self->_lines}) { + next if !exists $line->{owners}; + for (my $i = 0; $i < @{$line->{owners}}; ++$i) { + next if $line->{owners}[$i] ne $old_owner; + $line->{owners}[$i] = $new_owner; + ++$count; + } + } + + return $count; +} + + sub rename_project { my $self = shift; my $old_project = shift; @@ -405,7 +430,7 @@ File::Codeowners - Read and write CODEOWNERS files =head1 VERSION -version 0.48 +version 0.49 =head1 METHODS @@ -525,6 +550,14 @@ 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_owner + + $codeowners->rename_owner($old_name => $new_name); + +Rename an owner. + +Nothing happens if the file does not have an owner with the old name. + =head2 rename_project $codeowners->rename_project($old_name => $new_name); diff --git a/lib/Test/File/Codeowners.pm b/lib/Test/File/Codeowners.pm index 7d537c2..0679e6b 100644 --- a/lib/Test/File/Codeowners.pm +++ b/lib/Test/File/Codeowners.pm @@ -10,7 +10,7 @@ use Encode qw(encode); use File::Codeowners; use Test::Builder; -our $VERSION = '0.48'; # VERSION +our $VERSION = '0.49'; # VERSION my $Test = Test::Builder->new; @@ -88,7 +88,7 @@ Test::File::Codeowners - Write tests for CODEOWNERS files =head1 VERSION -version 0.48 +version 0.49 =head1 SYNOPSIS -- 2.45.2