]> Dogcows Code - chaz/git-codeowners/commitdiff
add update_owner method to File::Codeowners
authorCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 22 Mar 2020 07:26:13 +0000 (01:26 -0600)
committerCharles McGarvey <chazmcgarvey@brokenzipper.com>
Sun, 22 Mar 2020 07:30:04 +0000 (01:30 -0600)
lib/File/Codeowners.pm

index f4caf4722fe7bac6c0c057cd964e75c20674f575..9238a29a2939084390c3567eeadbda2480687839 100644 (file)
@@ -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);
This page took 0.027678 seconds and 4 git commands to generate.