App-Codeowners

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


    Does not yet support Zsh...

COMMANDS

 show

        git-codeowners [show] [--format FORMAT] [--owner OWNER]...
                       [--pattern PATTERN]... [--[no-]patterns]
                       [--project PROJECT]... [--[no-]projects] [PATH...]
                       [--[no-]expand-aliases]

    Show owners of one or more files in a repo.

    If --owner, --project, --pattern are set, only show files with matching
    criteria. These can be repeated.

    Use --patterns to also show the matching pattern associated with each
    file.

    By default the output might show associated projects if the CODEOWNERS
    file defines them. You can control this by explicitly using --projects
    or --no-projects to always show or always hide defined projects,
    respectively.

    Use --expand-aliases to show owners that are group aliases defined in
    the CODEOWNERS file as their aliased owners.

 owners

        git-codeowners owners [--format FORMAT] [--pattern PATTERN]

    List all owners defined in the CODEOWNERS file.

 patterns

bin/git-codeowners  view on Meta::CPAN


Does not yet support Zsh...

=head1 COMMANDS

=head2 show

    git-codeowners [show] [--format FORMAT] [--owner OWNER]...
                   [--pattern PATTERN]... [--[no-]patterns]
                   [--project PROJECT]... [--[no-]projects] [PATH...]
                   [--[no-]expand-aliases]

Show owners of one or more files in a repo.

If C<--owner>, C<--project>, C<--pattern> are set, only show files with matching
criteria. These can be repeated.

Use C<--patterns> to also show the matching pattern associated with each file.

By default the output might show associated projects if the C<CODEOWNERS> file
defines them. You can control this by explicitly using C<--projects> or
C<--no-projects> to always show or always hide defined projects, respectively.

Use C<--expand-aliases> to show owners that are group aliases defined in the
F<CODEOWNERS> file as their aliased owners.

=head2 owners

    git-codeowners owners [--format FORMAT] [--pattern PATTERN]

List all owners defined in the F<CODEOWNERS> file.

=head2 patterns

lib/App/Codeowners.pm  view on Meta::CPAN

}

sub _command_show {
    my $self = shift;
    my $opts = shift;

    my $toplevel = git_toplevel('.') or die "Not a git repo\n";

    my $codeowners_path = find_codeowners_in_directory($toplevel)
        or die "No CODEOWNERS file in $toplevel\n";
    local $ENV{GIT_CODEOWNERS_ALIASES} = 1 if $opts->{expand_aliases};
    my $codeowners = $self->_parse_codeowners($codeowners_path);

    my ($proc, $cdup) = run_git(qw{rev-parse --show-cdup});
    $proc->wait and exit 1;

    my $show_projects = $opts->{projects} // scalar @{$codeowners->projects};

    my $formatter = App::Codeowners::Formatter->new(
        format  => $opts->{format} || ' * %-50F %O',
        handle  => *STDOUT,

lib/App/Codeowners.pm  view on Meta::CPAN

        ],
    );

    my %filter_owners   = map { $_ => 1 } @{$opts->{owner}};
    my %filter_projects = map { $_ => 1 } @{$opts->{project}};
    my %filter_patterns = map { $_ => 1 } @{$opts->{pattern}};

    $proc = git_ls_files('.', $opts->args);
    while (my $filepath = $proc->next) {
        my $match = $codeowners->match(path($filepath)->relative($cdup),
            expand => $opts->{expand_aliases});
        if (%filter_owners) {
            for my $owner (@{$match->{owners}}) {
                goto ADD_RESULT if $filter_owners{$owner};
            }
            next;
        }
        if (%filter_patterns) {
            goto ADD_RESULT if $filter_patterns{$match->{pattern} || ''};
            next;
        }

lib/App/Codeowners/Formatter/String.pm  view on Meta::CPAN

        F => $self->_create_filterer->($result->{File},    undef),
        O => $self->_create_filterer->($result->{Owner},   $self->_owner_colorgen),
        P => $self->_create_filterer->($result->{Project}, undef),
        T => $self->_create_filterer->($result->{Pattern}, undef),
    );

    my $text = stringf($self->format, %info);
    print { $self->handle } $text, "\n";
}

sub _expand_filter_args {
    my $arg = shift || '';

    my @filters = split(/,/, $arg);
    my $color_override;

    for (my $i = 0; $i < @filters; ++$i) {
        my $filter = $filters[$i] or next;
        if ($filter =~ /^(?:nocolor|color:([0-9a-fA-F]{3,6}))$/) {
            $color_override = $1 || '';
            splice(@filters, $i, 1);

lib/App/Codeowners/Formatter/String.pm  view on Meta::CPAN

    my %filter = (
        quote   => sub { local $_ = $_[0]; s/"/\"/s; "\"$_\"" },
    );

    return sub {
        my $value = shift || '';
        my $color = shift || '';
        my $gencolor = ref($color) eq 'CODE' ? $color : sub { $color };
        return sub {
            my $arg = shift;
            my ($filters, $color) = _expand_filter_args($arg);
            if (ref($value) eq 'ARRAY') {
                $value = join(',', map { _colored($_, $color // $gencolor->($_)) } @$value);
            }
            else {
                $value = _colored($value, $color // $gencolor->($value));
            }
            for my $key (@$filters) {
                if (my $filter = $filter{$key}) {
                    $value = $filter->($value);
                }

lib/App/Codeowners/Options.pm  view on Meta::CPAN

        'patterns'  => {
            'owner=s'   => '',
        },
        'projects'  => {},
        'show'      => {
            'owner=s@'          => [],
            'pattern=s@'        => [],
            'project=s@'        => [],
            'patterns!'         => 0,
            'projects!'         => undef,
            'expand-aliases!'   => 0,
        },
        'update'    => {},
    };
}

sub _commands {
    my $self = shift;
    my @commands = sort keys %{$self->_command_options};
    return @commands;
}



( run in 1.229 second using v1.01-cache-2.11-cpan-5b529ec07f3 )