App-Gitc

 view release on metacpan or  search on metacpan

bin/gitc-pass  view on Meta::CPAN

    my $id = meta_data_add({
        action    => 'pass',
        changeset => $changeset,
    });
    to_undo { meta_data_rm(id => $id, changeset => $changeset) };

    # publish the new master branch to the world
    failure_warning "\nGitc failed when publishing the changeset. "
        . "It was probably a push collision.\n"
        . "Try 'gitc pass' again.\n";
    git "push origin master:master";
    return;  # to make sure the push happens in void context
};

# published successfully, now we can send the email
$send_email->() if $send_email;

my $its = its_for_changeset($changeset);
if ($its) {
    # update the ITS status
    my $its_name = $its->label_service;
    eval {
        if ( my $issue = $its->get_issue($changeset, reload => 1) ) {
            my $project = project_name();
            my $what_happened = $its->transition_state({
                command   => 'pass',
                issue     => $issue,
                message   => "$project#$changeset passed code review",
                changeset => $changeset,
            });
        }
    };
    warn "$its_name Error: ".$@ if $@;
}

# if this fails, don't rollback, tell the user to do it manually
my $base = "refs/tags/cs/$changeset";
my $push_command
    = "push origin"
    . " $base/head:$base/head"
    . " $base/to-master:$base/to-master"
    . ($self_review ? '' : " :pu/$changeset")
    ;
eval { git $push_command };
if ($@) {
    warn "Failed while cleaning up after a successful 'pass'.  I\n"
        . "tried to execute the following command:\n"
        . "\n"
        . "  git $push_command\n"
        . "\n"
        . "but got this message: $@\n"
        . "Please help out by doing the above command manually. Thanks.\n"
        ;
}

# reinstate any changes present when we started
git "stash apply $stash" if $stash;

############################### helper subroutines #######################
# tells the user to resolve any merge conflicts, suspends this process
# and waits to be resumed.  Once resumed, verify that the conflict
# was resolved and committed.  If not, let the user try again or
# die.
#
# This code is very similar to code in gitc-promote.  Unfortunately, there
# were enough differences that a common framework couldn't be factored out
# cleanly.
sub let_user_resolve_conflict {
    my ($changeset, $again) = @_;
    if ( not $again ) {
        warn "There were conflicts merging '$changeset' to master.\n";

        # let the reviewer resolve the conflicts
        warn  "This process will suspend so that you can manually resolve\n"
            . "the conflict and commit.  Once you've done that, 'fg' this\n"
            . "process and the merge will continue.\n"
            ;
    }

    my $suspended = 1;
    local $SIG{CONT} = sub { $suspended = 0 };
    kill STOP => $$;
    while ($suspended) { } # spin while signals propagate (necessary?)

    my $confirm_note = q{NOTE: Saying 'no' will abort the pass and put you back into the review branch.};
    my $confirm_text = q{Do you want to try resolving conflicts again?};

    # we're back, verify the state of the tree
    if( git('diff') or git('diff --cached') ) {
        warn "You shall not pass! You have a dirty tree.\n";
        warn "$confirm_note\n";
        if ( confirm($confirm_text) ) {
            return let_user_resolve_conflict($changeset, 'again');
        }
        die "You didn't resolve a merge conflict\n";
    }

    # verify that the previous commit is a merge
    if ( not is_merge_commit('HEAD') ) {
        warn "The most recent commit is not a merge.\n";
        warn "$confirm_note\n";
        if ( confirm($confirm_text) ) {
            return let_user_resolve_conflict($changeset, 'again');
        }
        die   "You were supposed to resolve merge conflicts for '$changeset' but\n"
            . "the most recent commit does not look like a merge commit.\n";
    }

    return;
}

__END__

=pod

=head1 NAME

gitc-pass - Pass a changeset review

=head1 VERSION

version 0.60

=head1 AUTHOR

Grant Street Group <developers@grantstreet.com>

=head1 COPYRIGHT AND LICENSE

This software is Copyright (c) 2013 by Grant Street Group.

This is free software, licensed under:

  The GNU Affero General Public License, Version 3, November 2007

=cut



( run in 0.621 second using v1.01-cache-2.11-cpan-437f7b0c052 )