X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fgit-codeowners;a=blobdiff_plain;f=lib%2FFile%2FCodeowners.pm;h=9238a29a2939084390c3567eeadbda2480687839;hp=f4caf4722fe7bac6c0c057cd964e75c20674f575;hb=39c158d76aefae4be3ff0c92e3977402c691323d;hpb=1c893b7e095fdaffdf47ffee426407a1f7e305fb diff --git a/lib/File/Codeowners.pm b/lib/File/Codeowners.pm index f4caf47..9238a29 100644 --- a/lib/File/Codeowners.pm +++ b/lib/File/Codeowners.pm @@ -449,6 +449,38 @@ sub update_owners_by_project { return $count; } +=method 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. + +=cut + +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; +} + =method rename_project $codeowners->rename_project($old_name => $new_name);