Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the ability to always set the notify flag, regardless of build statu... #72

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/main/java/jenkins/plugins/hipchat/ActiveNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void completed(AbstractBuild r) {
|| (result == Result.SUCCESS && previousResult == Result.FAILURE && jobProperty.getNotifyBackToNormal())
|| (result == Result.SUCCESS && jobProperty.getNotifySuccess())
|| (result == Result.UNSTABLE && jobProperty.getNotifyUnstable())) {
getHipChat(r).publish(getBuildStatusMessage(r), getBuildColor(r));
getHipChat(r).publish(getBuildStatusMessage(r), getBuildColor(r), jobProperty.getAlwaysShowNotification());
}
}

Expand All @@ -84,7 +84,12 @@ String getChanges(AbstractBuild r) {
Entry entry = (Entry) o;
logger.info("Entry " + o);
entries.add(entry);
files.addAll(entry.getAffectedFiles());
try{
files.addAll(entry.getAffectedFiles());
} catch (UnsupportedOperationException e) {
logger.info(e.getMessage());
return null;
}
}
if (entries.isEmpty()) {
logger.info("Empty change...");
Expand Down
19 changes: 13 additions & 6 deletions src/main/java/jenkins/plugins/hipchat/HipChatNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ public DescriptorImpl getDescriptor() {
}

public String getRoom() {
return room;
return this.room;
}

public String getAuthToken() {
return authToken;
return this.authToken;
}

public String getBuildServerUrl() {
return buildServerUrl;
return this.buildServerUrl;
}

public String getSendAs() {
return sendAs;
return this.sendAs;
}


Expand Down Expand Up @@ -144,6 +144,7 @@ public static class HipChatJobProperty extends hudson.model.JobProperty<Abstract
private boolean notifyUnstable;
private boolean notifyFailure;
private boolean notifyBackToNormal;
private boolean alwaysShowNotification;


@DataBoundConstructor
Expand All @@ -154,7 +155,8 @@ public HipChatJobProperty(String room,
boolean notifyNotBuilt,
boolean notifySuccess,
boolean notifyUnstable,
boolean notifyBackToNormal) {
boolean notifyBackToNormal,
boolean alwaysShowNotification) {
this.room = room;
this.startNotification = startNotification;
this.notifyAborted = notifyAborted;
Expand All @@ -163,6 +165,7 @@ public HipChatJobProperty(String room,
this.notifySuccess = notifySuccess;
this.notifyUnstable = notifyUnstable;
this.notifyBackToNormal = notifyBackToNormal;
this.alwaysShowNotification = alwaysShowNotification;
}

@Exported
Expand Down Expand Up @@ -219,6 +222,9 @@ public boolean getNotifyBackToNormal() {
return notifyBackToNormal;
}

@Exported
public boolean getAlwaysShowNotification() { return alwaysShowNotification; }

@Extension
public static final class DescriptorImpl extends JobPropertyDescriptor {
public String getDisplayName() {
Expand All @@ -239,7 +245,8 @@ public HipChatJobProperty newInstance(StaplerRequest sr, JSONObject formData) th
sr.getParameter("hipChatNotifyNotBuilt") != null,
sr.getParameter("hipChatNotifySuccess") != null,
sr.getParameter("hipChatNotifyUnstable") != null,
sr.getParameter("hipChatNotifyBackToNormal") != null);
sr.getParameter("hipChatNotifyBackToNormal") != null,
sr.getParameter("hipChatAlwaysShowNotification") != null);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/jenkins/plugins/hipchat/HipChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ public interface HipChatService {
void publish(String message);

void publish(String message, String color);

void publish(String message, String color, Boolean notify);
}
14 changes: 11 additions & 3 deletions src/main/java/jenkins/plugins/hipchat/StandardHipChatService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,12 @@ public void publish(String message) {
}

public void publish(String message, String color) {
publish(message, color, false);
}

public void publish(String message, String color, Boolean notify) {
for (String roomId : roomIds) {
logger.info("Posting: " + from + " to " + roomId + ": " + message + " " + color);
logger.info("Posting: " + from + " to " + roomId + ": " + message + " " + color + " " + notify);
HttpClient client = getHttpClient();
String url = "https://" + host + "/v1/rooms/message?auth_token=" + token;
PostMethod post = new PostMethod(url);
Expand All @@ -42,7 +46,7 @@ public void publish(String message, String color) {
post.addParameter("room_id", roomId);
post.addParameter("message", message);
post.addParameter("color", color);
post.addParameter("notify", shouldNotify(color));
post.addParameter("notify", shouldNotify(color, notify));
post.getParams().setContentCharset("UTF-8");
int responseCode = client.executeMethod(post);
String response = post.getResponseBodyAsString();
Expand All @@ -68,10 +72,14 @@ private HttpClient getHttpClient() {
return client;
}

private String shouldNotify(String color) {
private String shouldColorNotify(String color) {
return color.equalsIgnoreCase("green") ? "0" : "1";
}

private String shouldNotify(String color, Boolean notify) {
return notify ? "1" : shouldColorNotify(color);
}

void setHost(String host) {
this.host = host;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">

<f:section title="HipChat Notifications">
<f:entry title="Project Room">
<f:textbox name="hipChatProjectRoom" value="${instance.getRoom()}"/>
</f:entry>
<f:section title="HipChat Notifications">
<f:entry title="Project Room">
<f:textbox name="hipChatProjectRoom" value="${instance.getRoom()}"/>
</f:entry>

<f:entry title="Notify Build Start">
<f:checkbox name="hipChatStartNotification" value="true" checked="${instance.getStartNotification()}"/>
</f:entry>
<f:entry title="Notify Build Start">
<f:checkbox name="hipChatStartNotification" value="true" checked="${instance.getStartNotification()}"/>
</f:entry>

<f:entry title="Notify Aborted">
<f:checkbox name="hipChatNotifyAborted" value="true" checked="${instance.getNotifyAborted()}"/>
Expand All @@ -33,6 +33,9 @@
<f:checkbox name="hipChatNotifyBackToNormal" value="true" checked="${instance.getNotifyBackToNormal()}"/>
</f:entry>

<f:entry title="Always Show Notification">
<f:checkbox name="hipChatAlwaysShowNotification" value="true" checked="${instance.getAlwaysShowNotification()}"/>
</f:entry>
</f:section>

</j:jelly>