Skip to content

Commit

Permalink
Add link to docs if git push failed
Browse files Browse the repository at this point in the history
  • Loading branch information
perlpunk committed Jan 29, 2025
1 parent 0b3fff4 commit d46fb3f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lib/OpenQA/Git.pm
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,13 @@ sub commit ($self, $args = undef) {
# push changes
if (($self->config->{do_push} || '') eq 'yes') {
$res = $self->_run_cmd(['push'], {batchmode => 1});
return $self->_format_git_error($res, 'Unable to push Git commit') unless $res->{status};
return undef if $res->{status};

my $msg = 'Unable to push Git commit';
if ($res->{return_code} == 128 and $res->{stderr} =~ m/Authentication failed for .http/) {
$msg .= '. See https://open.qa/docs/#_setting_up_git_support on how to setup git support and possibly push via ssh.';
}
return $self->_format_git_error($res, $msg);
}

return undef;
Expand Down
17 changes: 16 additions & 1 deletion t/14-grutasks-git.t
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ subtest 'git clone' => sub {
};
});
my @gru_args = ($t->app, 'git_clone', $clone_dirs, {priority => 10});
my $res = run_gru_job(@gru_args);
my $res;
stderr_like { $res = run_gru_job(@gru_args) } qr{Git command failed.*verify};

is $res->{result}, 'Job successfully executed', 'minion job result indicates success';
#<<< no perltidy
Expand Down Expand Up @@ -400,14 +401,28 @@ subtest 'delete_needles' => sub {
like $error->{message}, qr{Unable to find needle.*99}, 'expected error for not existing needle';

$t->app->config->{global}->{scm} = 'git';
$t->app->config->{'scm git'}->{do_push} = 'yes';
my $openqa_git = Test::MockModule->new('OpenQA::Git');
my @cmds;
$openqa_git->redefine(
run_cmd_with_log_return_error => sub ($cmd) {
push @cmds, "@$cmd";
if (grep m/push/, @$cmd) {
return {status => 0, return_code => 128, stderr => q{fatal: Authentication failed for 'https://github.com/lala}, stdout => ''};
}
return {status => 1};
});
$args{needle_ids} = [4];
stderr_like { $res = run_gru_job(@gru_args) } qr{Git command failed: .*push}, 'Got error on stderr';
is $res->{state}, 'finished', 'git job finished';
like $res->{result}->{errors}->[0]->{message}, qr{Unable to push Git commit. See .*_setting_up_git_support on how to setup}, 'Got error for push';
$t->app->config->{'scm git'}->{do_push} = '';

$openqa_git->redefine(
run_cmd_with_log_return_error => sub ($cmd) {
push @cmds, "@$cmd";
return {status => 1};
});
$res = run_gru_job(@gru_args);
is $res->{state}, 'finished', 'git job finished';
like $cmds[0], qr{git.*rm.*test-nestedneedle-1.json}, 'git rm was executed';
Expand Down
1 change: 1 addition & 0 deletions t/16-utils-runcmd.t
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ my @executed_commands;
my %mock_return_value = (
status => 1,
stderr => undef,
return_code => 0,
);

sub _run_cmd_mock ($cmd) {
Expand Down

0 comments on commit d46fb3f

Please sign in to comment.