<commit_before>#!/usr/bin/env perl6
# Copyright © 2016
#     <NAME> <<EMAIL>>
#     <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use lib ‘.’;
use Whateverable;

use IRC::Client;

unit class Committable is Whateverable;

constant LIMIT      = 1000;
constant TOTAL-TIME = 60*3;

method help($message) {
    “Like this: {$message.server.current-nick}: f583f22,HEAD say ‘hello’; say ‘world’”
};

multi method irc-to-me($message where { .text !~~ /:i ^ [help|source|url] ‘?’? $ | ^stdin /
                                        # ↑ stupid, I know. See RT #123577
                                        and .text ~~ /^ \s* $<config>=\S+ \s+ $<code>=.+ / }) {
    my $value = self.process($message, ~$<config>, ~$<code>);
    return ResponseStr.new(:$value, :$message);
}

method process($message, $config, $code is copy) {
    my $start-time = now;
    my @commits;
    my $old-dir = $*CWD;
    if $config ~~ / ‘,’ / {
        @commits = $config.split: ‘,’;
    } elsif $config ~~ /^ $<start>=\S+ ‘..’ $<end>=\S+ $/ {
        chdir RAKUDO; # goes back in LEAVE
        return ‘Bad start’ if run(‘git’, ‘rev-parse’, ‘--verify’, $<start>).exitcode != 0;
        return ‘Bad end’   if run(‘git’, ‘rev-parse’, ‘--verify’, $<end>).exitcode   != 0;
        my ($result, $exit-status, $exit-signal, $time) =
          self.get-output(‘git’, ‘rev-list’, “$<start>^..$<end>”); # TODO unfiltered input
        return ‘Couldn't find anything in the range’ if $exit-status != 0;
        @commits = $result.split: “\n”;
        my $num-commits = @commits.elems;
        return “Too many commits ($num-commits) in range, you're only allowed {LIMIT}” if $num-commits > LIMIT;
    } elsif $config ~~ /:i releases / {
        @commits = <2015.10 2015.11 2015.12 2016.02 2016.03 2016.04 2016.05 2016.06 2016.07 HEAD>;
    } else {
        @commits = $config;
    }

    my ($succeeded, $code-response) = self.process-code($code, $message);
    return $code-response unless $succeeded;
    $code = $code-response;

    my $filename = self.write-code($code);

    my @result;
    my %lookup;
    for @commits -> $commit {
        # convert to real ids so we can look up the builds<commit_msg>Better error message for wrong ranges<commit_after>#!/usr/bin/env perl6
# Copyright © 2016
#     <NAME> <<EMAIL>>
#     <NAME> <<EMAIL>>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

use lib ‘.’;
use Whateverable;

use IRC::Client;

unit class Committable is Whateverable;

constant LIMIT      = 1000;
constant TOTAL-TIME = 60*3;

method help($message) {
    “Like this: {$message.server.current-nick}: f583f22,HEAD say ‘hello’; say ‘world’”
};

multi method irc-to-me($message where { .text !~~ /:i ^ [help|source|url] ‘?’? $ | ^stdin /
                                        # ↑ stupid, I know. See RT #123577
                                        and .text ~~ /^ \s* $<config>=\S+ \s+ $<code>=.+ / }) {
    my $value = self.process($message, ~$<config>, ~$<code>);
    return ResponseStr.new(:$value, :$message);
}

method process($message, $config, $code is copy) {
    my $start-time = now;
    my @commits;
    my $old-dir = $*CWD;
    if $config ~~ / ‘,’ / {
        @commits = $config.split: ‘,’;
    } elsif $config ~~ /^ $<start>=\S+ ‘..’ $<end>=\S+ $/ {
        chdir RAKUDO; # goes back in LEAVE
        if run(‘git’, ‘rev-parse’, ‘--verify’, $<start>).exitcode != 0 {
            return “Bad start, cannot find a commit for “$<start>””;
        }
        if run(‘git’, ‘rev-parse’, ‘--verify’, $<end>).exitcode   != 0 {
            return “Bad end, cannot find a commit for “$<end>””;
        }
        my ($result, $exit-status, $exit-signal, $time) =
          self.get-output(‘git’, ‘rev-list’, “$<start>^..$<end>”); # TODO unfiltered input
        return ‘Couldn't find anything in the range’ if $exit-status != 0;
        @commits = $result.split: “\n”;
        my $num-commits = @commits.elems;
        return “Too many commits ($num-commits) in range, you're only allowed {LIMIT}” if $num-commits > LIMIT;
    } elsif $config ~~ /:i releases / {
        @commits = <2015.10 2015.11 2015.12 2016.02 2016.03 2016.04 2016.05 2016.06 2016.07 HEAD>;
    } else {
        @commits = $config;
    }

    my ($succeeded, $code-response) = self.process-code($code, $message);
    return $code-response unless $succeeded;
    $code = $code-response;

    my $filename = self.write-code($code);

    my @result;
    my %lookup;
    for @commits -> $commit {
        # convert to real ids so we can look up the builds
{'fraction_non_alphanumeric': 0.15371209480655282, 'fraction_numerical': 0.028232833739979087, 'mean_word_length': 2.664750957854406, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 45, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5765734', 'n_tokens_mistral': 2004, 'n_tokens_neox': 1830, 'n_words': 626}