]> Dogcows Code - chaz/git-codeowners/commitdiff
Version 0.48
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 21 Jan 2020 17:14:26 +0000 (10:14 -0700)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Tue, 21 Jan 2020 17:14:26 +0000 (10:14 -0700)
19 files changed:
Changes
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
t/file-codeowners.t

diff --git a/Changes b/Changes
index 94ce334f4862ae68a27c5600b8be750c0350bba1..dc5ce0fad0bdb2148d81ee5f9134e438e15f80af 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 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).
index 22654cd8d9755015386e254e05f2093af8007c29..cbfbafd0db85877482ce01f96c8d806672eed0f9 100644 (file)
--- a/META.json
+++ b/META.json
    "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"
index babd239c225ecba7834412dc1995b5cc8b537b7a..e4aa077026f948ea5dbc063b945478183e1aa342 100644 (file)
--- a/META.yml
+++ b/META.yml
@@ -31,43 +31,43 @@ no_index:
 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'
@@ -93,7 +93,7 @@ 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.47'
+version: '0.48'
 x_authority: cpan:CCM
 x_generated_by_perl: v5.28.0
 x_serialization_backend: 'YAML::Tiny version 1.73'
index ae4b3010fae1dedfc922624ef15a3aa320332482..100341ad8b56c99ad560894660ec120b43d1f513 100644 (file)
@@ -47,7 +47,7 @@ my %WriteMakefileArgs = (
     "Test::Exit" => 0,
     "Test::More" => 0
   },
-  "VERSION" => "0.47",
+  "VERSION" => "0.48",
   "test" => {
     "TESTS" => "t/*.t"
   }
diff --git a/README b/README
index 0b9aa08877c7e6906940cdb7ac40eebcfc3ba1d5..9d0b26e31f7484bf0cd7defda7b337aaa9addd72 100644 (file)
--- a/README
+++ b/README
@@ -4,7 +4,7 @@ NAME
 
 VERSION
 
-    version 0.47
+    version 0.48
 
 SYNOPSIS
 
index 6ea28c67dbc4627d8019558b886bd1cd90aa504d..178f874cb8e8d98d00cf5ae85bd753309a5938be 100755 (executable)
@@ -10,7 +10,7 @@ use strict;
 
 use App::Codeowners;
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 App::Codeowners->main(@ARGV);
 
@@ -26,7 +26,7 @@ git-codeowners - A tool for managing CODEOWNERS files
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 SYNOPSIS
 
index 0a21fb6ef39b4f25e19126d842be8da752a112fe..5715354c8a6cff9a47bcfb6f5833156d97d08e1c 100644 (file)
@@ -14,7 +14,7 @@ use Encode qw(encode);
 use File::Codeowners;
 use Path::Tiny;
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 
 sub main {
@@ -177,7 +177,7 @@ sub _command_update {
         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:
@@ -218,7 +218,7 @@ App::Codeowners - A tool for managing CODEOWNERS files
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 DESCRIPTION
 
index 2f974d8cb9b2433cb1fdc19ab741d31ec33d373f..efb516cabd01d05aec2e5d5d61953e8945cbdeae 100644 (file)
@@ -5,7 +5,7 @@ package App::Codeowners::Formatter;
 use warnings;
 use strict;
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 use Module::Load;
 
@@ -120,7 +120,7 @@ App::Codeowners::Formatter - Base class for formatting codeowners output
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 SYNOPSIS
 
index 036bb4469a8107b2b773709342e67b51c9d0fcb1..3913700a4f7f5fb9281d246c0ac402802f677e79 100644 (file)
@@ -5,7 +5,7 @@ package App::Codeowners::Formatter::CSV;
 use warnings;
 use strict;
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 use parent 'App::Codeowners::Formatter';
 
@@ -63,7 +63,7 @@ App::Codeowners::Formatter::CSV - Format codeowners output as comma-separated va
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 DESCRIPTION
 
index 2d1c300e1dc5bfb1cf6f1d9a042426c2dd6640a4..a8a4509aa85ad8259f6ccb27c6a8a4fa6f2d785f 100644 (file)
@@ -5,7 +5,7 @@ package App::Codeowners::Formatter::JSON;
 use warnings;
 use strict;
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 use parent 'App::Codeowners::Formatter';
 
@@ -42,7 +42,7 @@ App::Codeowners::Formatter::JSON - Format codeowners output as JSON
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 DESCRIPTION
 
index 6c98c6982fff27996e3457ff06fcdc534f9e55d4..c613b47b8e2c19d48b5a00b2f3f81228df03929b 100644 (file)
@@ -5,7 +5,7 @@ package App::Codeowners::Formatter::String;
 use warnings;
 use strict;
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 use parent 'App::Codeowners::Formatter';
 
@@ -136,7 +136,7 @@ App::Codeowners::Formatter::String - Format codeowners output using printf-like
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 DESCRIPTION
 
index 25b8d54d70d21f1cb2ee7e07b4d4dd9a26656697..bcc90aa048f13b4394bfd3ea57272e4d8f44155c 100644 (file)
@@ -5,7 +5,7 @@ package App::Codeowners::Formatter::TSV;
 use warnings;
 use strict;
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # 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.47
+version 0.48
 
 =head1 DESCRIPTION
 
index d41933344be30f28fc8f82480a8ee6438a95b792..cba514782f81f7cbb5014574ce907ab1916ac214 100644 (file)
@@ -5,7 +5,7 @@ package App::Codeowners::Formatter::Table;
 use warnings;
 use strict;
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 use parent 'App::Codeowners::Formatter';
 
@@ -40,7 +40,7 @@ App::Codeowners::Formatter::Table - Format codeowners output as a table
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 DESCRIPTION
 
index de0bc604b5e7c20d644ac6eae6d15d7e253669b8..16ef44d54036505121e099854834d6eed98ecf22 100644 (file)
@@ -5,7 +5,7 @@ package App::Codeowners::Formatter::YAML;
 use warnings;
 use strict;
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 use parent 'App::Codeowners::Formatter';
 
@@ -36,7 +36,7 @@ App::Codeowners::Formatter::YAML - Format codeowners output as YAML
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 DESCRIPTION
 
index 153376fc3a1bb0cb7efe9c16e28f96ec408c3749..0cfdf4bc8e4f6d27411af769681f57a25fc00deb 100644 (file)
@@ -8,7 +8,7 @@ use strict;
 use Getopt::Long 2.39 ();
 use Path::Tiny;
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 sub pod2usage {
     eval { require Pod::Usage };
@@ -299,7 +299,7 @@ App::Codeowners::Options - Getopt and shell completion for App::Codeowners
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 METHODS
 
index b8169561d2836082794ab75d353013c3f886b28e..8a0b8866a89bf41d6f4de63e8d12cdca1b652ddd 100644 (file)
@@ -23,7 +23,7 @@ our @EXPORT_OK = qw(
     zip
 );
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 
 sub find_nearest_codeowners {
@@ -280,7 +280,7 @@ App::Codeowners::Util - Grab bag of utility subs for Codeowners modules
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 DESCRIPTION
 
index 0ae71a8d92004f8b15d1541ff06214084360ee65..ee50d99f14356e5bfd94cea9297ce200cdeaa412 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.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 sub _croak { require Carp; Carp::croak(@_); }
 sub _usage { _croak("Usage: @_\n") }
@@ -65,11 +65,13 @@ sub parse_from_fh {
         }
         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*$/) {
@@ -278,11 +280,60 @@ sub update_owners {
 
     $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;
 }
 
 
@@ -354,7 +405,7 @@ File::Codeowners - Read and write CODEOWNERS files
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 METHODS
 
@@ -466,6 +517,22 @@ multiple such patterns, they will all be updated.
 
 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);
index 14d4c2dff5c013a0051129e48cb37bc7bcc7aaa8..7d537c251cafceb5647f791c9a6e669e5b29a363 100644 (file)
@@ -10,7 +10,7 @@ use Encode qw(encode);
 use File::Codeowners;
 use Test::Builder;
 
-our $VERSION = '0.47'; # VERSION
+our $VERSION = '0.48'; # VERSION
 
 my $Test = Test::Builder->new;
 
@@ -88,7 +88,7 @@ Test::File::Codeowners - Write tests for CODEOWNERS files
 
 =head1 VERSION
 
-version 0.47
+version 0.48
 
 =head1 SYNOPSIS
 
index a50a050eb8dbebb859297879100481c7a72e80e8..7bfb53ca9636eb48e812f137b0e435bf1b18ad7b 100644 (file)
@@ -94,6 +94,30 @@ subtest 'parse errors', sub {
     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;
This page took 0.044388 seconds and 4 git commands to generate.