Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix force-restarting jobs when an advanced restarting option was chosen #5364

Merged
merged 2 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading