Skip to content

Commit

Permalink
Merge pull request #5364 from Martchus/restarting
Browse files Browse the repository at this point in the history
Fix force-restarting jobs when an advanced restarting option was chosen
  • Loading branch information
mergify[bot] authored Nov 17, 2023
2 parents 0534e92 + 7353782 commit 34068e3
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
26 changes: 22 additions & 4 deletions assets/javascripts/openqa.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,22 @@ function showJobRestartResults(responseJSON, newJobUrl, retryFunction, targetEle
return true;
}

function forceJobRestartViaRestartLink(restartLink) {
if (!restartLink.href.endsWith('?force=1')) {
restartLink.href += '?force=1';
function addParam(path, key, value) {
const paramsStart = path.indexOf('?');
let params;
if (paramsStart === -1) {
params = new URLSearchParams();
path = path + '?';
} else {
params = new URLSearchParams(path.substr(paramsStart + 1));
path = path.substr(0, paramsStart + 1);
}
params.set(key, value);
return path + params.toString();
}

function forceJobRestartViaRestartLink(restartLink) {
restartLink.href = addParam(restartLink.href, 'force', '1');
restartLink.click();
}

Expand All @@ -242,7 +254,13 @@ function restartJob(ajaxUrl, jobId) {
} catch {
// Intentionally ignore all errors
}
if (showJobRestartResults(responseJSON, newJobUrl, restartJob.bind(undefined, ajaxUrl + '?force=1', jobId))) {
if (
showJobRestartResults(
responseJSON,
newJobUrl,
restartJob.bind(undefined, addParam(ajaxUrl, 'force', '1'), jobId)
)
) {
return;
}
if (newJobUrl) {
Expand Down
2 changes: 1 addition & 1 deletion assets/javascripts/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ function setupTestButtons() {
function setupResultButtons() {
$('.restart-result').click(function (event) {
event.preventDefault();
restartJob($(this).attr('href'), $(this).data('jobid'));
restartJob(this.href, this.dataset.jobid);
// prevent posting twice by clicking #restart-result
return false;
});
Expand Down
5 changes: 5 additions & 0 deletions t/ui/26-jobs_restart.t
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ subtest 'restart job from info panel in test results' => sub {
expected_job_id_regex(2),
'warning with link to new job appears'
);

my $test = "return addParam('/api/v1/jobs/123/restart?skip_ok_result_children=1', 'force', '1')";
my $path = $driver->execute_script($test);
is $path, '/api/v1/jobs/123/restart?skip_ok_result_children=1&force=1',
'advanced restarting parameter preserved when adding force parameter';
};
subtest 'successful restart' => sub {
is($driver->get('/tests/99946'), 1, 'go to job 99946');
Expand Down

0 comments on commit 34068e3

Please sign in to comment.