Skip to content

Commit

Permalink
Added FormValidation for testing connection to Flowdock.
Browse files Browse the repository at this point in the history
  • Loading branch information
Antti Pitkanen committed Mar 22, 2012
1 parent 18f5fca commit 0dc90e0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/com/flowdock/jenkins/FlowdockNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

import javax.servlet.ServletException;
import java.io.IOException;
import java.io.PrintStream;
import java.io.StringWriter;
import java.io.ByteArrayOutputStream;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -112,6 +115,23 @@ public String getDisplayName() {
return "Flowdock notification";
}

public FormValidation doTestConnection(@QueryParameter("flowToken") final String flowToken,
@QueryParameter("notificationTags") final String notificationTags) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);

FlowdockAPI api = new FlowdockAPI(apiUrl(), flowToken, ps);
ChatMessage testMsg = new ChatMessage();
testMsg.setTags(notificationTags);
testMsg.setContent("Your plugin is ready!");

if(api.pushChatMessage(testMsg)) {
return FormValidation.ok("Success! Flowdock plugin can send notifications to your flow.");
} else {
return FormValidation.error(baos.toString());
}
}

@Override
public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {
apiUrl = formData.getString("apiUrl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
<f:textbox />
</f:entry>

<f:validateButton
title="Test connection with Chat notification" progress="Sending..."
method="testConnection" with="flowToken,notificationTags" />

<f:entry title="Chat notification when build fails" field="chatNotification">
<f:checkbox />
</f:entry>
Expand Down

0 comments on commit 0dc90e0

Please sign in to comment.