JIRA-Client-Automated

 view release on metacpan or  search on metacpan

lib/JIRA/Client/Automated.pm  view on Meta::CPAN

    my $subtask = $jira->create_subtask($project, $summary, $description, $parent_key);
    # or with optional subtask type
    my $subtask = $jira->create_subtask($project, $summary, $description, $parent_key, 'sub-task');

Creating a subtask. If your JIRA instance does not call subtasks "Sub-task" or
"sub-task", then you will need to pass in your subtask type.

This method calls L</create> and return the same hash reference that it does.

=cut

sub create_subtask {
    my ($self, $project, $summary, $description, $parent_key, $type) = @_;

    # validate fields
    die "parent_key required" unless $parent_key;
    $type ||= 'Sub-task';

    my $fields = {
        project     => { key => $project, },
        issuetype   => { name => $type },
        summary     => $summary,
        description => $description,
        parent      => { key  => $parent_key},
    };

    return $self->create($fields);
}


=head2 update_issue

    $jira->update_issue($key, $field_update_hash, $update_verb_hash);

There are two ways to express the updates you want to make to an issue.

For simple changes you pass $field_update_hash as a reference to a hash of
field_name => new_value pairs. For example:

    $jira->update_issue($key, { summary => $new_summary });

That works for simple fields, but there are some, like comments, that can't be
updated in this way. For them you need to use $update_verb_hash.

The $update_verb_hash parameter allow you to express a series of specific
operations (verbs) to be performed on each field. For example:

    $jira->update_issue($key, undef, {
        labels   => [ { remove => "test" }, { add => "another" } ],
        comments => [ { remove => { id => 10001 } } ]
    });

The two forms of update can be combined in a single call.

For more information see:

    L<https://developer.atlassian.com/cloud/jira/platform/rest/#api-api-2-issue-issueIdOrKey-put>

=cut

sub update_issue {
    my ($self, $key, $field_update_hash, $update_verb_hash) = @_;
    
    my $cur_issue = $self->get_issue( $key );
    my $project   = $cur_issue->{fields}{project}{key};
    my $issuetype = $cur_issue->{fields}{issuetype}{name};
    
    my $issue = {};
    $issue->{fields} = $self->_convert_to_customfields($project, $issuetype, $field_update_hash) if $field_update_hash;
    $issue->{update} = $self->_convert_update_to_customfields($project, $issuetype, $update_verb_hash)  if $update_verb_hash;

    my $issue_json = $self->{_json}->encode($issue);
    my $uri        = "$self->{auth_url}issue/$key";

    my $request = PUT $uri,
      Content_Type => 'application/json',
      Content      => $issue_json;

    my $response = $self->_perform_request($request);

    return $key;
}


=head2 get_issue

    my $issue = $jira->get_issue($key);

Returns details for any issue, given its key. This call returns a hash
containing the information for the issue in JIRA's format. See L</"JIRA ISSUE
HASH FORMAT"> for details.

=cut

sub get_issue {
    my ($self, $key) = @_;
    my $uri = "$self->{auth_url}issue/$key";

    my $request = GET $uri, Content_Type => 'application/json';

    my $response = $self->_perform_request($request);

    my $new_issue = $self->{_json}->decode($response->decoded_content());

    my $project = $new_issue->{fields}{project}{key};
    my $issuetype = $new_issue->{fields}{issuetype}{name};
    my $english_fields = $self->_convert_from_customfields( $project, $issuetype, $new_issue->{fields} );
    $new_issue->{fields} = $english_fields;

    return $new_issue;
}


sub _get_transitions {
    my ($self, $key) = @_;
    my $uri = "$self->{auth_url}issue/$key/transitions";

    my $request = GET $uri, Content_Type => 'application/json';

    my $response = $self->_perform_request($request);



( run in 0.954 second using v1.01-cache-2.11-cpan-bbe5e583499 )