# Type: Input and output # Category: Task # Description: Sets issue ID for the current task. # Dialog: Task -> -> Activity # Fields: asked # Uses: YesNo # Author: Andriy Lesyuk new Orangutan::Context( request => sub { my ($context, $user) = @_; my $task = $user->GetTask; if (!$task) { my $last = $user->GetLast; if ($last) { if ($last->GetEnd->Elapsed <= 3600) { $task = $last; } } } if ($task) { $context->SetField('asked', 1); my $number = $user->GetResponse('Number'); if ($number) { $number->InsertForeignHandler($context); } if ($main::query->GetBestIssues($user, $task->GetProject('id'))) { my $message = Orangutan::Context::Random( 'You should specify the issue.', 'Please specify the issue.', 'What issue is this?', 'What is the issue?' ).' '; if ($main::query->Rows == 1) { $message .= Orangutan::Context::Random( 'I guess you work on this one', 'Maybe this one', 'It might be' ); $context->SetField('issue', $main::query->GetRow(0)->{'id'}); my $yesno = $user->GetResponse('YesNo'); if ($yesno) { $yesno->InsertForeignHandler($context, 1800); } } else { $message .= Orangutan::Context::Random( 'Some issues which might be what you are working on', 'I guess you work on one of these', 'Some of the issues' ); } $message .= ":\n"; while (defined(my $issue = $main::query->Next)) { utf8::decode($issue->{'subject'}); $issue->{'status_name'} =~ tr/[A-Z]/[a-z]/; $issue->{'priority_name'} =~ tr/[A-Z]/[a-z]/; $message .= sprintf("#%d) ", $issue->{'id'}); $message .= $issue->{'tracker_name'}; $message .= ' ('.$issue->{'status_name'}.'): '; $message .= $issue->{'subject'}; $message .= ' ['.$issue->{'priority_name'}.']'; if (!defined($task->GetProject)) { $message .= ' ('.$issue->{'project_name'}.')'; } $message .= "\n"; } $message .= Orangutan::Context::Random( 'To create a task without an issue answer "None".', 'You may answer "None"...' ); return $message; } else { return Orangutan::Context::Random( 'What is the issue number?', 'Tell me the issue number', 'What issue is this?', 'What is the issue?' ); } } return undef; }, response => sub { my ($context, $user, $issue) = @_; my @result = ( ); my @regexps = ( '(?:I(?:\'m| am)? )?do(?:ing)? (?:this|it) (?:for|on|at) (?:(?:the )?issue )?(?:#|No\.? ?)?([0-9]+)!*\.*', '(?:Change|set) (?:the )?(?:number|ID) of (?:(?:the|my) )?issue to (?:#|No\.? ?)?([0-9]+)!*\.*', '(?:Change|set) (?:(?:the|my) )?issue(?: (?:number|ID))? to (?:#|No\.? ?)?([0-9]+)!*\.*', '(?:The )?(?:number|ID) of (?:(?:the|my) )?issue is (?:#|No\.? ?)?([0-9]+)!*\.*', '(?:(?:The|my) )?issue(?: (?:number|ID))? is (?:#|No\.? ?)?([0-9]+)!*\.*', 'Use (?:(?:the )?issue )?(?:#|No\.? ?)?([0-9]+)!*\.*' ); if ($context->GetField('asked')) { push(@regexps, '(?:This|it) is (?:#|No\.? ?)?([0-9]+)!*\.*'); push(@regexps, '(?:(?:The )?issue )?(?:#|No\.? ?)?([0-9]+)!*\.*'); } foreach my $regexp (@regexps) { if ($issue =~ /^$regexp$/i) { push(@result, 1); push(@result, $1); last; } } if (scalar @result == 0) { @regexps = ( '(?:Clear|unset|remove) (?:the )?(?:number|ID) of (?:(?:the|my) )?issue!*\.*', '(?:Clear|unset|remove) (?:(?:the|my) )?issue(?: (?:number|ID))?!*\.*' ); if ($context->GetField('asked')) { push(@regexps, 'None!*\.*'); push(@regexps, 'Skip!*\.*'); } foreach my $regexp (@regexps) { if ($issue =~ /^$regexp$/i) { push(@result, 2); push(@result, undef); last; } } } return @result; }, handler => sub { my ($context, $user, $item, $issueid) = @_; my $task = $user->GetTask; if (!$task) { my $last = $user->GetLast; if ($last) { if ($last->GetEnd->Elapsed <= 3600) { $task = $last; } } } $context->UnsetField('asked'); if ($task) { if (($item != -1) || ($issueid eq 'Y')) { my $issue; if (($item == 1) || ($item == -2)) { $issue = $main::query->GetIssue($issueid); if (defined($issue)) { if ($main::query->Can('edit_time_entries', $user, $issue->{'project_id'})) { if ($issue->{'is_closed'}) { $user->SendMessage([ 'I hope you know that this issue is already closed...', 'Weird. This issue seems to be closed...', 'Hm... This issue looks to be closed...' ]); } elsif ($issue->{'done_ratio'} == 100) { $user->SendMessage([ 'Hm... Someone believes that this issue has been completed...', 'Weird... This issue is marked to be completed...', 'Hm... I thought it was done...' ]); } } else { my $format = Orangutan::Context::Random( 'To be able to log time for this issue you must be a member of %s.', "Sorry. I can't use this issue - you are not a member of %s!", "You can't log time for this issue." ); $user->SendMessage(sprintf($format, $issue->{'project_name'})); my $yesno = $user->GetResponse('YesNo'); if ($yesno) { $yesno->RemoveForeignHandler($context); } return 1; } } } elsif ($item == 2) { $task->SetIssue; if ($task->GetID) { $user->ResubmitLastTask; } if ($user->GetRequest($context->GetID)) { $user->RemoveRequest($context); } $main::config->Context('Ok')->Tell($user); my $number = $user->GetResponse('Number'); if ($number) { $number->RemoveForeignHandler($context); } my $yesno = $user->GetResponse('YesNo'); if ($yesno) { $yesno->RemoveForeignHandler($context); } $context->SetTimeout; return 1; } else { $issueid = $context->GetField('issue'); $issue = $main::query->GetIssue($issueid); } if (defined($issue)) { $task->SetIssue($issue->{'id'}); my $projectid = $task->GetProject('id'); my $message = Orangutan::Context::Random('Ok...', 'Got it!..', 'I see...'); if (!defined($projectid) || ($projectid != $issue->{'project_id'})) { $task->SetProject( id => $issue->{'project_id'}, name => $issue->{'project_name'} ); if (defined($task->GetActivity)) { my $activityid = $main::query->ActivityExists($task->GetActivity, $task->GetProject('id')); if ($activityid) { $task->SetActivity( id => $activityid, name => $task->GetActivity ); } else { $task->SetActivity; } } if (!defined($task->GetActivity) && defined($user->GetActivity)) { my $activityid = $main::query->ActivityExists($user->GetActivity, $task->GetProject('id')); if ($activityid) { $task->SetActivity( id => $activityid, name => $user->GetActivity ); } } if (!defined($task->GetActivity)) { my $default_activity = $main::query->GetDefaultActivity($task->GetProject('id')); if (defined($default_activity)) { $task->SetActivity( id => $default_activity->{'id'}, name => $default_activity->{'name'} ); } } if (defined($task->GetActivity)) { $message .= ' Using activity "'.$task->GetActivity.'"...'; } } if ($task->GetID) { $user->ResubmitLastTask; } if ($user->GetRequest($context->GetID)) { $user->RemoveRequest($context); } $user->SendMessage($message); my $number = $user->GetResponse('Number'); if ($number) { $number->RemoveForeignHandler($context); } $context->SetTimeout; } else { if ($item == -1) { $user->SendMessage('Weird... The issue has gone... :S'); } else { $user->SendMessage([ 'Such issue does not exist.', "I can't find such issue.", 'No such issue.' ]); } } } else { $user->SendMessage([ 'Then just tell me the correct issue.', 'Ok... Tell me the correct issue ID.', 'So what is the correct issue?' ]); } } else { $user->SendMessage([ 'First you tell me your task then you tell me the issue this task is for - not vice versa.', "And? I don't have any information regarding the task you are working on!..", 'I need to know what are you doing to use the issue...', "Let's begin from what are you working on..." ]); my $number = $user->GetResponse('Number'); if ($number) { $number->RemoveForeignHandler($context); } $context->SetTimeout; } my $yesno = $user->GetResponse('YesNo'); if ($yesno) { $yesno->RemoveForeignHandler($context); } return 1; }, ontimeout => sub { my ($context, $user) = @_; $context->UnsetField('asked'); my $number = $user->GetResponse('Number'); if ($number) { $number->RemoveForeignHandler($context); } my $yesno = $user->GetResponse('YesNo'); if ($yesno) { $yesno->RemoveForeignHandler($context); } $context->SetTimeout; return 1; }, ontask => sub { my ($context, $user, $type, $status) = @_; if (($status eq 'start') || ($status eq 'cancel')) { my $issue = $user->GetResponse($context->GetID); if ($issue) { if ($user->GetRequest($context->GetID)) { $user->RemoveRequest($issue); } elsif ($issue->GetField('asked')) { if ($status eq 'cancel') { $user->SendMessage([ 'Then you may ignore my question about the issue...', 'Well... Then I do not need the issue anymore...', 'Forget about issue...' ]); } $issue->UnsetField('asked'); my $number = $user->GetResponse('Number'); if ($number) { $number->RemoveForeignHandler($context); } my $yesno = $user->GetResponse('YesNo'); if ($yesno) { $yesno->RemoveForeignHandler($issue); } $issue->SetTimeout; } } } }, help => { title => 'How can I change the issue of the task?', question => [ '^(?:How )?(?:(?:can|do) I |to )(?:change|set) (?:the )?(?:number|ID) of (?:the )?issue'. '(?: (?:of|for) (?:the )?(?:current )?task)?\?*!*\.*$', '^(?:How )?(?:(?:can|do) I |to )(?:change|set) (?:the )?issue(?: (?:number|ID))?'. '(?: (?:of|for) (?:the )?(?:current )?task)?\?*!*\.*$' ], answer => "Any task you enter should be assicated with some issue. ". "You can set issue for the task anytime.\n". "Some samples to do this:\n". " o The ID of the issue is #98\n". " o Change issue id to #15\n". " o I do this for #58\n". " o Use issue #68\n". "You can also set issue when creating a task:\n". " o Writing base class on #30", weight => 620 }, timeout => 1800, weight => [ undef, 0, undef ] ); # kate: syntax perl