App-GHPT

 view release on metacpan or  search on metacpan

lib/App/GHPT/WorkSubmitter.pm  view on Meta::CPAN


    my $stories = [
        map {
            $self->_pt_api->project_stories_where(
                project_id => $_,
                filter     => sprintf(
                    '(owner:%s AND (state:started OR state:finished))',
                    $self->pivotaltracker_username
                ),
            )->@*
        } $self->_project_ids->@*
    ];

    $stories = $self->_filter_chores_and_maybe_warn_user($stories);

    return undef unless $stories->@*;

    my %stories_lookup = map { $_->name => $_ } $stories->@*;
    my $chosen_story   = $self->_choose( [ sort keys %stories_lookup ] );

    return (
        $stories_lookup{$chosen_story}->requested_by->name,
        $stories_lookup{$chosen_story}
    );
}

sub _get_story_name ($self) {
    my $story_name = $self->story_name;
    if ( !$story_name ) {
        say q{Please enter the new story's name:};
        $story_name = $self->_read_line;
    }
    return $story_name;
}

sub _read_line ($) {
    while (1) {
        my $l = readline( \*STDIN );
        $l =~ s/^\s+|\s+$//g;
        return $l if $l;
    }
}

sub _filter_chores_and_maybe_warn_user ( $self, $stories ) {
    my ( $chore_stories, $non_chore_stories )
        = part { $_->story_type eq 'chore' ? 0 : 1 } $stories->@*;

    say 'Note: '
        . ( scalar $chore_stories->@* )
        . PL( ' chore', scalar $chore_stories->@* )
        . PL_V( ' is', scalar $chore_stories->@* )
        . ' not shown here (chores by definition do not require review).'
        if $chore_stories;

    return $non_chore_stories // [];
}

sub _confirm_story ( $self, $text ) {
    my $result = $self->_choose(
        [ 'Accept', 'Edit' ],
        { prompt => $text, clear_screen => $ENV{'SUBMIT_WORK_CLEAR'} // 0 }
    );
    return $text if $result eq 'Accept';
    my $fh = solicit($text);
    return do { local $/ = undef; <$fh> };
}

sub _text_for_story ( $self, $story, $reviewer ) {
    join "\n\n",
        $story->name,
        $story->url,
        ( $story->description ? $story->description : () ),
        (
        $self->_include_requester_name_in_pr
        ? 'Reviewer: ' . $reviewer
        : ()
        ),
        ;
}

sub _create_pull_request ( $self, $text ) {
    if ( $self->dry_run ) {
        print $text;
        exit;
    }

    my ( $title, $body ) = split /\n\n/, $text, 2;

    my $res = $self->_github_api->pull_requests->create(
        data => {
            base  => $self->base,
            body  => $body,
            head  => $self->_git_current_branch,
            title => $title,
        },
    );

    unless ( $res->success ) {
        die "Error while creating pull request:\n\n"
            . _format_github_error($res) . "\n";
    }

    return $res->content->{html_url};
}

sub _format_github_error ($res) {
    my $content = $res->content;
    if ( my $msg = $content->{message} ) {
        if ( my $errors = $content->{errors} ) {
            $msg .= "\n\n" . join "\n", map { $_->{message} } @$errors;
        }
        return $msg;
    }
    return $res->raw_content;
}

sub _build_git_remote ($self) {
    my $git_url = $self->_git_config->{'remote.origin.url'} // q{};

    if ( my ( $host, $user, $repo )
        = $git_url =~ m{^git@([^:]+):([^/]+)/([^/]+?)(?:\.git)?$} ) {



( run in 1.066 second using v1.01-cache-2.11-cpan-6aa56a78535 )