Git-Code-Review

 view release on metacpan or  search on metacpan

lib/Git/Code/Review/Command/config.pm  view on Meta::CPAN

    my $action = undef;
    my @files_to_edit = ();
    $action = 'edit';
    my $file = prompt("Which file would you like to edit?", menu => \%files);

    # Configure the default if not there
    my $filename = _default_file( $file, \%cfg );
    unless(defined $filename && -f $filename) {
        output({stderr=>1,color=>"red"}, "Invalid config file, this shouldn't happen. ($filename)");
        exit 1;
    }
    push @files_to_edit, $filename;

    my @confirmed_files = ();
    # Edit files in the list.
    foreach my $filename (@files_to_edit) {
        gcr_open_editor(modify => $filename);
        if ( confirm( "Are you sure you want to make this change?" ) ) {
            $audit->run( add => $filename );
            push @confirmed_files, $filename;
        } else {
            # remove the file
            my @dirty = $audit->run( qw{ status --porcelain --ignore-submodules=all -- }, $filename );
            if ( my $status = shift @dirty ) {
                if ( substr( $status, 0, 2 ) eq '??' ) {
                    # untracked file - delete it
                    unlink $filename or warn output({stderr=>1,color=>"red"}, "Could not delete $filename: $!");
                } else {
                    # check out the old version
                    $audit->run( checkout => $filename );
                }
            }
        }
    }
    if ( scalar @confirmed_files ) {
        # commit and push any changes
        $audit->run( commit => '-m',
            join("\n", $message,
                Dump({
                    reviewer => $cfg{user},
                    state    => "config",
                    files    => \@confirmed_files,
                    skip     => 'true',
                }),
            )
        );
        gcr_push();
    }
}

sub _default_file {
    my ($file, $cfg) = @_;
    my %content = (
        'mailhandler.config' => [
            "; Mailhandler configuration",
            ';',
            ';[global]',
            ';  server = imap.mailserver.com',
            ';  port = 993',
            ';  ssl = 1',
            ';  credentials-file = /etc/code-review/sox_code_review_email.conf',
            ';  folder = INBOX',
            ';  auto-approve = 1',
        ],
        'notification.config' => [
            "; Notification Configuration for audit",
            ";   Valid headers are global and template where template takes a name",
            '; ',
            ';[global]',
            ";  from = $cfg->{user}",
            ";  headers.reply-to = $cfg->{user}",
            ';  jira-url = https://jira.company.com/jira',
            ';  jira-credential-file = /etc/code-review/jira.conf',
            '',
            ';[template "select"]',
            ";  to = $cfg->{user}",
            '',
            ';[template "report"]',
            ';  jira-title = Code Review Project',
            ';  jira-project = CRP',
            ';  jira-assignee = user',
            ';  to = codereview@company.com',
        ],
        'README' => [
            "README with the purpose, guidelines and other information for the code review",
        ],
        'special-days.txt' => [
            '# This is a simple text file containing a list of dates in yyyy-mm-dd format e.g. 2015-04-01',
            '# lines that begin with a # are ignored, you can also use a # at the end of the line',
            '# you can comma separate multiple dates on a single line or on multiple lines or both',
            '# white space is usually ignored',
            '',
            '#2015-04-01  # April fools day, no we do not give holiday to people for this',
            '',
            '# 2015 public holidays',
            "2015-01-01  # New Year's Day",
            '2015-04-03  # Friday	Good Friday',
            '2015-04-05  # Sunday	Easter Sunday',
            '2015-05-25  # Monday	Whit Monday',
            '2015-12-25, 2015-12-26  # Christmas and boxing day',
            '',
            '# 2015 special days',
            '2015-06-15  # Monday    Team outing',
            '',
            '# 2016 holidays',
            '2016-01-01  # new years day for next year',
            '',
            "# that's it, pretty simple huh?",
        ],
        'review.config' => [
            ';[labels.approve]',
            ';  cosmetic    = "Cosmetic change only, no functional difference."',
            ';  correct     = "Calculations are all accurate."',
            ';  outofbounds = "Changes are not in the bounds for the audit."',
            ';  other       = "Other (requires explanation)"',
            '',
            ';[labels.concerns]',
            ';  incorrect = "Calculations are incorrect."',
            ';  unclear = "Code is not clear, requires more information from the author."',
            ';  other = "Other"',
        ],



( run in 1.998 second using v1.01-cache-2.11-cpan-140bd7fdf52 )