blib/lib/App/karr/Cmd/Handoff.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/App/karr/Cmd/GetRefs.pm ↑ Summary blib/lib/App/karr/Cmd/List.pm »
1 # ABSTRACT: Hand off a task for review
2  
3 package App::karr::Cmd::Handoff;
4 our $VERSION = '0.602';
5 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use MooX::Cmd;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use MooX::Options (
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 usage_string => 'USAGE: karr handoff ID --claim NAME [--note TEXT] [--block REASON] [--release]',
9 2 );
10 0 ▶use App::karr::Role::BoardAccess;
Subroutine BEGIN: called CC=1 SCAR=2.6
11 use App::karr::Role::Output;
12 use App::karr::Role::TaskMutation;
13 use App::karr::Role::ClaimDefault;
14 use App::karr::Task;
15 use App::karr::Config;
16 use App::karr::Error ();
17 use Time::Piece;
18  
19 # TaskMutation composes Role::ClaimTimeout, which is where check_claim comes
20 # from; handoff no longer names it separately because it no longer applies the
21 # claim rule on its own terms.
22 with 'App::karr::Role::BoardAccess', 'App::karr::Role::Output',
23 'App::karr::Role::TaskMutation', 'App::karr::Role::ClaimDefault';
24  
25  
26 option claim => (
27 is => 'ro',
28 format => 's',
29 doc => 'Agent name claiming the task (defaults to KARR_CLAIM)',
30 );
31  
32 option note => (
33 is => 'ro',
34 format => 's',
35 doc => 'Handoff note to append to body',
36 );
37  
38 option timestamp => (
39 is => 'ro',
40 short => 't',
41 doc => 'Prefix timestamp to note',
42 );
43  
44 option block => (
45 is => 'ro',
46 format => 's',
47 doc => 'Block task with reason',
48 );
49  
50 option release => (
51 is => 'ro',
52 doc => 'Release claim after handoff',
53 );
54  
55 sub execute {
56 my ($self, $args_ref, $chain_ref) = @_;
57  
58 $self->check_positional_args($args_ref, 1);
59  
60 $self->sync_before;
61 $self->require_board;
62  
63 my @pos = $self->positional_args($args_ref);
64 # See the note in Cmd::Move: length, not truth, or the id "0" is read as no
65 # id at all and answered with a usage error instead of "not found" (#239).
66 # normalize_task_id accepts the house kNNN spelling (k30 == 30) here, the way
67 # parse_ids does for the batch commands, and leaves undef/"0" untouched.
68 my $id = $self->normalize_task_id($pos[0]);
69 # No suggestion line here, deliberately (ticket k263). This guard fires only
70 # when the id is missing, and --claim is required on this command, so by the
71 # time it is reached the caller has typed nothing that could be quoted back:
72 # a suggestion would be `karr handoff ID --claim NAME`, which is the "Usage:"
73 # line again in placeholders -- the generic example k263 refuses, and the one
74 # line a `tail -1` would keep. The "Usage:" line is the actionable line here.
75 die "Usage: karr handoff ID --claim NAME [--note TEXT] [--block REASON] [--release]\n"
76 unless defined $id && length $id;
77  
78 # --claim was `required => 1` before ADR 0005; now KARR_CLAIM fills it when the
79 # flag is omitted. A handoff still needs a claim, so when neither supplies one
80 # this is a usage error (exit 2, as the old required was) that names both ways.
81 my $claim = $self->resolved_claim;
82 $self->usage_error(
83 App::karr::Error::mandatory_claim_message(
84 'handoff', 'handoff', $id, '--claim', 'NAME' ) )
85 unless defined $claim && length $claim;
86  
87 # The status a handoff lands in: the board's review column when it has one,
88 # the derived last non-terminal column when it does not -- a literal
89 # C<review> here made handoff unusable on any board without that column
90 # (ticket #102). The derivation lives on the config, next to the
91 # terminal-status rule it builds on.
92 my $target = App::karr::Config->from_merged( $self->store->effective_config )
93 ->handoff_status;
94  
95 # Handoff used to read the task, mutate it and save it back unguarded, so a
96 # claim landing in that window was overwritten rather than obeyed -- the same
97 # read-then-write #44/#46/#56 closed everywhere else. update_task_guarded is
98 # that closure: the claim rule below is applied to the revision this writes,
99 # and re-applied if another agent gets in first (ticket #97).
100 my $task = $self->update_task_guarded($id, sub {
101 my ($task) = @_;
102  
103 # The one claim-ownership rule, shared with move/edit/delete/archive rather
104 # than reimplemented here.
105 $self->check_claim($task, $claim);
106  
107 # And the one status-change path, so the handoff obeys the same
108 # require_claim, status validation and lifecycle stamps as `karr move`
109 # (tickets #54, #55, #68). --claim is required on this command, so a target
110 # status flagged require_claim is always satisfied.
111 $self->apply_status_change($task, $target, $claim);
112  
113 # Refresh claim
114 $task->claimed_by($claim);
115 $task->claimed_at(gmtime->datetime . 'Z');
116  
117 # Block if requested. length, not truth: --block 0 is a reason (ticket #153,
118 # extending ticket #78's rule to the handoff path).
119 if (defined $self->block && length $self->block) {
120 $task->block($self->block);
121 }
122  
123 # Append note. length, not truth: --note 0 is a note (ticket #153, the
124 # same fix as --append_body in edit). The stamp and the blank-line
125 # separator come from App::karr::Task::append_body, which is also what
126 # edit's --append-body calls: this was a copy of that code, and the two
127 # had already drifted apart over the stamp (ticket #238).
128 $task->append_body( $self->note, $self->timestamp )
129 if defined $self->note && length $self->note;
130  
131 # Release claim if requested
132 if ($self->release) {
133 $task->clear_claimed_by;
134 $task->clear_claimed_at;
135 }
136 });
137  
138 $self->sync_after;
139  
140 # A handoff re-stamps claimed_by, so it is the command that most thoroughly
141 # erases whoever held the card before -- and the one #176's agent, having lost
142 # its own claim name, reaches for. If check_claim above only let it through
143 # because the claim had expired, this is where that is said (#177).
144 my %expired = $self->expired_claim_report( $task->id );
145  
146 # The handoff target is a working column, so apply_status_change above will
147 # have recorded any unsatisfied dependencies; this emits them (ticket #123).
148 my %dependency = $self->dependency_report( $task->id );
149  
150 if ($self->json) {
151 $self->print_json({ %{ $task->to_json_hash }, %expired, %dependency });
152 return;
153 }
154  
155 my $msg = sprintf "Handed off task %d -> %s", $task->id, $target;
156 # length, not truth on this side too: the guard above blocks the card for
157 # --block 0, so the line reporting the handoff has to say so -- it read
158 # `if $self->block` and denied a block that had just happened (ticket #230,
159 # the reporting half of ticket #153's --block fix).
160 $msg .= sprintf " (blocked: %s)", $self->block
161 if defined $self->block && length $self->block;
162 $msg .= " (claim released)" if $self->release;
163 print "$msg\n";
164 }
165  
166 1;
167  
168 __END__
« blib/lib/App/karr/Cmd/GetRefs.pm ↑ Summary blib/lib/App/karr/Cmd/List.pm »