# Type: Input # Category: Issue # Description: Shows comments for an issue # Author: Andriy Lesyuk new Orangutan::Context( response => sub { my ($context, $user, $message) = @_; my @result = ( ); # Prepare tracker regexp my $regexp = 'issue'; my $trackers = $main::config->Get('redmine', '_trackers_regexp'); if ($trackers) { $regexp = "(?:issue|$trackers)"; } my @regexps = ( '(?:(?:Show|give)(?: me)? )?(?:comment|note)s? (?:for|of|in) (?:(?:the )?'.$regexp.' )?(?:#|No\.? ?)?([0-9]+)\?*!*\.*', 'What are (?:comment|note)s? (?:for|of|in) (?:(?:the )?'.$regexp.' )?(?:#|No\.? ?)?([0-9]+)\?*!*\.*' ); # Extract issue ID foreach my $regexp (@regexps) { if ($message =~ /^$regexp$/i) { push(@result, 1); push(@result, $1); last; } } return @result; }, handler => sub { my ($context, $user, $item, $issueid) = @_; my $issue = $main::query->GetIssue($issueid); if ($issue) { if (!$user->IsCreator && !$user->IsManager && !$main::query->Can('view_issues', $user, $issue->{'project_id'})) { $user->SendMessage([ 'You have no permissions to access comments for this issue...', "I can't show you comments of this issue...", 'Permission denied!' ]); return; } my $notes = $main::query->GetNotes($issueid); if ($notes) { my $message; if ($notes > 1) { my $format = Orangutan::Context::Random( 'Here are %d comments for %s #%d', 'Showing %d comments for %s #%d' ).'...'; $message = sprintf($format, $notes, $issue->{'tracker_name'}, $issueid); } else { my $format = Orangutan::Context::Random( 'Here is comment for %s #%d', 'Showing comment for %s #%d' ).'...'; $message = sprintf($format, $issue->{'tracker_name'}, $issueid); } $user->SendMessage($message); my @comments = ( ); while (defined(my $note = $main::query->Next)) { utf8::decode($note->{'notes'}); push(@comments, $note); } for (my $i = 0; $i < $notes; $i++) { $message = sprintf("Comment #%d by ", $i + 1); $message .= Orangutan::User::GetDisplayName($comments[$i]->{'user_name'}); my ($min, $hour, $day, $mon, $year, $wday) = (localtime($comments[$i]->{'created_on'}))[1..6]; $message .= sprintf(" on %s, %d %s %04d %02d:%02d", $Orangutan::Date::weekdays[$wday], $day, $Orangutan::Date::months[$mon], $year + 1900, $hour, $min); $message .= ":\n"; ShowIssue_Format(\$comments[$i]->{'notes'}); $message .= $comments[$i]->{'notes'}; $user->SendMessage($message); } } else { $user->SendMessage([ "Can't find any comments for this issue...", 'This issue does not have any comments...', 'No comments...' ]); } } else { $user->SendMessage([ 'I guess you made a mistake in issue ID because I cannot find such issue...', 'Seems such issue does not exist...', 'I cannot find such issue!' ]); } }, help => { title => 'How can I check comments of an issue?', question => '^(?:How )?(?:(?:can|do) I |to )(?:check|see|list) (?:comment|note)s (?:of|in) (?:(?:some|an) )?issue?\?*!*\.*$', answer => "Orangutan can show you all comments of an issue.\n". "Check out samples:\n". " o Show comments of issue #536\n". " o What are notes of #125?\n". " o Comments of #485", weight => 910 } ); # kate: syntax perl