| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::bif::push::issue; | 
| 2 | 1 |  |  | 1 |  | 4656 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 3 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 23 |  | 
| 4 | 1 |  |  | 1 |  | 3 | use feature 'state'; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 71 |  | 
| 5 | 1 |  |  | 1 |  | 3 | use Bif::Mo; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 5 |  | 
| 6 | 1 |  |  | 1 |  | 453 | use DBIx::ThinSQL qw/concat qv/; | 
|  | 1 |  |  |  |  | 18720 |  | 
|  | 1 |  |  |  |  | 7 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = '0.1.5_5'; | 
| 9 |  |  |  |  |  |  | extends 'App::bif'; | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | sub run { | 
| 12 | 1 |  |  | 1 | 1 | 2 | my $self = shift; | 
| 13 | 1 |  |  |  |  | 3 | my $opts = $self->opts; | 
| 14 | 1 |  |  |  |  | 6 | my $info = $self->get_node( $opts->{id}, 'issue' ); | 
| 15 | 0 |  |  |  |  |  | my $dbw  = $self->dbw; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | $dbw->txn( | 
| 18 |  |  |  |  |  |  | sub { | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 0 |  |  | 0 |  |  | foreach my $path ( @{ $opts->{path} } ) { | 
|  | 0 |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 0 |  |  |  |  |  | my $pinfo = $self->get_project($path); | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | my $existing = $dbw->xval( | 
| 25 |  |  |  |  |  |  | select     => 'ist.status', | 
| 26 |  |  |  |  |  |  | from       => 'issues i', | 
| 27 |  |  |  |  |  |  | inner_join => 'issues i2', | 
| 28 |  |  |  |  |  |  | on         => 'i2.id = i.src_id', | 
| 29 |  |  |  |  |  |  | inner_join => 'issue_status ist', | 
| 30 |  |  |  |  |  |  | on         => { | 
| 31 |  |  |  |  |  |  | 'ist.id'         => \'i2.issue_status_id', | 
| 32 |  |  |  |  |  |  | 'ist.project_id' => $pinfo->{id}, | 
| 33 |  |  |  |  |  |  | }, | 
| 34 |  |  |  |  |  |  | where        => { 'i.id' => $info->{id} }, | 
| 35 |  |  |  |  |  |  | union_select => 'ist.status', | 
| 36 |  |  |  |  |  |  | from         => 'issues i', | 
| 37 |  |  |  |  |  |  | inner_join   => 'issue_status ist', | 
| 38 |  |  |  |  |  |  | on           => { | 
| 39 |  |  |  |  |  |  | 'ist.id'         => \'i.issue_status_id', | 
| 40 |  |  |  |  |  |  | 'ist.project_id' => $pinfo->{id}, | 
| 41 |  |  |  |  |  |  | }, | 
| 42 |  |  |  |  |  |  | where => { 'i.src_id' => $info->{id} }, | 
| 43 | 0 |  |  |  |  |  | ); | 
| 44 |  |  |  |  |  |  |  | 
| 45 | 0 | 0 |  |  |  |  | if ($existing) { | 
| 46 | 0 | 0 |  |  |  |  | if ( $opts->{err_on_exists} ) { | 
| 47 | 0 |  |  |  |  |  | return $self->err( 'DestinationExists', | 
| 48 |  |  |  |  |  |  | "$opts->{id} already has status $path:$existing\n" | 
| 49 |  |  |  |  |  |  | ); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  | else { | 
| 52 | 0 |  |  |  |  |  | print | 
| 53 |  |  |  |  |  |  | "$opts->{id} already has status $path:$existing\n"; | 
| 54 | 0 |  |  |  |  |  | next; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =cut | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | # Not yet sure what I should be doing here. Will comment it out until | 
| 61 |  |  |  |  |  |  | # after the next issue reorganisation | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | my @unsatisfied = map { $_->[0] } $dbw->xarrayrefs( | 
| 64 |  |  |  |  |  |  | select        => 'p.path', | 
| 65 |  |  |  |  |  |  | from          => 'project_issues pi', | 
| 66 |  |  |  |  |  |  | inner_join    => 'projects p', | 
| 67 |  |  |  |  |  |  | on            => 'p.id = pi.project_id', | 
| 68 |  |  |  |  |  |  | inner_join    => 'hubs h', | 
| 69 |  |  |  |  |  |  | on            => 'h.id = p.hub_id', | 
| 70 |  |  |  |  |  |  | where         => { 'pi.issue_id' => $info->{id} }, | 
| 71 |  |  |  |  |  |  | except_select => 'p2.path', | 
| 72 |  |  |  |  |  |  | from          => 'projects p', | 
| 73 |  |  |  |  |  |  | inner_join    => 'hub_related_projects hrp', | 
| 74 |  |  |  |  |  |  | on            => 'hrp.hub_id = p.hub_id', | 
| 75 |  |  |  |  |  |  | inner_join    => 'projects p2', | 
| 76 |  |  |  |  |  |  | on            => 'p2.id = hrp.project_id', | 
| 77 |  |  |  |  |  |  | inner_join    => 'hubs h', | 
| 78 |  |  |  |  |  |  | on            => 'h.id = p2.hub_id', | 
| 79 |  |  |  |  |  |  | where         => { 'p.id' => $pinfo->{id} }, | 
| 80 |  |  |  |  |  |  | ); | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | if (@unsatisfied) { | 
| 83 |  |  |  |  |  |  | my $name = $dbw->xval( | 
| 84 |  |  |  |  |  |  | select     => ['n.name'], | 
| 85 |  |  |  |  |  |  | from       => 'nodes n', | 
| 86 |  |  |  |  |  |  | inner_join => 'hubs h', | 
| 87 |  |  |  |  |  |  | on         => 'h.id = p.hub_id', | 
| 88 |  |  |  |  |  |  | where      => { 'n.id' => $pinfo->{id} }, | 
| 89 |  |  |  |  |  |  | ); | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | @unsatisfied = join ', ', @unsatisfied; | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | return $self->err( 'NoCooperation', | 
| 94 |  |  |  |  |  |  | "$path\@$name has no cooperation with @unsatisfied" ); | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  | =cut | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 0 |  | 0 |  |  |  | $opts->{message} ||= $self->prompt_edit; | 
| 99 |  |  |  |  |  |  |  | 
| 100 |  |  |  |  |  |  | $opts->{change_id} = | 
| 101 | 0 |  |  |  |  |  | $self->new_change( parent_id => $info->{first_change_id}, ); | 
| 102 |  |  |  |  |  |  |  | 
| 103 | 0 |  | 0 |  |  |  | $opts->{message} //= 'junk'; | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | my $status_id = $dbw->xval( | 
| 106 |  |  |  |  |  |  | select => 'id', | 
| 107 |  |  |  |  |  |  | from   => 'issue_status', | 
| 108 |  |  |  |  |  |  | where  => { | 
| 109 |  |  |  |  |  |  | project_id => $pinfo->{id}, | 
| 110 | 0 |  |  |  |  |  | def        => 1, | 
| 111 |  |  |  |  |  |  | }, | 
| 112 |  |  |  |  |  |  | ); | 
| 113 |  |  |  |  |  |  |  | 
| 114 | 0 |  |  |  |  |  | my $id = $dbw->nextval('nodes'); | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | $dbw->xdo( | 
| 117 |  |  |  |  |  |  | insert_into => [ | 
| 118 |  |  |  |  |  |  | 'func_new_issue', qw/change_id id src_id | 
| 119 |  |  |  |  |  |  | issue_status_id title / | 
| 120 |  |  |  |  |  |  | ], | 
| 121 |  |  |  |  |  |  | select => [ | 
| 122 |  |  |  |  |  |  | qv( $opts->{change_id} ), qv($id), | 
| 123 |  |  |  |  |  |  | qv( $info->{id} ),        qv($status_id), | 
| 124 |  |  |  |  |  |  | 'i.title' | 
| 125 |  |  |  |  |  |  | ], | 
| 126 |  |  |  |  |  |  | from  => 'issues i', | 
| 127 |  |  |  |  |  |  | where => { | 
| 128 |  |  |  |  |  |  | 'i.id' => $info->{id}, | 
| 129 |  |  |  |  |  |  | }, | 
| 130 | 0 |  |  |  |  |  | ); | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | my $src = $dbw->xval( | 
| 133 |  |  |  |  |  |  | select => 'n.path', | 
| 134 |  |  |  |  |  |  | from   => 'nodes n', | 
| 135 |  |  |  |  |  |  | where  => { 'n.id' => $info->{id}, }, | 
| 136 | 0 |  |  |  |  |  | ); | 
| 137 |  |  |  |  |  |  |  | 
| 138 | 0 |  |  |  |  |  | my $dest = $dbw->xval( | 
| 139 |  |  |  |  |  |  | select => 'n.path', | 
| 140 |  |  |  |  |  |  | from   => 'nodes n', | 
| 141 |  |  |  |  |  |  | where  => { 'n.id' => $id, }, | 
| 142 |  |  |  |  |  |  | ); | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | $self->end_change( | 
| 145 |  |  |  |  |  |  | id               => $opts->{change_id}, | 
| 146 |  |  |  |  |  |  | action_format    => "push issue $src (%s) $dest (%s)", | 
| 147 |  |  |  |  |  |  | action_node_id_1 => $info->{id}, | 
| 148 |  |  |  |  |  |  | action_node_id_2 => $pinfo->{id}, | 
| 149 |  |  |  |  |  |  | message          => "[ forked: $src -> $dest ]\n\n" | 
| 150 |  |  |  |  |  |  | . $opts->{message}, | 
| 151 | 0 |  |  |  |  |  | ); | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | } | 
| 154 |  |  |  |  |  |  | } | 
| 155 | 0 |  |  |  |  |  | ); | 
| 156 |  |  |  |  |  |  |  | 
| 157 | 0 |  |  |  |  |  | return $self->ok('PushIssue'); | 
| 158 |  |  |  |  |  |  | } | 
| 159 |  |  |  |  |  |  |  | 
| 160 |  |  |  |  |  |  | 1; | 
| 161 |  |  |  |  |  |  | __END__ |