summaryrefslogtreecommitdiffstats
path: root/lib/Devscripts/Salsa/search_project.pm
blob: 67b2805462a57318d8ab6661435336b3bfc6c837 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Searches projects using given string
package Devscripts::Salsa::search_project;

use strict;
use Devscripts::Output;
use Moo::Role;

sub search_project {
    my ($self, $project) = @_;
    unless ($project) {
        ds_warn "Searched string is missing";
        return 1;
    }
    my $projects = $self->api->project($project);
    if ($projects) {
        $projects = [$projects];
    } else {
        $projects
          = $self->api->paginator('projects',
            { search => $project, order_by => 'name' })->all();
    }
    unless ($projects and @$projects) {
        ds_warn "No projects found";
        return 1;
    }
    foreach (@$projects) {
        print <<END;
Id       : $_->{id}
Name     : $_->{name}
Full path: $_->{path_with_namespace}
END
        print($_->{namespace}->{kind} eq 'group'
            ? "Group id : "
            : "User id  : "
        );
        print "$_->{namespace}->{id}\n";
        print($_->{namespace}->{kind} eq 'group'
            ? "Group    : "
            : "User     : "
        );
        print "$_->{namespace}->{name}\n";
        if ($_->{forked_from_project} and $_->{forked_from_project}->{id}) {
            print
              "Fork of  : $_->{forked_from_project}->{name_with_namespace}\n";
        }
        print "\n";
    }
    return 0;
}

1;