| 1 | package JIRA::REST::Class::Sprint; | ||
| 2 | use parent qw( JIRA::REST::Class::Abstract ); | ||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | use 5.010; | ||
| 6 | |||
| 7 | our $VERSION = '0.11'; | ||
| 8 | our $SOURCE = 'CPAN'; | ||
| 9 | ## $SOURCE = 'GitHub'; # COMMENT | ||
| 10 | # the line above will be commented out by Dist::Zilla | ||
| 11 | |||
| 12 | # ABSTRACT: A helper class for L<JIRA::REST::Class|JIRA::REST::Class> that represents the sprint of a JIRA issue as an object (if you're using L<Atlassian GreenHopper|https://www.atlassian.com/software/jira/agile>). | ||
| 13 | |||
| 14 | use Readonly 2.04; | ||
| 15 | |||
| 16 | Readonly my @ACCESSORS => qw( id rapidViewId state name startDate endDate | ||
| 17 | completeDate sequence ); | ||
| 18 | |||
| 19 | __PACKAGE__->mk_ro_accessors( @ACCESSORS ); | ||
| 20 | |||
| 21 | Readonly my $GREENHOPPER_SPRINT => qr{ com [.] atlassian [.] greenhopper [.] | ||
| 22 | service [.] sprint [.] Sprint }x; | ||
| 23 | |||
| 24 | sub init { | ||
| 25 | my $self = shift; | ||
| 26 | $self->SUPER::init( @_ ); | ||
| 27 | |||
| 28 | my $data = $self->data; | ||
| 29 | $data =~ s{ $GREENHOPPER_SPRINT [^ \[ ]+ \[ }{}x; | ||
| 30 | $data =~ s{\]$}{}x; | ||
| 31 | my @fields = split /,/, $data; | ||
| 32 | foreach my $field ( @fields ) { | ||
| 33 | my ( $k, $v ) = split /=/, $field; | ||
| 34 | if ( $v && $v eq '<null>' ) { | ||
| 35 | undef $v; | ||
| 36 | } | ||
| 37 | $self->{$k} = $v; | ||
| 38 | } | ||
| 39 | |||
| 40 | return; | ||
| 41 | } | ||
| 42 | |||
| 43 | 1; | ||
| 44 | |||
| 45 | __END__ | ||
| 46 | |||
| 47 | =pod | ||
| 48 | |||
| 49 | =encoding UTF-8 | ||
| 50 | |||
| 51 | =for :stopwords Packy Anderson Alexandr Alexey Ciornii Melezhik Atlassian GreenHopper JRC | ||
| 52 | ScriptRunner TODO aggregateprogress aggregatetimeestimate | ||
| 53 | aggregatetimeoriginalestimate assigneeType avatar avatarUrls completeDate | ||
| 54 | displayName duedate emailAddress endDate fieldtype fixVersions fromString | ||
| 55 | genericized iconUrl isAssigneeTypeValid issueTypes issuekeys issuelinks | ||
| 56 | issuetype jira jql lastViewed maxResults originalEstimate | ||
| 57 | originalEstimateSeconds parentkey projectId rapidViewId remainingEstimate | ||
| 58 | remainingEstimateSeconds resolutiondate sprintlist startDate | ||
| 59 | subtaskIssueTypes timeSpent timeSpentSeconds timeestimate | ||
| 60 | timeoriginalestimate timespent timetracking toString updateAuthor worklog | ||
| 61 | workratio | ||
| 62 | |||
| 63 | =head1 NAME | ||
| 64 | |||
| 65 | JIRA::REST::Class::Sprint - A helper class for L<JIRA::REST::Class|JIRA::REST::Class> that represents the sprint of a JIRA issue as an object (if you're using L<Atlassian GreenHopper|https://www.atlassian.com/software/jira/agile>). | ||
| 66 | |||
| 67 | =head1 VERSION | ||
| 68 | |||
| 69 | version 0.11 | ||
| 70 | |||
| 71 | =head1 READ-ONLY ACCESSORS | ||
| 72 | |||
| 73 | =head2 B<id> | ||
| 74 | |||
| 75 | =head2 B<rapidViewId> | ||
| 76 | |||
| 77 | =head2 B<state> | ||
| 78 | |||
| 79 | =head2 B<name> | ||
| 80 | |||
| 81 | =head2 B<startDate> | ||
| 82 | |||
| 83 | =head2 B<endDate> | ||
| 84 | |||
| 85 | =head2 B<completeDate> | ||
| 86 | |||
| 87 | =head2 B<sequence> | ||
| 88 | |||
| 89 | =head1 RELATED CLASSES | ||
| 90 | |||
| 91 | =over 2 | ||
| 92 | |||
| 93 | =item * L<JIRA::REST::Class|JIRA::REST::Class> | ||
| 94 | |||
| 95 | =item * L<JIRA::REST::Class::Abstract|JIRA::REST::Class::Abstract> | ||
| 96 | |||
| 97 | =back | ||
| 98 | |||
| 99 | # These methods don't work, probably because JIRA doesn't have a well-defined | ||
| 100 | # interface for adding/removing issues from a sprint. | ||
| 101 | |||
| 102 | sub greenhopper_api_url { | ||
| 103 | my $self = shift; | ||
| 104 | my $url = $self->jira->rest_api_url_base; | ||
| 105 | $url =~ s{/rest/api/.+}{/rest/greenhopper/latest}; | ||
| 106 | return $url; | ||
| 107 | } | ||
| 108 | |||
| 109 | sub add_issues { | ||
| 110 | my $self = shift; | ||
| 111 | my $url = join '/', q{}, | ||
| 112 | 'sprint', $self->id, 'issues', 'add'; | ||
| 113 | |||
| 114 | my $args = { issueKeys => \@_ }; | ||
| 115 | my $host = $self->jira->{rest}->getHost; | ||
| 116 | |||
| 117 | $self->jira->{rest}->setHost($self->greenhopper_api_url); | ||
| 118 | $self->jira->{rest}->PUT($url, undef, $args); | ||
| 119 | $self->jira->_content; | ||
| 120 | $self->jira->{rest}->setHost($host); | ||
| 121 | } | ||
| 122 | |||
| 123 | sub remove_issues { | ||
| 124 | my $self = shift; | ||
| 125 | my $url = join '/', q{}, | ||
| 126 | 'sprint', $self->id, 'issues', 'remove'; | ||
| 127 | my $args = { issueKeys => \@_ }; | ||
| 128 | my $host = $self->jira->{rest}->getHost; | ||
| 129 | |||
| 130 | $self->jira->{rest}->setHost($self->greenhopper_api_url); | ||
| 131 | $self->jira->{rest}->PUT($url, undef, $args); | ||
| 132 | $self->jira->_content; | ||
| 133 | $self->jira->{rest}->setHost($host); | ||
| 134 | } | ||
| 135 | |||
| 136 | =head1 AUTHOR | ||
| 137 | |||
| 138 | Packy Anderson <packy@cpan.org> | ||
| 139 | |||
| 140 | =head1 COPYRIGHT AND LICENSE | ||
| 141 | |||
| 142 | This software is Copyright (c) 2017 by Packy Anderson. | ||
| 143 | |||
| 144 | This is free software, licensed under: | ||
| 145 | |||
| 146 | The Artistic License 2.0 (GPL Compatible) | ||
| 147 | |||
| 148 | =cut |