]> Dogcows Code - chaz/git-codeowners/commitdiff
Version 0.49
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 22 Mar 2020 07:32:07 +0000 (01:32 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 22 Mar 2020 07:32:07 +0000 (01:32 -0600)
19 files changed:
Changes
MANIFEST
META.json
META.yml
Makefile.PL
README
bin/git-codeowners
lib/App/Codeowners.pm
lib/App/Codeowners/Formatter.pm
lib/App/Codeowners/Formatter/CSV.pm
lib/App/Codeowners/Formatter/JSON.pm
lib/App/Codeowners/Formatter/String.pm
lib/App/Codeowners/Formatter/TSV.pm
lib/App/Codeowners/Formatter/Table.pm
lib/App/Codeowners/Formatter/YAML.pm
lib/App/Codeowners/Options.pm
lib/App/Codeowners/Util.pm
lib/File/Codeowners.pm
lib/Test/File/Codeowners.pm

diff --git a/Changes b/Changes
index dc5ce0fad0bdb2148d81ee5f9134e438e15f80af..5b4e5ce496010b5113500b3742522cc5a150a313 100644 (file)
--- 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
index 8d701ef2081eb900a338c21b67b0981217bb9f5e..0db697f2f740b789c4414774b6b1ee4b784a2892 100644 (file)
--- 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
index cbfbafd0db85877482ce01f96c8d806672eed0f9..10d7765a5ce03b1a8800a8123cda94a3bd03dd3e 100644 (file)
--- a/META.json
+++ b/META.json
@@ -4,7 +4,7 @@
       "Charles McGarvey <chazmcgarvey@brokenzipper.com>"
    ],
    "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"
    ],
    "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",
          "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"
 }
 
index e4aa077026f948ea5dbc063b945478183e1aa342..30c0c5556261bf336524e0b39d2eaf70251daa48 100644 (file)
--- 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'
index 100341ad8b56c99ad560894660ec120b43d1f513..ca1bb2b750cdcd4fcc40bb4a95563020c52c0e53 100644 (file)
@@ -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 9d0b26e31f7484bf0cd7defda7b337aaa9addd72..4d522a7a39c59878dbe33be97afcaa1cb441bd87 100644 (file)
--- a/README
+++ b/README
@@ -4,7 +4,7 @@ NAME
 
 VERSION
 
-    version 0.48
+    version 0.49
 
 SYNOPSIS
 
index 178f874cb8e8d98d00cf5ae85bd753309a5938be..9fffa250102fb82ef222563dd9d08a5f29677004 100755 (executable)
@@ -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
 
index 5715354c8a6cff9a47bcfb6f5833156d97d08e1c..f33dfb820f827841bfab5b18c878086b9943828d 100644 (file)
@@ -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
 
index efb516cabd01d05aec2e5d5d61953e8945cbdeae..5c908d4275d550a8cbb421bd2f4f70fb1427a25a 100644 (file)
@@ -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
 
index 3913700a4f7f5fb9281d246c0ac402802f677e79..b4aff632839777418734ea317e63f28edbdf0fe3 100644 (file)
@@ -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
 
index a8a4509aa85ad8259f6ccb27c6a8a4fa6f2d785f..e4d8332b44ff91e82a53f9dbcccdc9c936d1c5b1 100644 (file)
@@ -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
 
index c613b47b8e2c19d48b5a00b2f3f81228df03929b..14b07a4096b2769881f9565eb575cfe5a41a3666 100644 (file)
@@ -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
 
index bcc90aa048f13b4394bfd3ea57272e4d8f44155c..2ba0f538776510f66f0c637079398a569b2ba35d 100644 (file)
@@ -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
 
index cba514782f81f7cbb5014574ce907ab1916ac214..2309e6acce971f3d15fcaf57f1a3d7c4ff32d10e 100644 (file)
@@ -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
 
index 16ef44d54036505121e099854834d6eed98ecf22..079eae5bdb59a07ba67b465a892295f97bac33c9 100644 (file)
@@ -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
 
index 0cfdf4bc8e4f6d27411af769681f57a25fc00deb..db7261e0a2bf87eab8f8e1902df65277f4efe315 100644 (file)
@@ -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
 
index 8a0b8866a89bf41d6f4de63e8d12cdca1b652ddd..57e154d8d26a0cc5cb306c6325eebed86e22c36c 100644 (file)
@@ -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
 
index ee50d99f14356e5bfd94cea9297ce200cdeaa412..183208bfa93209ac59c8cce90a7ec77173c2c21e 100644 (file)
@@ -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);
index 7d537c251cafceb5647f791c9a6e669e5b29a363..0679e6b4b601c09800c68c338c4e30a958f4c4e4 100644 (file)
@@ -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
 
This page took 0.059597 seconds and 4 git commands to generate.