diff --git a/README.md b/README.md index 7760987..64b473a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Preface # +# Preface This document describes the functionality provided by the XL Release Flowdock plugin. @@ -22,20 +22,22 @@ See the [XL Release Documentation](https://docs.xebialabs.com/xl-release/) for b -# Overview # +## Overview The XL Release Flowdock plugin is a XL Release plugin that adds capability for sending message to a Flowdock inbox. -# Requirements # +## Requirements * **Requirements** * **XL Release** 6.0.x+ -# Installation # +## Installation Place the plugin JAR file into your `SERVER_HOME/plugins` directory. -# Usage # +## Usage + +### Event based notifications 1. Go to `Settings - Shared configuration - Flowdock: Configuration` 2. Add a new configuration @@ -43,3 +45,6 @@ Place the plugin JAR file into your `SERVER_HOME/plugins` directory. ![Flowdock configuration](images/Flowdock_configuration.png?raw=true "Flowdock configuration") 4. Each time XL Release stores something into the Activity logs, this will also be send to Flowdock. +### Tasks + ++ SendTeamInboxMessage: Allows to send a specific message to a TeamInbox. diff --git a/build.gradle b/build.gradle index a4c364f..bd23c43 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id "com.github.hierynomus.license" version "0.14.0" id "com.xebialabs.xl.docker" version "1.1.0" id 'nebula.release' version '6.0.0' + id "com.github.hierynomus.jython" version "0.8.0" } apply plugin: 'java' @@ -42,12 +43,19 @@ dependencies { compile "com.xebialabs.deployit:engine-api:$apiVersion" compile group: "com.xebialabs.xl-platform", name: "xl-repository-api", version: "$apiVersion", transitive: false compile "nl.javadude.t2bus:t2-bus:1.2.1" + jython ":requests:2.11.1" + jython(":python-flowdock:0.1") { + artifact { + name = "flowdock" + extension = "py" + } + } } - license { header rootProject.file('License.md') strictCheck false ext.year = Calendar.getInstance().get(Calendar.YEAR) ext.name = 'XEBIALABS' + excludes(["**/requests/**/*.py", "**/flowdock.py"]) } diff --git a/src/main/resources/caflowdock/FlowdockHelper.py b/src/main/resources/caflowdock/FlowdockHelper.py new file mode 100644 index 0000000..5a5e3ef --- /dev/null +++ b/src/main/resources/caflowdock/FlowdockHelper.py @@ -0,0 +1,18 @@ +# +# Copyright 2017 XEBIALABS +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +class FlowdockHelper(object): + + def __init__(self): + return + + @staticmethod + def get_token(variables): + return variables['flowToken'] if variables['flowToken'] else variables['flowdockServer']["flowToken"] diff --git a/src/main/resources/caflowdock/SendTeamInboxMessage.py b/src/main/resources/caflowdock/SendTeamInboxMessage.py new file mode 100644 index 0000000..de7619a --- /dev/null +++ b/src/main/resources/caflowdock/SendTeamInboxMessage.py @@ -0,0 +1,18 @@ +# +# Copyright 2017 XEBIALABS +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +import flowdock + +from caflowdock.FlowdockHelper import FlowdockHelper + +api_key = FlowdockHelper.get_token(locals()) +fdclient = flowdock.FlowDock(api_key=api_key, app_name=appName, project=project) + +fdclient.post(fromAddress, subject, content, from_name = fromName, tags=tags, link=link) diff --git a/src/main/resources/caflowdock/__init__.py b/src/main/resources/caflowdock/__init__.py new file mode 100644 index 0000000..00f3f3d --- /dev/null +++ b/src/main/resources/caflowdock/__init__.py @@ -0,0 +1,32 @@ +# +# Copyright 2017 XEBIALABS +# +# Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# + +import os +import tempfile +from com.xebialabs.xlr.ssl import LoaderUtil +from java.nio.file import Files, Paths, StandardCopyOption + +def set_ca_bundle_path(): + ca_bundle_path = extract_file_from_jar("requests/cacert.pem") + os.environ['REQUESTS_CA_BUNDLE'] = ca_bundle_path + + +def extract_file_from_jar(config_file): + file_url = LoaderUtil.getResourceBySelfClassLoader(config_file) + if file_url: + tmp_file, tmp_abs_path = tempfile.mkstemp() + tmp_file.close() + Files.copy(file_url.openStream(), Paths.get(tmp_abs_path), StandardCopyOption.REPLACE_EXISTING) + return tmp_abs_path + else: + return None + +if 'REQUESTS_CA_BUNDLE' not in os.environ: + set_ca_bundle_path() diff --git a/src/main/resources/caflowdock/flowdock.png b/src/main/resources/caflowdock/flowdock.png new file mode 100644 index 0000000..c64b76c Binary files /dev/null and b/src/main/resources/caflowdock/flowdock.png differ diff --git a/src/main/resources/synthetic.xml b/src/main/resources/synthetic.xml index b03c27d..30bb202 100644 --- a/src/main/resources/synthetic.xml +++ b/src/main/resources/synthetic.xml @@ -10,11 +10,30 @@ --> + xmlns="http://www.xebialabs.com/deployit/synthetic" + xsi:schemaLocation="http://www.xebialabs.com/deployit/synthetic synthetic.xsd"> - - + + + + + +