summaryrefslogtreecommitdiffstats
path: root/lib/Devscripts/Salsa/Repo.pm
blob: 177607fad221df0ef502431925ef7a81b80a48c4 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Common method to get projects
package Devscripts::Salsa::Repo;

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

with "Devscripts::Salsa::Hooks";

sub get_repo {
    my ($self, $prompt, @reponames) = @_;
    my @repos;
    if ($self->config->all and @reponames == 0) {
        ds_debug "--all is set";
        my $projects;
        # This rule disallow trying to configure all "Debian" projects:
        #  - Debian id is 2
        #  - next is 1987
        if ($self->group_id) {
            $projects
              = $self->api->paginator('group_projects', $self->group_id)->all;
        } elsif ($self->user_id) {
            $projects
              = $self->api->paginator('user_projects', $self->user_id)->all;
        } else {
            ds_warn "Missing or invalid token";
            return 1;
        }
        unless ($projects) {
            ds_warn "No projects found";
            return 1;
        }
        @repos = map {
            $self->projectCache->{ $_->{path_with_namespace} } = $_->{id};
            [$_->{id}, $_->{name}]
        } @$projects;
        if (@{ $self->config->skip }) {
            @repos = map {
                my $res = 1;
                foreach my $k (@{ $self->config->skip }) {
                    $res = 0 if ($_->[1] =~ m#(?:.*/)?\Q$k\E#);
                }
                $res ? $_ : ();
            } @repos;
        }
        if ($ds_yes > 0 or !$prompt) {
            ds_verbose "Found " . @repos . " projects";
        } else {
            unless (
                ds_prompt(
                        "You're going to configure "
                      . @repos
                      . " projects. Continue (N/y) "
                ) =~ accept
            ) {
                ds_warn "Aborting";
                return 1;
            }
        }
    } else {
        @repos = map { [$self->project2id($_), $_] } @reponames;
    }
    return @repos;
}

1;