Permalink
Browse files

Refactored codebase

  • Loading branch information...
1 parent 2359d75 commit 6c501759fc718f4f00adadd4f60eb75a78f9e281 Antti Pitkanen committed Mar 20, 2012
View
0 README
No changes.
View
@@ -0,0 +1,55 @@
+# Jenkins Flowdock Plugin
+
+Jenkins Flowdock Plugin is a tool for sending build notification from Jenkins to your flow. It hooks to Post-build Actions of the build,
+so you can use with any number of different builds. All you need to configure is the API token of the flow where you want the notifications
+to go. See [Tokens](https://www.flowdock.com/account/tokens) page for list of your API tokens.
+
+## Install
+
+### From Jenkins Plugin repository
+
+ * Go to Manage Jenkins/Hudson -> Manage Plugins -> Available
+ * Find "Flowdock plugin" and install it
+ * Restart Jenkins/Hudson
+
+### From source
+
+ * Clone the Github repo
+ * Run `mvn install` to build a .hpi-plugin package
+ * Install to Jenkins/Hudson by uploading the package in admin: `Manage Jenkins/Hudson -> Manage Plugins -> Advanced -> Upload Plugin`
+ * Restart Jenkins
+
+## Configure
+
+ * Go to Configure page inside a build
+ * Scroll down to Post-build Actions
+ * Select "Flowdock notification" from the list and fill out your the API token of your flow
+ * Save the changes and click "Build Now"
+ * Your flow should now receive notification. If not, see the Console Output of the build for errors.
+
+## Troubleshooting by Console Output
+
+```
+Flowdock: failed to send notification
+Flowdock: response status: 401
+```
+
+Most likely the API token is not valid or you do not have the permission to access the flow.
+
+```
+Flowdock: failed to send notification
+Flowdock: response status: 400
+```
+
+Validation of the notification message failed. This can occur when customizing the build notification content as it needs to conform to
+ Flowdock Push API format described in [the API documentation](https://www.flowdock.com/api/push).
+
+## Write your own custom notifier
+
+It's easy, just fork the Github repo of Jenkins Flowdock Plugin and start hacking!
+
+To simply modify the contents of Team Inbox or Chat messages sent by the plugin, see the `fromBuild` method in `TeamInboxMessage` and `ChatMessage` classes.
+
+Jenkins Flowdock Plugin contains a full implementation of the [Flowdock Push API](https://www.flowdock.com/api/push) which is great for posting notifications.
+If you need to go beyond simple notifications, have a look at what the [REST API](https://www.flowdock.com/api/rest) can offer you.
+
View
11 pom.xml
@@ -3,14 +3,19 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
- <version>1.409</version><!-- which version of Jenkins is this plugin built against? -->
+ <version>1.454</version><!-- which version of Jenkins is this plugin built against? -->
</parent>
<groupId>com.flowdock.jenkins</groupId>
- <artifactId>flowdock-jenkins-plugin</artifactId>
- <version>1.0-SNAPSHOT</version>
+ <artifactId>jenkins-flowdock-plugin</artifactId>
+ <version>1.0</version>
<packaging>hpi</packaging>
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ </properties>
+
<!-- get every artifact through maven.glassfish.org, which proxies all the artifacts that we need -->
<repositories>
<repository>
@@ -5,37 +5,36 @@
import java.io.UnsupportedEncodingException;
public class ChatMessage extends FlowdockMessage {
- protected String externalUserName;
+ protected String externalUserName;
- public ChatMessage() {
- this.externalUserName = "Jenkins";
- }
+ public ChatMessage() {
+ this.externalUserName = "Jenkins";
+ }
- public void setExternalUserName(String externalUserName) {
- this.externalUserName = externalUserName;
- }
+ public void setExternalUserName(String externalUserName) {
+ this.externalUserName = externalUserName;
+ }
- public String asPostData() throws UnsupportedEncodingException {
- StringBuffer postData = new StringBuffer();
- postData.append("content=").append(urlEncode(content));
- postData.append("&external_user_name=").append(urlEncode(externalUserName));
- postData.append("&tags=").append(urlEncode(tags));
- return postData.toString();
- }
+ public String asPostData() throws UnsupportedEncodingException {
+ StringBuffer postData = new StringBuffer();
+ postData.append("content=").append(urlEncode(content));
+ postData.append("&external_user_name=").append(urlEncode(externalUserName));
+ postData.append("&tags=").append(urlEncode(tags));
+ return postData.toString();
+ }
- public static ChatMessage fromBuild(AbstractBuild build) {
- ChatMessage msg = new ChatMessage();
- StringBuffer content = new StringBuffer();
- content.append("Build: ").append(build.getProject().getName()).
- append(" ").append(build.getDisplayName()).
- append(" is ").append(build.getResult().toString());
+ public static ChatMessage fromBuild(AbstractBuild build) {
+ ChatMessage msg = new ChatMessage();
+ StringBuffer content = new StringBuffer();
+ content.append("Build: ").append(build.getProject().getName()).
+ append(" ").append(build.getDisplayName()).
+ append(" is ").append(build.getResult().toString());
- String rootUrl = Hudson.getInstance().getRootUrl();
- String buildLink = (rootUrl == null) ? null : rootUrl + build.getUrl();
- if(buildLink != null)
- content.append(" \n").append(buildLink);
+ String rootUrl = Hudson.getInstance().getRootUrl();
+ String buildLink = (rootUrl == null) ? null : rootUrl + build.getUrl();
+ if(buildLink != null) content.append(" \n").append(buildLink);
- msg.setContent(content.toString());
- return msg;
- }
-}
+ msg.setContent(content.toString());
+ return msg;
+ }
+}
@@ -6,20 +6,20 @@
import java.net.URLEncoder;
public abstract class FlowdockMessage {
- protected String content;
- protected String tags;
+ protected String content;
+ protected String tags;
- public void setContent(String content) {
- this.content = content;
- }
+ public void setContent(String content) {
+ this.content = content;
+ }
- public void setTags(String tags) {
- this.tags = tags;
- }
+ public void setTags(String tags) {
+ this.tags = tags;
+ }
- public abstract String asPostData() throws UnsupportedEncodingException;
+ public abstract String asPostData() throws UnsupportedEncodingException;
- protected String urlEncode(String data) throws UnsupportedEncodingException {
- return data == null ? "" : URLEncoder.encode(data, "UTF-8");
- }
+ protected String urlEncode(String data) throws UnsupportedEncodingException {
+ return data == null ? "" : URLEncoder.encode(data, "UTF-8");
+ }
}
@@ -27,53 +27,32 @@
private final String notificationTags;
private final Boolean chatNotification;
- private final Boolean notifySuccess;
- private final Boolean notifyFailure;
- private final Boolean notifyUnstable;
- private final Boolean notifyAborted;
- private final Boolean notifyNotBuilt;
+ private final Map<Result, Boolean> notifyMap;
// Fields in config.jelly must match the parameter names in the "DataBoundConstructor"
@DataBoundConstructor
public FlowdockNotifier(String flowToken, String notificationTags, Boolean chatNotification,
- Boolean notifySuccess, Boolean notifyFailure, Boolean notifyUnstable, Boolean notifyAborted, Boolean notifyNotBuilt) {
+ final Boolean notifySuccess, final Boolean notifyFailure, final Boolean notifyUnstable,
+ final Boolean notifyAborted, final Boolean notifyNotBuilt) {
this.flowToken = flowToken;
this.notificationTags = notificationTags;
this.chatNotification = chatNotification;
- this.notifySuccess = notifySuccess;
- this.notifyFailure = notifyFailure;
- this.notifyUnstable = notifyUnstable;
- this.notifyAborted = notifyAborted;
- this.notifyNotBuilt = notifyNotBuilt;
+ this.notifyMap = new HashMap<Result, Boolean>() {{
+ put(Result.SUCCESS, notifySuccess);
+ put(Result.FAILURE, notifyFailure);
+ put(Result.UNSTABLE, notifyUnstable);
+ put(Result.ABORTED, notifyAborted);
+ put(Result.NOT_BUILT, notifyNotBuilt);
+ }};
}
public String getFlowToken() {
- return flowToken;
+ return flowToken;
}
public String getNotificationTags() {
- return notificationTags;
- }
-
- public Boolean getChatNotification() {
- return chatNotification;
- }
-
- public Boolean getNotifySuccess() {
- return notifySuccess;
- }
- public Boolean getNotifyFailure() {
- return notifyFailure;
- }
- public Boolean getNotifyUnstable() {
- return notifyUnstable;
- }
- public Boolean getNotifyAborted() {
- return notifyAborted;
- }
- public Boolean getNotifyNotBuilt() {
- return notifyNotBuilt;
+ return notificationTags;
}
public BuildStepMonitor getRequiredMonitorService() {
@@ -96,13 +75,6 @@ public boolean perform(AbstractBuild build, Launcher launcher, BuildListener lis
}
public boolean shouldNotify(Result buildResult) {
- Map<Result, Boolean> notifyMap = new HashMap<Result, Boolean>() {{
- put(Result.SUCCESS, notifySuccess);
- put(Result.FAILURE, notifyFailure);
- put(Result.UNSTABLE, notifyUnstable);
- put(Result.ABORTED, notifyAborted);
- put(Result.NOT_BUILT, notifyNotBuilt);
- }};
return notifyMap.get(buildResult);
}
@@ -129,7 +101,7 @@ public DescriptorImpl getDescriptor() {
@Extension
public static final class DescriptorImpl extends BuildStepDescriptor<Publisher> {
- private String apiUrl = "https://api.flowdock.com/";
+ private String apiUrl = "https://api.flowdock.com";
public boolean isApplicable(Class<? extends AbstractProject> aClass) {
return true;
Oops, something went wrong.

0 comments on commit 6c50175

Please sign in to comment.