Skip to content
Snippets Groups Projects

Resolve "Customize branch name when using create branch in an issue"

All threads resolved!
Compare and Show latest version
4 files
+ 40
21
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -122,7 +122,7 @@ export default class CreateMergeRequestDropdown {
checkBranchExists() {
if (this.newBranchNameInput.value) {
this.checkBranchExistencePath = this.checkBranchExistencePath.replace(/(\/branches\/)(.*?)$/, "$1" + this.newBranchNameInput.value);
this.checkBranchExistencePath = this.checkBranchExistencePath.replace(/(\/branches\/)(.*?)$/, `$1${this.newBranchNameInput.value}`);
} else {
this.checkBranchExistencePath = this.wrapperEl.dataset.checkBranchExistencePath;
}
@@ -137,14 +137,16 @@ export default class CreateMergeRequestDropdown {
this.isCheckingBranchExistence = true;
},
})
.always(() => this.isCheckingBranchExistence = false)
.always(() => {
this.isCheckingBranchExistence = false;
})
.success((jqXHR, textStatus, xhr) => {
if (xhr.status == 200 || xhr.status == 204) {
if (xhr.status === 200 || xhr.status === 204) {
this.branchTaken = true;
}
})
.fail((xhr) => {
if (xhr.status == 404) {
if (xhr.status === 404) {
this.branchTaken = false;
}
});
@@ -177,7 +179,6 @@ export default class CreateMergeRequestDropdown {
.addEventListener('click', this.onClickCreateMergeRequestButton.bind(this));
this.dropdownToggle.addEventListener('click', this.onClickSetFocusOnBranchNameInput.bind(this));
this.newBranchNameInput.addEventListener('keyup', this.onChangeNewBranchNameInput.bind(this));
this.refInput.addEventListener('keyup', this.onChangeRefInput.bind(this));
}
isBusy() {
@@ -224,18 +225,22 @@ export default class CreateMergeRequestDropdown {
}
onChangeNewBranchNameInput(e) {
this.newBranchNameInput.value = $.trim(this.newBranchNameInput.value)
if (this.isCheckingBranchExistence) {
return;
}
// `ENTER` key submits the data.
if (e.keyCode === 13 && this.inputsAreValid) {
return this.createMergeRequestButton.click();
this.createMergeRequestButton.click();
return;
}
// `ESC` key closes the dropdown.
if (e.keyCode === 27) {
return this.dropdownToggle.click();
this.dropdownToggle.click();
return;
}
// If the input is empty, use the original branch name generated by the backend.
@@ -252,8 +257,8 @@ export default class CreateMergeRequestDropdown {
this.inputsAreValid = false;
this.disableCreateAction();
this.showNewBranchTakenMessage();
this.createBranchPath = this.createBranchPath.replace(/(branch_name=)(.+?)(?=&issue)/, "$1" + this.newBranchNameInput.value);
this.createMrPath = this.createMrPath.replace(/(branch_name=)(.+?)(?=&ref)/, "$1" + this.newBranchNameInput.value);
this.createBranchPath = this.createBranchPath.replace(/(branch_name=)(.+?)(?=&issue)/, `$1${this.newBranchNameInput.value}`);
this.createMrPath = this.createMrPath.replace(/(branch_name=)(.+?)(?=&ref)/, `$1${this.newBranchNameInput.value}`);
} else {
this.inputsAreValid = true;
this.enable();
@@ -270,8 +275,8 @@ export default class CreateMergeRequestDropdown {
return;
}
this.createBranchPath = this.createBranchPath.replace(/(ref=)(.+?)$/, "$1" + this.refInput.value);
this.createMrPath = this.createMrPath.replace(/(ref=)(.+?)$/, "$1" + this.refInput.value);
this.createBranchPath = this.createBranchPath.replace(/(ref=)(.+?)$/, `$1${this.refInput.value}`);
this.createMrPath = this.createMrPath.replace(/(ref=)(.+?)$/, `$1${this.refInput.value}`);
}
onClickCreateMergeRequestButton(e) {
Loading