Skip to content
This repository was archived by the owner on Jun 9, 2021. It is now read-only.

Commit 7de2b9c

Browse files
sreer-pegasreer
andauthored
Changes for bitbucket 7+ (#372)
Co-authored-by: sreer <RajeshKrishna.SreeramaKrishnan@in.pega.com>
1 parent ec66010 commit 7de2b9c

File tree

5 files changed

+132
-135
lines changed

5 files changed

+132
-135
lines changed

pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>se.bjurr.prnfb</groupId>
66
<artifactId>pull-request-notifier-for-bitbucket</artifactId>
7-
<version>4.2-SNAPSHOT</version>
7+
<version>5.0-SNAPSHOT</version>
88
<organization>
99
<name>Tomas Bjerre AB</name>
1010
<url>https://tomasbjerreab.se/</url>
@@ -332,9 +332,9 @@ Changelog of Pull Request Notifier for Bitbucket.
332332
<changelog.version>1.60</changelog.version>
333333
<fmt.version>2.9</fmt.version>
334334
<violations.version>1.21</violations.version>
335-
<bitbucket.version>6.8.0-bbs-cdn-m1</bitbucket.version>
335+
<bitbucket.version>7.1.1</bitbucket.version>
336336
<bitbucket.data.version>${bitbucket.version}</bitbucket.data.version>
337337
<quick.reload.version>2.0.0</quick.reload.version>
338338
<amps.version>8.0.2</amps.version>
339339
</properties>
340-
</project>
340+
</project>

src/main/resources/admin.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
define('plugin/prnfb/admin', [
22
'jquery',
33
'@atlassian/aui',
4-
'plugin/prnfb/utils',
5-
'wrm/context-path'
6-
], function($, AJS, utils, contextPath) {
7-
var settingsAdminUrlPostUrl = contextPath + "/rest/prnfb-admin/1.0/settings";
4+
'plugin/prnfb/utils'
5+
], function($, AJS, utils) {
6+
var settingsAdminUrlPostUrl = "/rest/prnfb-admin/1.0/settings";
87
var settingsAdminUrl = settingsAdminUrlPostUrl;
98

10-
var notificationsAdminUrlPostUrl = contextPath + "/rest/prnfb-admin/1.0/settings/notifications";
9+
var notificationsAdminUrlPostUrl = "/rest/prnfb-admin/1.0/settings/notifications";
1110
var notificationsAdminUrl = notificationsAdminUrlPostUrl;
1211

13-
var buttonsAdminUrlPostUrl = contextPath + "/rest/prnfb-admin/1.0/settings/buttons";
12+
var buttonsAdminUrlPostUrl = "/rest/prnfb-admin/1.0/settings/buttons";
1413
var buttonsAdminUrl = buttonsAdminUrlPostUrl;
1514

1615
var projectKey;

src/main/resources/atlassian-plugin.xml

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333

3434
<web-resource name="Admin Web Resources" key="resources">
3535
<dependency>com.atlassian.auiplugin:ajs</dependency>
36-
<dependency>com.atlassian.plugins.atlassian-plugins-webresource-plugin:context-path</dependency>
3736
<dependency>com.atlassian.auiplugin:template</dependency>
37+
<dependency>com.atlassian.bitbucket.server.bitbucket-web-api:server</dependency>
3838
<resource type="download" name="3rdparty.js" location="3rdparty.js" />
3939
<resource type="download" name="utils.js" location="utils.js" />
4040
<resource type="download" name="admin.js" location="admin.js" />
@@ -58,18 +58,44 @@
5858
</link>
5959
</web-item>
6060

61-
<client-web-item key="se.bjurr.prnfb.triggerbutton" name="Trigger Notification" weight="50" section="bitbucket.pullrequest.action">
62-
<dependency>${project.groupId}-${project.artifactId}:pr-triggerbutton</dependency>
63-
<label key="bitbucket.web.pull-request.toolbar.triggerbutton">pr-triggerbutton</label>
64-
</client-web-item>
61+
<web-item key="custom-buttons0" section="bitbucket.ui.pullrequest.action">
62+
<label key="" />
63+
</web-item>
64+
<web-item key="custom-buttons1" section="bitbucket.ui.pullrequest.action">
65+
<label key="" />
66+
</web-item>
67+
<web-item key="custom-buttons2" section="bitbucket.ui.pullrequest.action">
68+
<label key="" />
69+
</web-item>
70+
<web-item key="custom-buttons3" section="bitbucket.ui.pullrequest.action">
71+
<label key="" />
72+
</web-item>
73+
<web-item key="custom-buttons4" section="bitbucket.ui.pullrequest.action">
74+
<label key="" />
75+
</web-item>
76+
<web-item key="custom-buttons5" section="bitbucket.ui.pullrequest.action">
77+
<label key="" />
78+
</web-item>
79+
<web-item key="custom-buttons6" section="bitbucket.ui.pullrequest.action">
80+
<label key="" />
81+
</web-item>
82+
<web-item key="custom-buttons7" section="bitbucket.ui.pullrequest.action">
83+
<label key="" />
84+
</web-item>
85+
<web-item key="custom-buttons8" section="bitbucket.ui.pullrequest.action">
86+
<label key="" />
87+
</web-item>
88+
<web-item key="custom-buttons9" section="bitbucket.ui.pullrequest.action">
89+
<label key="" />
90+
</web-item>
6591

6692
<web-resource key="pr-triggerbutton">
6793
<resource type="download" name="3rdparty.js" location="3rdparty.js" />
6894
<resource type="download" name="utils.js" location="utils.js" />
69-
<resource type="download" name="pr-triggerbutton.js" location="/pr-triggerbutton.js" />
95+
<resource type="download" name="pr-triggerbutton.js" location="pr-triggerbutton.js" />
7096
<dependency>com.atlassian.bitbucket.bitbucket-web-plugin:global</dependency>
7197
<dependency>com.atlassian.auiplugin:ajs</dependency>
72-
<dependency>com.atlassian.plugins.atlassian-plugins-webresource-plugin:context-path</dependency>
73-
<context>bitbucket.page.pullRequest.view</context>
98+
<dependency>com.atlassian.bitbucket.server.bitbucket-web-api:server</dependency>
99+
<context>bitbucket.ui.pullrequest.action</context>
74100
</web-resource>
75-
</atlassian-plugin>
101+
</atlassian-plugin>

src/main/resources/pr-triggerbutton.js

Lines changed: 72 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
1-
define('plugin/prnfb/pr-triggerbutton', [
1+
require([
2+
'@atlassian/clientside-extensions-registry',
23
'jquery',
34
'@atlassian/aui',
4-
'bitbucket/util/state',
55
'underscore',
66
'plugin/prnfb/3rdparty',
7-
'wrm/context-path'
8-
], function($, AJS, pageState, _, thirdParty, contextPath) {
9-
var buttonsAdminUrl = contextPath + "/rest/prnfb-admin/1.0/settings/buttons";
7+
'bitbucket/util/server',
8+
'@bitbucket/apps/pull-requests/initial-data'
9+
], function(registry, $, AJS, _, thirdParty, srv, prData) {
10+
var prId = prData.pullRequest.id
11+
var repoId = prData.repository.id
12+
var buttonsAdminUrl = "/rest/prnfb-admin/1.0/settings/buttons";
1013

1114
var waiting = '<span class="aui-icon aui-icon-wait aui-icon-small">Wait</span>';
12-
var $buttonArea = $('#pull-request-header-more').find('.aui-button').first().closest('ul');
13-
$buttonArea.find('.aui-button').each(function(index, auiButton) {
14-
var buttonText = $(auiButton).text().trim();
15-
if (buttonText === '' || buttonText === 'pr-triggerbutton') {
16-
//An empty button is added by 'client-web-item' in atlassian-plugin.xml
17-
$(auiButton).remove();
18-
}
19-
});
20-
21-
var buttonTemplate = function(name) {
22-
return $('<li><button class="aui-button aui-button-link prnfb-button" role="menuitem">' + name + '</button></li>');
23-
};
2415

2516
var dialogTemplate = function(name, content) {
2617
var escapedName = _.escape(name);
@@ -185,7 +176,7 @@ define('plugin/prnfb/pr-triggerbutton', [
185176
});
186177
} else {
187178
AJS.flag({
188-
close: 'auto',
179+
close: 'manual',
189180
type: 'error',
190181
title: notificationResponse.notificationName.replace(/<script>/g, 'script'),
191182
body: '<p>' + notificationResponse.status + ' ' + notificationResponse.uri + '</p>' +
@@ -205,106 +196,81 @@ define('plugin/prnfb/pr-triggerbutton', [
205196
}
206197
};
207198

208-
function loadSettingsAndShowButtons() {
209-
$.get(buttonsAdminUrl + '/repository/' + pageState.getRepository().id + '/pullrequest/' + pageState.getPullRequest().id, function(settings) {
210-
$buttonArea.find('.prnfb-button').remove();
211-
settings.forEach(function(item) {
212-
var $buttonDropdownItem = buttonTemplate(item.name.replace(/<script>/g, 'script'));
213-
$buttonDropdownItem.click(function() {
214-
var $this = $(this);
215-
216-
var enableButton = function() {
217-
$this.removeAttr("disabled");
218-
$this.removeAttr("aria-disabled");
219-
$this.find("span").remove();
220-
};
221-
var disableButton = function() {
222-
$this.attr("disabled", "disabled");
223-
$this.attr("aria-disabled", "true");
224-
$this.prepend(waiting);
225-
};
226-
227-
var submitButton = function(formResult) {
228-
disableButton();
229-
$.ajax({
230-
"type": "POST",
231-
"url": buttonsAdminUrl + '/' + item.uuid + '/press/repository/' + pageState.getRepository().id + '/pullrequest/' + pageState.getPullRequest().id,
232-
"data": {
233-
"form": formResult
234-
},
235-
"success": function(content) {
236-
setTimeout(function() {
237-
enableButton();
199+
function submitButton(item, formResult) {
200+
srv.ajax({
201+
"type": "POST",
202+
"url": buttonsAdminUrl + '/' + item.uuid + '/press/repository/' + repoId +'/pullrequest/' + prId,
203+
"data": {
204+
"form": formResult
205+
},
206+
"success": function(content) {
207+
setTimeout(function() {
238208
if (content.confirmation == "on") {
239-
presentResult(content.notificationResponses);
209+
presentResult(content.notificationResponses);
240210
}
241-
}, 500);
242-
},
243-
"error": function(content) {
244-
enableButton();
245-
AJS.flag({
246-
close: 'auto',
211+
}, 500);
212+
},
213+
"error": function(content) {
214+
AJS.flag({
215+
close: 'manual',
247216
type: 'error',
248217
title: "Unknown error",
249218
body: '<p>' + content.status + '</p>' + '<p>Check the Bitbucket Server log for more details.</p>'
250-
});
251-
}
252-
});
253-
254-
if (item.redirectUrl) {
255-
redirect();
256-
}
257-
};
258-
259-
var redirect = function() {
260-
disableButton();
261-
window.location.replace(item.redirectUrl);
262-
};
263-
264-
if (item.confirmationText || item.buttonFormList && item.buttonFormList.length > 0) {
265-
// Create the form and dialog
266-
var confirmationText = confirmationTextTemplate(item.confirmationText);
267-
var form = formTemplate(item.buttonFormList);
268-
var formHtml = $("<div/>").append(confirmationText).append(form).html();
269-
var $dialog = $(dialogTemplate(item.name, formHtml));
270-
$dialog.appendTo($("body"));
219+
});
220+
}
221+
});
271222

272-
var dialogRef = AJS.dialog2($dialog);
223+
if (item.redirectUrl) {
224+
window.location.replace(item.redirectUrl);
225+
}
226+
}
273227

274-
// When you submit the form, we will post to the server with all the
275-
// form data.
276-
AJS.$("#dialog-submit-button").click(function(e) {
277-
var formResult = $dialog.find("form").serializeJSON();
278-
e.preventDefault();
279-
dialogRef.hide();
228+
function loadSettingsAndShowButtons() {
229+
srv.rest({
230+
url : buttonsAdminUrl + '/repository/' + repoId + '/pullrequest/' + prId,
231+
success : function(settings) {
232+
settings.forEach(function(item, index) {
233+
registry.registerExtension(
234+
'se.bjurr.prnfs.pull-request-notifier-for-stash:custom-buttons' + index,
235+
function buttonFactory(extensionAPI, context) {
236+
return {
237+
type: 'button',
238+
label: item.name,
239+
onAction : function() {
240+
if (item.confirmationText || item.buttonFormList && item.buttonFormList.length > 0) {
241+
// Create the form and dialog
242+
var confirmationText = confirmationTextTemplate(item.confirmationText);
243+
var form = formTemplate(item.buttonFormList);
244+
var formHtml = $("<div/>").append(confirmationText).append(form).html();
245+
var $dialog = $(dialogTemplate(item.name, formHtml));
246+
$dialog.appendTo($("body"));
280247

281-
submitButton(formResult);
282-
});
283-
AJS.$("#dialog-close-button").click(function(e) {
284-
e.preventDefault();
285-
dialogRef.hide();
286-
});
287-
dialogRef.show();
288-
} else {
289-
submitButton(null);
290-
}
248+
var dialogRef = AJS.dialog2($dialog);
291249

292-
});
293-
$buttonArea.append($buttonDropdownItem);
294-
});
250+
// When you submit the form, we will post to the server with all the form data.
251+
AJS.$("#dialog-submit-button").click(function(e) {
252+
var formResult = $dialog.find("form").serializeJSON();
253+
e.preventDefault();
254+
dialogRef.hide();
255+
submitButton(item, formResult);
256+
});
257+
AJS.$("#dialog-close-button").click(function(e) {
258+
e.preventDefault();
259+
dialogRef.hide();
260+
});
261+
dialogRef.show();
262+
} else {
263+
submitButton(item, null);
264+
}
265+
}
266+
};
267+
}
268+
);
269+
});
270+
}
295271
});
296272
}
297273

298274
loadSettingsAndShowButtons();
299275

300-
//If a reviewer approves the PR, then a button may become visible
301-
$('.aui-button.approve').click(function() {
302-
setTimeout(function() {
303-
loadSettingsAndShowButtons();
304-
}, 1000);
305-
});
306-
});
307-
308-
AJS.$(document).ready(function() {
309-
require('plugin/prnfb/pr-triggerbutton');
310276
});

src/main/resources/utils.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
define('plugin/prnfb/utils', [
22
'jquery',
33
'plugin/prnfb/3rdparty',
4-
'wrm/context-path'
5-
], function($, trdparty, contextPath) {
4+
'bitbucket/util/server'
5+
], function($, trdparty, srv) {
66

77
function postForm(url, formSelector, whenDone) {
88
$('.statusresponse').empty();
99
var jsonString = $(formSelector).serializeJSON();
10-
$.ajax({
10+
srv.ajax({
1111
url: url,
1212
type: "POST",
1313
contentType: "application/json; charset=utf-8",
@@ -60,9 +60,12 @@ define('plugin/prnfb/utils', [
6060
}
6161

6262
function getProjects(whenDone) {
63-
var projectsUrl = contextPath + "/rest/api/1.0/projects?limit=999999";
64-
$.getJSON(projectsUrl, function(data) {
65-
whenDone(data);
63+
var projectsUrl = "/rest/api/1.0/projects?limit=999999";
64+
srv.rest ({
65+
url : projectsUrl,
66+
success: function(data) {
67+
whenDone(data);
68+
}
6669
});
6770
}
6871

@@ -91,10 +94,13 @@ define('plugin/prnfb/utils', [
9194
whenDone();
9295
return;
9396
}
94-
var reposUrl = contextPath + "/rest/api/1.0/projects/" + projectKey + "/repos?limit=999999";
95-
$.getJSON(reposUrl, function(data) {
96-
whenDone(data);
97-
});
97+
var reposUrl = "/rest/api/1.0/projects/" + projectKey + "/repos?limit=999999";
98+
srv.rest ({
99+
url : reposUrl,
100+
success: function(data) {
101+
whenDone(data);
102+
}
103+
});
98104
}
99105

100106
function setupProjectAndRepoSettingsInForm($form, hasProjectAndRepo) {
@@ -249,7 +255,7 @@ define('plugin/prnfb/utils', [
249255
e.preventDefault();
250256
var uuid = $(formSelector).find('[name=uuid]').val();
251257
if (uuid) {
252-
$.ajax({
258+
srv.ajax({
253259
url: postUrl + '/' + uuid,
254260
type: 'DELETE',
255261
success: function(result) {

0 commit comments

Comments
 (0)