From 64d9a8c894257f308f6f2299271e7fa487162c5d Mon Sep 17 00:00:00 2001 From: Jason Fah Date: Thu, 31 Aug 2017 18:42:48 +1000 Subject: [PATCH 1/8] Updated deprecated methods doInput and execute Corrected field names in validate --- .../bamboo/plugins/RocketChatGlobalConfiguration.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/ca/bamboo/plugins/RocketChatGlobalConfiguration.java b/src/main/java/fr/ca/bamboo/plugins/RocketChatGlobalConfiguration.java index 66dfb9b..aa1c190 100644 --- a/src/main/java/fr/ca/bamboo/plugins/RocketChatGlobalConfiguration.java +++ b/src/main/java/fr/ca/bamboo/plugins/RocketChatGlobalConfiguration.java @@ -27,7 +27,7 @@ public class RocketChatGlobalConfiguration extends BambooActionSupport { private BandanaManager bandanaManager = null; @Override - public String doInput() throws Exception { + public String input() throws Exception { return INPUT; } @@ -36,7 +36,7 @@ public String doInput() throws Exception { * Set values in bandana */ @Override - public String doExecute() throws Exception { + public String execute() throws Exception { bandanaManager.setValue(PlanAwareBandanaContext.GLOBAL_CONTEXT, PROP_RC_SERVER, this.rcServer); bandanaManager.setValue(PlanAwareBandanaContext.GLOBAL_CONTEXT, PROP_RC_USER, this.rcUser); @@ -47,19 +47,18 @@ public String doExecute() throws Exception { /** * Validate values - * (doesnt seem to get called?) */ @Override public void validate() { if(StringUtils.isEmpty(this.rcPassword)) { - addFieldError(rcPassword, "Please (re)enter the password."); + addFieldError("rcPassword", "Please (re)enter the password."); } if(StringUtils.isEmpty(this.rcUser)) { - addFieldError(rcUser, "Please enter the RocketChat user."); + addFieldError("rcUser", "Please enter the RocketChat user."); } if(StringUtils.isEmpty(this.rcServer)) { - addFieldError(rcServer, "Please enter the RocketChat server."); + addFieldError("rcServer", "Please enter the RocketChat server."); } } From 2728b601b856254a4f5d1e6d5fd7ef5561bd4a5a Mon Sep 17 00:00:00 2001 From: Jason Fah Date: Thu, 31 Aug 2017 18:44:21 +1000 Subject: [PATCH 2/8] descriptions and readme updates --- README.md | 4 ++-- src/main/resources/english.properties | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 8f72a07..8f0045c 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Just a reminder of the License, this is provided "WITHOUT WARRANTIES OR CONDITIO # Configure 1. Go to your **RocketChat Server** tab in Bamboo administration -2. Fill all the fields, be careful the Server url should end with **/api** +2. Fill all the fields, be careful the Server url should end with **/api/v1** # Use it You can now use it from the **Notifications** tab in your plan configuration. @@ -18,7 +18,7 @@ You can now use it from the **Notifications** tab in your plan configuration. At this time, you can't use LDAP accounts and must use RocketChat local accounts. # Working Versions -- 5.7.1 (It has only been tested with that version because it's the one we use in production +- Bamboo v6.0.0 - It might work with other versions and I'll really appreciate that you tell me if it works with your version # Thanks diff --git a/src/main/resources/english.properties b/src/main/resources/english.properties index 8e534a6..9de975c 100644 --- a/src/main/resources/english.properties +++ b/src/main/resources/english.properties @@ -1,9 +1,9 @@ rc.server.global=Server -rc.server.global.description=The Rocket Chat server url, this should be the api url ending with /api +rc.server.global.description=The Rocket Chat server url, this should be the api url ending with /api/v1 rc.user.global=User rc.user.description=The user to send the notifications from rc.password.global=Password rc.password.description=The password of the configured user rc.channel=Send to Channel -rc.channel.description=Send the notification to the specified channel, if no channel is set not notification will be sent. \ No newline at end of file +rc.channel.description=Send the notification to the specified channel, if no channel is set not notification will be sent. Include the hash before the channel name. \ No newline at end of file From 8633b2a5a74ab382d065ce80e7a0f3a185e24d8e Mon Sep 17 00:00:00 2001 From: Jason Fah Date: Thu, 31 Aug 2017 18:53:23 +1000 Subject: [PATCH 3/8] Updated to support Rocket.Chat API v1 removed fetchPublicRooms() now using chat.postMessage to send the message --- .../plugins/rc/RocketChatConnection.java | 42 ++++--------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/src/main/java/fr/ca/bamboo/plugins/rc/RocketChatConnection.java b/src/main/java/fr/ca/bamboo/plugins/rc/RocketChatConnection.java index 51d9e18..7c333aa 100644 --- a/src/main/java/fr/ca/bamboo/plugins/rc/RocketChatConnection.java +++ b/src/main/java/fr/ca/bamboo/plugins/rc/RocketChatConnection.java @@ -23,7 +23,6 @@ public class RocketChatConnection { private static final Logger log = Logger.getLogger(RocketChatConnection.class.getName()); - private static Map roomsById = new HashMap(); private String server; private String user; @@ -43,11 +42,9 @@ public RocketChatConnection(String server, String user, String pass) { this.password = pass; configure(); - // Login login(); } - /** * Configures jersey client */ @@ -72,54 +69,29 @@ private void login() { this.userId = data.getString("userId"); this.authToken = data.getString("authToken"); } - else{ - throw new RuntimeException("Failed to fetch public rooms with error: " + responseObject.getString("message")); - } - fetchPublicRooms(); - } - - private void fetchPublicRooms() { - WebResource resource = restapi.path("publicRooms"); - - ClientResponse response = addTokens(resource).get(ClientResponse.class); - - JSONObject responseObject = JSONObject.fromObject(response.getEntity(String.class)); - - if (responseObject.getString("status").equals("success")) { - JSONArray rooms = responseObject.getJSONArray("rooms"); - - for (int i = 0; i < rooms.size(); i++) { - { - JSONObject room = (JSONObject) rooms.get(i); - roomsById.put(room.getString("name"), room.getString("_id")); - } - } - } - else{ + else { throw new RuntimeException("Failed to fetch public rooms with error: " + responseObject.getString("message")); } } public void sendMessage(String roomName, String message) { - // joinRoom(roomName); - WebResource resource = restapi.path("rooms").path(roomsById.get(roomName)).path("send"); + WebResource resource = restapi.path("chat.postMessage"); JSONObject object = new JSONObject(); - object.put("msg", message); + object.put("channel", roomName); + object.put("text", message); ClientResponse response = addTokens(resource).header("Content-Type", "application/json").post(ClientResponse.class, object.toString()); JSONObject responseObject = JSONObject.fromObject(response.getEntity(String.class)); - if (!responseObject.getString("status").equals("success")) { + if (!responseObject.getString("success").equals(true)) { throw new RuntimeException("Failed to send the message with error: " + responseObject.getString("message")); } } public void logout() { WebResource resource = restapi.path("logout"); - ClientResponse response = addTokens(resource).get(ClientResponse.class); - JSONObject responseObject = JSONObject.fromObject(response.getEntity(String.class)); if (!responseObject.getString("status").equals("success")) { @@ -128,10 +100,10 @@ public void logout() { } private WebResource.Builder addTokens(WebResource original) { - return original.header("X-Auth-Token", authToken).header("X-User-Id", userId); + return original.header("X-Auth-Token", this.authToken).header("X-User-Id", this.userId); } public boolean isLoggedIn() { - return authToken != null && userId != null; + return this.authToken != null && this.userId != null; } } From 081eadd0467d20f3d7cae4d640043693c5475cd8 Mon Sep 17 00:00:00 2001 From: Jason Fah Date: Thu, 31 Aug 2017 18:57:45 +1000 Subject: [PATCH 4/8] sendNotification cleanup --- .../RocketChatNotificationTransport.java | 24 +++++++------------ 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/main/java/fr/ca/bamboo/plugins/RocketChatNotificationTransport.java b/src/main/java/fr/ca/bamboo/plugins/RocketChatNotificationTransport.java index fb2613d..03186bf 100644 --- a/src/main/java/fr/ca/bamboo/plugins/RocketChatNotificationTransport.java +++ b/src/main/java/fr/ca/bamboo/plugins/RocketChatNotificationTransport.java @@ -46,22 +46,13 @@ public void sendNotification(Notification notification) { // IM Messages to be sent String plainTextMessage = null; - String richTextMessage = null; HtmlImContentProvidingNotification imContentProvider = (HtmlImContentProvidingNotification) notification; plainTextMessage = imContentProvider.getIMContent(); - - // Make sure we have a message - if (StringUtils.isEmpty(richTextMessage)) { - richTextMessage = plainTextMessage; - } - if (StringUtils.isEmpty(plainTextMessage)) { - plainTextMessage = richTextMessage; - } - - // Send when we have users to send to and a message to send - if (targetChannel != null && richTextMessage != null && plainTextMessage != null) { - + + // Send when we have users to send to and a message to send + if (targetChannel != null && plainTextMessage != null) { + RocketChatConnection rcConnection = null; try { @@ -73,8 +64,9 @@ public void sendNotification(Notification notification) { rcConnection.logout(); } } - } else { - log.log(Level.INFO, "Not sending since no targets and/or text is available to be sent."); - } + + } else { + log.log(Level.INFO, "Not sending since no targets and/or text is available to be sent."); + } } } From 4f1d34a1deeb60ac49d6b92021ba3805e596e6a5 Mon Sep 17 00:00:00 2001 From: Jason Fah Date: Thu, 31 Aug 2017 18:58:23 +1000 Subject: [PATCH 5/8] removed spaces after value --- src/main/resources/configureRocketChatServer.ftl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/configureRocketChatServer.ftl b/src/main/resources/configureRocketChatServer.ftl index 755cd60..7de6f8a 100644 --- a/src/main/resources/configureRocketChatServer.ftl +++ b/src/main/resources/configureRocketChatServer.ftl @@ -14,8 +14,8 @@ titleKey='RocketChat Server' description='Send IM notifications using RocketChat.'] - [@ww.textfield name='rcServer' labelKey="rc.server.global" required='true' value =rcServer descriptionKey='rc.server.global.description' /] - [@ww.textfield name='rcUser' labelKey="rc.user.global" required='true' value =rcUser descriptionKey='rc.user.description' /] + [@ww.textfield name='rcServer' labelKey="rc.server.global" required='true' value=rcServer descriptionKey='rc.server.global.description' /] + [@ww.textfield name='rcUser' labelKey="rc.user.global" required='true' value=rcUser descriptionKey='rc.user.description' /] [@ww.password name='rcPassword' labelKey="rc.password.global" required='true' value=rcPassword showPassword="true" descriptionKey='rc.password.description' /] [@ui.clear /] From 7a63cddbbd713f3212411ff0f0e1b70082ddf2b4 Mon Sep 17 00:00:00 2001 From: Jason Fah Date: Thu, 31 Aug 2017 18:58:45 +1000 Subject: [PATCH 6/8] indenting fixed --- .../RocketChatNotificationRecipient.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/ca/bamboo/plugins/RocketChatNotificationRecipient.java b/src/main/java/fr/ca/bamboo/plugins/RocketChatNotificationRecipient.java index 55aea80..8cef2d7 100644 --- a/src/main/java/fr/ca/bamboo/plugins/RocketChatNotificationRecipient.java +++ b/src/main/java/fr/ca/bamboo/plugins/RocketChatNotificationRecipient.java @@ -133,17 +133,17 @@ public String getRecipientConfig() { public String getEditHtml() { // Get our template - String editTemplateLocation = ((NotificationRecipientModuleDescriptor)getModuleDescriptor()).getEditTemplate(); - - // Inject settings into the template context - Map context = new HashMap(); + String editTemplateLocation = ((NotificationRecipientModuleDescriptor)getModuleDescriptor()).getEditTemplate(); + + // Inject settings into the template context + Map context = new HashMap(); - // User - if (this.rcChannel != null) - context.put(VAL_RC_CHANNEL, this.rcChannel); - - // Render html - return templateRenderer.render(editTemplateLocation, context); + // User + if (this.rcChannel != null) + context.put(VAL_RC_CHANNEL, this.rcChannel); + + // Render html + return templateRenderer.render(editTemplateLocation, context); } /** From 4e74601182be901bde359c49a36bd522fb339c74 Mon Sep 17 00:00:00 2001 From: Jason Fah Date: Thu, 31 Aug 2017 18:59:27 +1000 Subject: [PATCH 7/8] version bump to 2.0 and support for bamboo 6.0.0 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 073c8ed..ac00032 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ 4.0.0 fr.ca.bamboo.plugins bamboo-rocketchat-plugin - 1.0 + 2.0 Clement Agarini @@ -19,8 +19,8 @@ atlassian-plugin - 5.7.1 - 5.7.1 + 6.0.0 + 6.0.0 5.0.4 1.2.0 From b1336251e7fa3a447c3c08f6bede48c1fb2ef178 Mon Sep 17 00:00:00 2001 From: Jason Fah Date: Thu, 31 Aug 2017 19:28:27 +1000 Subject: [PATCH 8/8] development section added to readme --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 8f0045c..95abe5b 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,11 @@ At this time, you can't use LDAP accounts and must use RocketChat local accounts - Bamboo v6.0.0 - It might work with other versions and I'll really appreciate that you tell me if it works with your version +# Development +1. Download and install the Atlassian Plugin SDK. +2. Run **atlas-package** from the project root. +3. Grab your jar file that has just been generated in the newly created **target** directory. + # Thanks I would like to specially thanks guys from [Sofico](http://www.sofico.be) for sharing their code with the world. Original code can be found here [BitBucket](https://bitbucket.org/sofico/bamboo-sametime-plugin).