Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
committable: much better output
Also, keep results in the same order
  • Loading branch information
AlexDaniel committed Jul 15, 2016
1 parent 4b7b3b4 commit 32cdbc8
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions committable.pl
Expand Up @@ -70,7 +70,8 @@ sub process_message {

my $filename = $self->write_code($code);

my %outputs;
my @result;
my %lookup;
for my $commit (@commits) {
# convert to real ids so we can look up the builds
my $full_commit = $self->to_full_commit($commit);
Expand All @@ -86,10 +87,21 @@ sub process_message {

$out //= '';
$out .= " exit code = $exit" if ($exit != 0);
push @{$outputs{$out}}, substr($commit, 0, 7);
my $short_commit = substr($commit, 0, 7);

# Code below keeps results in order. Example state:
# @result = [ { commits => ['A', 'B'], output => '42' },
# { commits => ['C'], output => '69' }, ];
# %lookup = { '42' => 0, '69' => 1 }
if (not exists $lookup{$out}) {
$lookup{$out} = $#result;
push @result, { commits => [$short_commit], output => $out };
} else {
push @{@result[$lookup{$out}]->{commits}}, $short_commit;
}
}

$msg_response .= join("\n", map { join(',', @{$outputs{$_}}) . "=$_" } sort keys %outputs);
$msg_response .= '|' . join("\n|", map { '' . join(',', @{$_->{commits}}) . '禄: ' . $_->{output} } @result);
} else {
$msg_response = help();
}
Expand Down

0 comments on commit 32cdbc8

Please sign in to comment.