Skip to content
This repository was archived by the owner on Aug 31, 2023. It is now read-only.

Commit 85b9265

Browse files
authoredMay 10, 2020
Merge pull request #7 from EpocDotFr/display-source-target-branches-option
Display source target branches option
2 parents a723632 + 55433eb commit 85b9265

File tree

6 files changed

+113
-41
lines changed

6 files changed

+113
-41
lines changed
 

‎README.md

+17-7
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ A browser extension that enhance all Merge Requests lists on any instance of Git
1010

1111
- No configuration needed: install and it just works
1212
- Display source and target branches
13-
- Buttons allowing to easily copy these branches name (can be disabled in the extension preferences)
13+
- Can be enabled/disabled in the extension preferences
14+
- Buttons allowing to easily copy these branches name (can be enabled/disabled in the extension preferences)
1415
- Button allowing to copy Merge Request information (useful when sharing the Merge Request on e.g instant messaging softwares)
15-
- Can be disabled in the extension preferences
16+
- Can be enabled/disabled in the extension preferences
1617
- Text format is customizable (with support of placeholders)
1718
- Direct Jira ticket link
1819
- Can be enabled/disabled in the extension preferences
1920
- Ticket ID is automatically detected in source branch name or Merge Request title
2021
- Base Jira URL is configured in extension preferences
2122
- The ticket ID or an icon can be displayed as the link label (configured in extension preferences)
22-
- WIP toggle button (can be disabled in the extension preferences)
23+
- WIP toggle button (can be enabled/disabled in the extension preferences)
2324
- Compatible with all GitLab editions (GitLab CE, GitLab EE, GitLab.com) (look at the prerequisites, though)
2425

2526
## Prerequisites
@@ -47,10 +48,19 @@ You can also install this add-on manually by using one of the ZIP files on the [
4748
- **1.1** - Copy source and target branches name
4849
- **1.2** - Copy Merge Request information (intended for sharing on e.g instant messaging softwares)
4950
- **1.3** - Direct Jira ticket link (automatic detection of ticket ID in source branch name or Merge Request title)
50-
- 👉 **1.4** - WIP toggle button
51-
- **1.5**
52-
- New option: enable display Merge Request source and target branches
53-
- New options: enable copy source and target branches name button (one option for each branches)
51+
- **1.4** - WIP toggle button
52+
- 👉 **1.5** - New option: enable display Merge Request source and target branches
53+
- **1.6** - Automatic update of pipeline status and conflict icons
54+
55+
## FAQ
56+
57+
- Why is there still clickable links on deleted source/target branches name?
58+
59+
Due to a technical GitLab limitation, the extension has no reliable way to determine if a branch has been deleted. Therefore, branches name are always links and are always clickable even though it's leading to a 404 page.
60+
61+
- Can you display a link to the Merge Request linked to the target branch, if any?
62+
63+
It would be great, however the extension has no reliable way to do that due to a technical GitLab limitation.
5464

5565
## License
5666

‎html/options.html

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
</head>
77
<body>
88
<form>
9-
<div class="pts pbs row">
9+
<div class="pts row">
1010
<div class="w40p txt-center browser-style">
11-
<input type="checkbox" id="enable_buttons_to_copy_source_and_target_branches_name">
11+
<input type="checkbox" id="display_source_and_target_branches">
1212
</div>
1313
<div>
14-
<label for="enable_buttons_to_copy_source_and_target_branches_name">Enable buttons allowing to copy source and target branches name</label>
14+
<label for="display_source_and_target_branches">Display source and target branches</label>
1515
</div>
1616
</div>
17+
<div class="pll pbs pts browser-style man" id="display-source-target-branches-options">
18+
<input type="checkbox" id="enable_buttons_to_copy_source_and_target_branches_name"> <label for="enable_buttons_to_copy_source_and_target_branches_name">Enable buttons allowing to copy source and target branches name</label>
19+
</div>
1720
<div class="pts row">
1821
<div class="w40p txt-center browser-style">
1922
<input type="checkbox" id="enable_button_to_copy_mr_info">

‎js/content.js

+36-30
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@
196196
this.apiClient.getProjectMergeRequests(
197197
function() {
198198
if (this.status == 200) {
199-
self.removeExistingTargetBranchNodes();
199+
if (self.preferences.display_source_and_target_branches) {
200+
self.removeExistingTargetBranchNodes();
201+
}
202+
200203
self.updateMergeRequestsNodes(this.response);
201204

202205
if (self.preferences.enable_buttons_to_copy_source_and_target_branches_name) {
@@ -346,38 +349,41 @@
346349
// -----------------------------------------------
347350
// Source and target branches info
348351

349-
// Source branch name
350-
let newInfoLineToInject = '<div class="issuable-info">' +
351-
'<span class="project-ref-path has-tooltip" title="Source branch">' +
352-
'<a class="ref-name" href="' + this.baseProjectUrl + '/-/commits/' + mergeRequest.source_branch + '">' + mergeRequest.source_branch + '</a>' +
353-
'</span>';
354-
355-
// Copy source branch name button
356-
if (this.preferences.enable_buttons_to_copy_source_and_target_branches_name) {
357-
newInfoLineToInject += ' <button class="btn btn-secondary btn-md btn-default btn-transparent btn-clipboard has-tooltip gmrle-copy-branch-name" title="Copy branch name" data-branch-name-to-copy="source">' +
358-
'<i class="fa fa-clipboard" aria-hidden="true"></i>' +
359-
'</button>';
360-
}
352+
if (this.preferences.display_source_and_target_branches) {
353+
let newInfoLineToInject = '<div class="issuable-info">';
361354

362-
// Target branch name
363-
newInfoLineToInject += ' <i class="fa fa-long-arrow-right" aria-hidden="true"></i> ' +
364-
'<span class="project-ref-path has-tooltip" title="Target branch">' +
365-
'<a class="ref-name" href="' + this.baseProjectUrl + '/-/commits/' + mergeRequest.target_branch + '">' + mergeRequest.target_branch + '</a>' +
366-
'</span>';
367-
368-
// Copy target branch name button
369-
if (this.preferences.enable_buttons_to_copy_source_and_target_branches_name) {
370-
newInfoLineToInject += ' <button class="btn btn-secondary btn-md btn-default btn-transparent btn-clipboard has-tooltip gmrle-copy-branch-name" title="Copy branch name" data-branch-name-to-copy="target">' +
371-
'<i class="fa fa-clipboard" aria-hidden="true"></i>' +
372-
'</button>';
373-
}
355+
// Source branch name
356+
newInfoLineToInject += '<span class="project-ref-path has-tooltip" title="Source branch">' +
357+
'<a class="ref-name" href="' + this.baseProjectUrl + '/-/commits/' + mergeRequest.source_branch + '">' + mergeRequest.source_branch + '</a>' +
358+
'</span>';
359+
360+
// Copy source branch name button
361+
if (this.preferences.enable_buttons_to_copy_source_and_target_branches_name) {
362+
newInfoLineToInject += ' <button class="btn btn-secondary btn-md btn-default btn-transparent btn-clipboard has-tooltip gmrle-copy-branch-name" title="Copy branch name" data-branch-name-to-copy="source">' +
363+
'<i class="fa fa-clipboard" aria-hidden="true"></i>' +
364+
'</button>';
365+
}
366+
367+
// Target branch name
368+
newInfoLineToInject += ' <i class="fa fa-long-arrow-right" aria-hidden="true"></i> ' +
369+
'<span class="project-ref-path has-tooltip" title="Target branch">' +
370+
'<a class="ref-name" href="' + this.baseProjectUrl + '/-/commits/' + mergeRequest.target_branch + '">' + mergeRequest.target_branch + '</a>' +
371+
'</span>';
372+
373+
// Copy target branch name button
374+
if (this.preferences.enable_buttons_to_copy_source_and_target_branches_name) {
375+
newInfoLineToInject += ' <button class="btn btn-secondary btn-md btn-default btn-transparent btn-clipboard has-tooltip gmrle-copy-branch-name" title="Copy branch name" data-branch-name-to-copy="target">' +
376+
'<i class="fa fa-clipboard" aria-hidden="true"></i>' +
377+
'</button>';
378+
}
374379

375-
newInfoLineToInject += '</div>';
380+
newInfoLineToInject += '</div>';
376381

377-
this.parseHtmlAndAppend(
378-
mergeRequestNode.querySelector('.issuable-main-info'),
379-
newInfoLineToInject
380-
);
382+
this.parseHtmlAndAppend(
383+
mergeRequestNode.querySelector('.issuable-main-info'),
384+
newInfoLineToInject
385+
);
386+
}
381387
}, this);
382388
}
383389

‎js/options.js

+52
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
this.optionsForm = document.querySelector('form');
2424
this.submitButtonInOptionsForm = this.optionsForm.querySelector('button[type="submit"]');
2525

26+
this.displaySourceTargetBranchesOptionsDiv = document.querySelector('div#display-source-target-branches-options');
27+
this.displaySourceAndTargetBranchesCheckbox = document.querySelector('input#display_source_and_target_branches');
2628
this.enableButtonsToCopySourceAndTargetBranchesNameCheckbox = document.querySelector('input#enable_buttons_to_copy_source_and_target_branches_name');
2729

2830
this.copyMrInfoOptionsDiv = document.querySelector('div#copy-mr-info-options');
@@ -44,6 +46,9 @@
4446
let self = this;
4547

4648
this.preferencesManager.getAll(function(preferences) {
49+
self.displaySourceAndTargetBranchesCheckbox.checked = preferences.display_source_and_target_branches;
50+
self.displaySourceAndTargetBranchesCheckbox.dispatchEvent(new CustomEvent('change'));
51+
4752
self.enableButtonsToCopySourceAndTargetBranchesNameCheckbox.checked = preferences.enable_buttons_to_copy_source_and_target_branches_name;
4853

4954
self.enableButtonToCopyMrInfoCheckbox.checked = preferences.enable_button_to_copy_mr_info;
@@ -61,6 +66,7 @@
6166
}).checked = true;
6267

6368
self.enableButtonToToggleWipStatusCheckbox.checked = preferences.enable_button_to_toggle_wip_status;
69+
self.enableButtonToToggleWipStatusCheckbox.dispatchEvent(new CustomEvent('change'));
6470
});
6571
}
6672

@@ -73,16 +79,28 @@
7379
this.optionsForm.addEventListener('submit', function(e) {
7480
e.preventDefault();
7581

82+
if (self.hasUserDisabledAllFeatures()) {
83+
return false;
84+
}
85+
7686
if (!self.initializeVisualFeedbackOnSubmitButton()) {
7787
return false;
7888
}
7989

8090
self.saveOptionsToStorage();
8191
});
8292

93+
this.displaySourceAndTargetBranchesCheckbox.addEventListener('change', function() {
94+
self.displaySourceTargetBranchesOptionsDiv.classList.toggle('is-hidden', !this.checked);
95+
96+
self.forceUserToEnableAtLeastOneFeatureIfNecessarily();
97+
});
98+
8399
this.enableButtonToCopyMrInfoCheckbox.addEventListener('change', function() {
84100
self.copyMrInfoOptionsDiv.classList.toggle('is-hidden', !this.checked);
85101
self.copyMrInfoFormatTextarea.toggleAttribute('required', this.checked);
102+
103+
self.forceUserToEnableAtLeastOneFeatureIfNecessarily();
86104
});
87105

88106
this.enableJiraTicketLinkCheckbox.addEventListener('change', function() {
@@ -92,6 +110,12 @@
92110
self.jiraTicketLinkLabelTypeRadioButtons.forEach(function(el) {
93111
el.toggleAttribute('required', this.checked);
94112
}, this);
113+
114+
self.forceUserToEnableAtLeastOneFeatureIfNecessarily();
115+
});
116+
117+
this.enableButtonToToggleWipStatusCheckbox.addEventListener('change', function() {
118+
self.forceUserToEnableAtLeastOneFeatureIfNecessarily();
95119
});
96120
}
97121

@@ -107,6 +131,7 @@
107131

108132
this.preferencesManager.setAll(
109133
{
134+
display_source_and_target_branches: this.displaySourceAndTargetBranchesCheckbox.checked,
110135
enable_buttons_to_copy_source_and_target_branches_name: this.enableButtonsToCopySourceAndTargetBranchesNameCheckbox.checked,
111136
enable_button_to_copy_mr_info: this.enableButtonToCopyMrInfoCheckbox.checked,
112137
copy_mr_info_format: this.copyMrInfoFormatTextarea.value,
@@ -124,6 +149,33 @@
124149
);
125150
}
126151

152+
/**
153+
* Force the user to enable at least one feature if he disabled all the features of
154+
* the extension (which is useless).
155+
*/
156+
forceUserToEnableAtLeastOneFeatureIfNecessarily() {
157+
if (this.hasUserDisabledAllFeatures() && !this.submitButtonInOptionsForm.disabled) {
158+
this.submitButtonInOptionsForm.disabled = true;
159+
this.submitButtonInOptionsForm.dataset.originalTextContent = this.submitButtonInOptionsForm.textContent;
160+
this.submitButtonInOptionsForm.textContent = '⚠️ Please enable at least one feature';
161+
} else if (this.submitButtonInOptionsForm.disabled) {
162+
this.submitButtonInOptionsForm.disabled = false;
163+
this.submitButtonInOptionsForm.textContent = this.submitButtonInOptionsForm.dataset.originalTextContent;
164+
165+
delete this.submitButtonInOptionsForm.dataset.originalTextContent;
166+
}
167+
}
168+
169+
/**
170+
* Determine if the user has disabled all the features of the extension (which is useless).
171+
*/
172+
hasUserDisabledAllFeatures() {
173+
return !this.displaySourceAndTargetBranchesCheckbox.checked
174+
&& !this.enableButtonToCopyMrInfoCheckbox.checked
175+
&& !this.enableJiraTicketLinkCheckbox.checked
176+
&& !this.enableButtonToToggleWipStatusCheckbox.checked;
177+
}
178+
127179
/**
128180
* Returns the browser name the extension is currently running on.
129181
*/

‎js/preferences.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
globals.Gmrle.PreferencesManager = class {
77
get defaults() {
88
return {
9+
display_source_and_target_branches: true,
910
enable_buttons_to_copy_source_and_target_branches_name: true,
1011
enable_button_to_copy_mr_info: true,
1112
copy_mr_info_format: 'MR {MR_ID} (from {MR_AUTHOR_NAME}): {MR_TITLE}\n{MR_URL}',

‎scripts/settings.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
MANIFEST_FILE = {
22
'manifest_version': 2,
33
'name': 'GitLab Merge Requests lists enhancer',
4-
'version': '1.4.0',
4+
'version': '1.5.0',
55
'description': 'An extension that enhance all Merge Requests lists on any instance of Gitlab and GitLab.com.',
66
'homepage_url': 'https://github.com/EpocDotFr/gitlab-merge-requests-lists-enhancer',
77
'author': 'Maxime \'Epoc\' G.',

0 commit comments

Comments
 (0)
Failed to load comments.