summaryrefslogtreecommitdiffstats
path: root/lib/Devscripts/Salsa/pipeline_schedules.pm
blob: 66ad08ae7931b6c12d2c1e6ec4887ce56e0383b1 (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
67
68
69
70
71
72
73
# Lists pipeline schedules of a project
package Devscripts::Salsa::pipeline_schedules;

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

# For --all
with "Devscripts::Salsa::Repo";

sub pipeline_schedules {
    my ($self, @repo) = @_;
    my $ret = 0;

    unless (@repo or $self->config->all) {
        ds_warn "Usage $0 pipelines <project|--all>";
        return 1;
    }
    if (@repo and $self->config->all) {
        ds_warn "--all with a project (@repo) makes no sense";
        return 1;
    }

    # If --all is asked, launch all projects
    @repo = map { $_->[1] } $self->get_repo(0, @repo) unless (@repo);

    foreach my $p (sort @repo) {
        my $id    = $self->project2id($p);
        my $count = 0;
        unless ($id) {
    #ds_warn "Project $p not found";   # $self->project2id($p) shows this error
            $ret++;
            unless ($self->config->no_fail) {
                ds_verbose "Use --no-fail to continue";
                return 1;
            }
        } else {
            my $projects = $self->api->project($id);
            if ($projects->{jobs_enabled} == 0) {
                print "$p has disabled CI/CD\n";
                next;
            }

            my $pipelines
              = $self->api->paginator('pipeline_schedules', $id)->all();

            print "$p\n" if @$pipelines;

            foreach (@$pipelines) {
                my $status = $_->{active} ? 'Enabled' : 'Disabled';
                print <<END;
\tID         : $_->{id}
\tDescription: $_->{description}
\tStatus     : $status
\tRef        : $_->{ref}
\tCron       : $_->{cron}
\tTimezone   : $_->{cron_timezone}
\tCreated    : $_->{created_at}
\tUpdated    : $_->{updated_at}
\tNext run   : $_->{next_run_at}
\tOwner      : $_->{owner}->{username}

END
            }
        }
        unless ($count) {
            next;
        }
    }
    return $ret;
}

1;