App-TimeTracker-Command-Gitlab
view release on metacpan or search on metacpan
lib/App/TimeTracker/Command/Gitlab.pm view on Meta::CPAN
say "reopend closed issue";
}
# set assignee
if ($self->config->{gitlab}{set_assignee}) {
my $assignee;
if ($issue->{assignees} && $issue->{assignees}[0] && $issue->{assignees}[0]{username}) {
$assignee = $issue->{assignees}[0]{username};
}
elsif ( $issue->{assignee} && $issue->{assignee}{username}) {
$assignee = $issue->{assignee}{username};
}
if (my $user = $self->_call('GET','user')) {
if ($assignee) {
if ($assignee ne $user->{username}) {
warning_message("Assignee already set to ".$assignee);
}
}
else {
$self->_call('PUT','projects/'.$self->project_id.'/issues/'.$self->issue.'?assignee_id='.$user->{id});
say "Assignee set to you";
}
}
else {
error_message("Cannot get user-id, thus cannot assign issue");
}
}
# un/set labels
if (my $on_start = $self->config->{gitlab}{labels_on_start}) {
my %l = map {$_ => 1} @{$issue->{labels}};
if (my $add = $on_start->{add}) {
foreach my $new (@$add) {
$l{$new}=1;
}
}
if (my $remove = $on_start->{remove}) {
foreach my $remove (@$remove) {
delete $l{$remove};
}
}
$self->_call('PUT','projects/'.$self->project_id.'/issues/'.$self->issue.'?labels='.uri_escape(join(',',keys %l)));
say "Labels are now: ".join(', ',sort keys %l);
}
};
#after [ 'cmd_start', 'cmd_continue', 'cmd_append' ] => sub {
# my $self = shift;
# TODO: do we want to do something after stop?
#};
sub _get_user_id {
my $self = shift;
my $user = $self->_call('GET','user');
return $user->{id} if $user && $user->{id};
return;
}
sub _call {
my ($self,$method, $endpoint, $args) = @_;
my $url = $self->config->{gitlab}{url}.'/api/v4/'.$endpoint;
my $res = $self->gitlab_client->request($method,$url);
if ($res->{success}) {
my $data = decode_json($res->{content});
return $data;
}
error_message(join(" ",$res->{status}, $res->{reason}, "\n" . $res->{content}));
}
sub App::TimeTracker::Data::Task::gitlab_issue {
my $self = shift;
foreach my $tag ( @{ $self->tags } ) {
next unless $tag =~ /^issue#(\d+)/;
return $1;
}
}
no Moose::Role;
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
App::TimeTracker::Command::Gitlab - App::TimeTracker Gitlab plugin
=head1 VERSION
version 1.004
=head1 DESCRIPTION
Connect tracker with L<Gitlab|https://about.gitlab.com/>.
Using the Gitlab plugin, tracker can fetch the name of an issue and use
it as the task's description; generate a nicely named C<git> branch
(if you're also using the C<Git> plugin).
Planned but not implemented: Adding yourself as the assignee.
=head1 CONFIGURATION
=head2 plugins
Add C<Gitlab> to the list of plugins.
=head2 gitlab
add a hash named C<gitlab>, containing the following keys:
=head3 url [REQUIRED]
The base URL of your gitlab instance, eg C<https://gitlab.example.com>
=head3 token [REQUIRED]
Your personal access token. Get it from your gitlab profile page. For
( run in 0.563 second using v1.01-cache-2.11-cpan-63c85eba8c4 )