From 61db8349041cceceb4ad3233e69613705bd0a128 Mon Sep 17 00:00:00 2001 From: Mario Lubenka Date: Mon, 16 Dec 2019 07:20:25 +0100 Subject: Change target branch for pull request (#6488) * Adds functionality to change target branch of created pull requests Signed-off-by: Mario Lubenka * Use const instead of var in JavaScript additions Signed-off-by: Mario Lubenka * Check if branches are equal and if PR already exists before changing target branch Signed-off-by: Mario Lubenka * Make sure to check all commits Signed-off-by: Mario Lubenka * Print error messages for user as error flash message Signed-off-by: Mario Lubenka * Disallow changing target branch of closed or merged pull requests Signed-off-by: Mario Lubenka * Resolve conflicts after merge of upstream/master Signed-off-by: Mario Lubenka * Change order of branch select fields Signed-off-by: Mario Lubenka * Removes duplicate check Signed-off-by: Mario Lubenka * Use ctx.Tr for translations Signed-off-by: Mario Lubenka * Recompile JS Signed-off-by: Mario Lubenka * Use correct translation namespace Signed-off-by: Mario Lubenka * Remove redundant if condition Signed-off-by: Mario Lubenka * Moves most change branch logic into pull service Signed-off-by: Mario Lubenka * Completes comment Signed-off-by: Mario Lubenka * Add Ref to ChangesPayload for logging changed target branches instead of creating a new struct Signed-off-by: Mario Lubenka * Revert changes to go.mod Signed-off-by: Mario Lubenka * Directly use createComment method Signed-off-by: Mario Lubenka * Return 404 if pull request is not found. Move written check up Signed-off-by: Mario Lubenka * Remove variable declaration Signed-off-by: Mario Lubenka * Return client errors on change pull request target errors Signed-off-by: Mario Lubenka * Return error in commit.HasPreviousCommit Signed-off-by: Mario Lubenka * Adds blank line Signed-off-by: Mario Lubenka * Test patch before persisting new target branch Signed-off-by: Mario Lubenka * Update patch before testing (not working) Signed-off-by: Mario Lubenka * Removes patch calls when changeing pull request target Signed-off-by: Mario Lubenka * Removes unneeded check for base name Signed-off-by: Mario Lubenka * Moves ChangeTargetBranch completely to pull service. Update patch status. Signed-off-by: Mario Lubenka * Set webhook mode after errors were validated Signed-off-by: Mario Lubenka * Update PR in one transaction Signed-off-by: Mario Lubenka * Move logic for check if head is equal with branch to pull model Signed-off-by: Mario Lubenka * Adds missing comment and simplify return Signed-off-by: Mario Lubenka * Adjust CreateComment method call Signed-off-by: Mario Lubenka --- web_src/js/index.js | 61 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 50 insertions(+), 11 deletions(-) (limited to 'web_src') diff --git a/web_src/js/index.js b/web_src/js/index.js index a7aa0d52c4..a310243c08 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -731,27 +731,66 @@ function initRepository() { $issueTitle.toggle(); $('.not-in-edit').toggle(); $('#edit-title-input').toggle(); + $('#pull-desc').toggle(); + $('#pull-desc-edit').toggle(); $('.in-edit').toggle(); $editInput.focus(); return false; }; + + const changeBranchSelect = function () { + const selectionTextField = $('#pull-target-branch'); + + const baseName = selectionTextField.data('basename'); + const branchNameNew = $(this).data('branch'); + const branchNameOld = selectionTextField.data('branch'); + + // Replace branch name to keep translation from HTML template + selectionTextField.html(selectionTextField.html().replace( + `${baseName}:${branchNameOld}`, + `${baseName}:${branchNameNew}` + )); + selectionTextField.data('branch', branchNameNew); // update branch name in setting + }; + $('#branch-select > .item').click(changeBranchSelect); + $('#edit-title').click(editTitleToggle); $('#cancel-edit-title').click(editTitleToggle); $('#save-edit-title').click(editTitleToggle).click(function () { + const pullrequest_targetbranch_change = function (update_url) { + const targetBranch = $('#pull-target-branch').data('branch'); + const $branchTarget = $('#branch_target'); + if (targetBranch === $branchTarget.text()) { + return false; + } + $.post(update_url, { + _csrf: csrf, + target_branch: targetBranch + }) + .success((data) => { + $branchTarget.text(data.base_branch); + }) + .always(() => { + reload(); + }); + }; + + const pullrequest_target_update_url = $(this).data('target-update-url'); if ($editInput.val().length === 0 || $editInput.val() === $issueTitle.text()) { $editInput.val($issueTitle.text()); - return false; + pullrequest_targetbranch_change(pullrequest_target_update_url); + } else { + $.post($(this).data('update-url'), { + _csrf: csrf, + title: $editInput.val() + }, + (data) => { + $editInput.val(data.title); + $issueTitle.text(data.title); + pullrequest_targetbranch_change(pullrequest_target_update_url); + reload(); + }); } - - $.post($(this).data('update-url'), { - _csrf: csrf, - title: $editInput.val() - }, - (data) => { - $editInput.val(data.title); - $issueTitle.text(data.title); - reload(); - }); return false; }); -- cgit v1.2.3