From b802f1eb0a4b3f057ed797190b95dfee638b8219 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Mon, 9 Nov 2020 15:34:51 +0100 Subject: [PATCH] TT#100601 release_dashboard: support empty hotfix Change-Id: Idad06fa1ad432483072c99294eb57769c4588bb9 --- .../static/release_dashboard/js/hotfix.js | 80 ++++++++++--------- .../templates/release_dashboard/hotfix.html | 8 +- release_dashboard/utils/build.py | 10 ++- release_dashboard/views/build.py | 20 +++-- 4 files changed, 69 insertions(+), 49 deletions(-) diff --git a/release_dashboard/static/release_dashboard/js/hotfix.js b/release_dashboard/static/release_dashboard/js/hotfix.js index 2d88c5e..b7e7620 100644 --- a/release_dashboard/static/release_dashboard/js/hotfix.js +++ b/release_dashboard/static/release_dashboard/js/hotfix.js @@ -2,60 +2,64 @@ * * */ -$('button.hotfix').click(function(e){ +$( "button.hotfix" ).click( function( e ) { + // don't send the form e.preventDefault(); - var button = $(this); - var id = button.attr('id').replace('hotfix_',''); - var branch = $('select#version_' + id + ' option:selected').val().replace('branch/', ''); + var button = $( this ); + var id = button.attr( "id" ).replace( "hotfix_", "" ); + var branch = $( "select#version_" + id + " option:selected" ).val().replace( "branch/", "" ); var repo = id; - var span = $('span#hotfix_error_' + id); - var push = $('select#push_' + id + ' option:selected').val(); + var span = $( "span#hotfix_error_" + id ); + var push = $( "select#push_" + id + " option:selected" ).val(); + var empty = $( "input#empty_" + id ).prop( "checked" ); - $.ajax({ - url: branch + '/' + repo + '/', - type: 'POST', - data: JSON.stringify({push: push }), + $.ajax( { + url: branch + "/" + repo + "/", + type: "POST", + data: JSON.stringify( { push: push, empty: empty } ), contentType: "application/json; charset=utf-8", dataType: "json", success: successFunc, error: errorFunc, + /* eslint-disable-next-line no-undef */ // at csrf.js beforeSend: csrftokenFunc - }); + } ); - button.attr("disabled", "disabled"); - span.html('processing'); + button.attr( "disabled", "disabled" ); + span.html( "processing" ); span.show(); - function successFunc(data, status) { - span.html(''); - span.append('Done'); - button.removeAttr("disabled"); + function successFunc( data, _status ) { + span.html( "" ); + span.append( "Done" ); + button.removeAttr( "disabled" ); } - function errorFunc(jqXHR, status, error) { - span.html(error); - button.removeAttr("disabled"); + function errorFunc( _jqXHR, _status, error ) { + span.html( error ); + button.removeAttr( "disabled" ); } -}); +} ); -$('td.version > select').change(function() { - var id = $(this).attr('id').replace('version_',''); - var version = $(this).val(); - var button = $('button#hotfix_' + id); - var span = $('span#hotfix_error_' + id); +$( "td.version > select" ).change( function() { + var id = $( this ).attr( "id" ).replace( "version_", "" ); + var version = $( this ).val(); + var button = $( "button#hotfix_" + id ); + var span = $( "span#hotfix_error_" + id ); - if (version.match(/^branch\/mr[0-9]+\.[0-9]+\.[0-9]+$/)) { - button.html("Release hotfix"); - button.removeAttr("disabled"); - } - else { - button.html("Select branch to hotfix"); - button.attr("disabled", "disabled"); + if ( version.match( /^branch\/mr[0-9]+\.[0-9]+\.[0-9]+$/ ) ) { + button.html( "Release hotfix" ); + button.removeAttr( "disabled" ); + } else { + button.html( "Select branch to hotfix" ); + button.attr( "disabled", "disabled" ); } - span.html(''); -}); + span.html( "" ); +} ); -$( document ).ready(function() { - $('td.version > select option[value^="branch/mr"]').each(function(){ $(this).change(); }); -}); +$( document ).ready( function() { + $( "td.version > select option[value^=\"branch/mr\"]" ).each( function() { + $( this ).change(); +} ); +} ); diff --git a/release_dashboard/templates/release_dashboard/hotfix.html b/release_dashboard/templates/release_dashboard/hotfix.html index e033b06..d799a2d 100644 --- a/release_dashboard/templates/release_dashboard/hotfix.html +++ b/release_dashboard/templates/release_dashboard/hotfix.html @@ -13,6 +13,7 @@ Project Version Push + Empty @@ -39,6 +40,9 @@ + + + @@ -53,6 +57,6 @@ {% endblock %} {% block extrajs %} - - + + {% endblock %} diff --git a/release_dashboard/utils/build.py b/release_dashboard/utils/build.py index a733e54..8976a0e 100644 --- a/release_dashboard/utils/build.py +++ b/release_dashboard/utils/build.py @@ -33,7 +33,8 @@ hotfix_url = ( "{base}/job/release-tools-runner/buildWithParameters?" "token={token}&action={action}&branch={branch}&" "PROJECTNAME={project}&repository={project}&" - "push={push}&uuid={uuid}&remote_user={user}" + "push={push}&release_empty_hotfix={empty}&" + "uuid={uuid}&remote_user={user}" ) @@ -45,8 +46,12 @@ def get_response(url): return response -def trigger_hotfix(project, branch, user, push="yes"): +def trigger_hotfix(project, branch, user, push="yes", empty=False): flow_uuid = uuid.uuid4() + if empty: + empty_val = "true" + else: + empty_val = "false" params = { "base": settings.JENKINS_URL, "token": urllib.parse.quote(settings.JENKINS_TOKEN), @@ -54,6 +59,7 @@ def trigger_hotfix(project, branch, user, push="yes"): "branch": urllib.parse.quote(branch), "project": urllib.parse.quote(project), "push": urllib.parse.quote(push), + "empty": empty_val, "uuid": flow_uuid, "user": user.username, } diff --git a/release_dashboard/views/build.py b/release_dashboard/views/build.py index 42e60b6..105cad9 100644 --- a/release_dashboard/views/build.py +++ b/release_dashboard/views/build.py @@ -1,4 +1,4 @@ -# Copyright (C) 2015 The Sipwise Team - http://sipwise.com +# Copyright (C) 2015-2020 The Sipwise Team - http://sipwise.com # # This program is free software: you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by the Free @@ -104,11 +104,11 @@ def hotfix_build(request, branch, project): return HttpResponseNotFound(error) json_data = json.loads(request.body.decode("utf-8")) - if json_data["push"] == "no": + push = json_data.get("push", "no") + empty = json_data.get("empty", False) + if push == "no": logger.warn("dryrun for %s:%s", project, branch) - url = build.trigger_hotfix( - project, branch, request.user, json_data["push"] - ) + url = build.trigger_hotfix(project, branch, request.user, push, empty) return JsonResponse({"url": url}) @@ -227,7 +227,10 @@ def build_trunk_deps_old(request): else: template = "release_dashboard/build_trunk_deps.html" context = { - "projects": _projects_versions(trunk_build_deps, regex_master,), + "projects": _projects_versions( + trunk_build_deps, + regex_master, + ), "common_versions": {"tags": [], "branches": ["master"]}, "debian": settings.RELEASE_DASHBOARD_DEBIAN_RELEASES, } @@ -245,7 +248,10 @@ def build_trunk_release_old(request): return render(request, "release_dashboard/build_result.html", context) else: context = { - "projects": _projects_versions(trunk_projects, regex_master,), + "projects": _projects_versions( + trunk_projects, + regex_master, + ), "common_versions": {"tags": [], "branches": ["master"]}, "debian": settings.RELEASE_DASHBOARD_DEBIAN_RELEASES, }