-
Notifications
You must be signed in to change notification settings - Fork 28
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
Additional features #6
base: master
Are you sure you want to change the base?
Changes from all commits
9dcfbc6
38b068c
f00580b
9f36b8b
dcf8bd7
d75e5be
22c673f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
package com.flowdock.jenkins; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.Cause; | ||
import hudson.model.Hudson; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.Map; | ||
|
||
public class ChatMessage extends FlowdockMessage { | ||
protected String externalUserName; | ||
|
@@ -26,13 +28,30 @@ public String asPostData() throws UnsupportedEncodingException { | |
public static ChatMessage fromBuild(AbstractBuild build, BuildResult buildResult) { | ||
ChatMessage msg = new ChatMessage(); | ||
StringBuffer content = new StringBuffer(); | ||
String buildNo = build.getDisplayName().replaceAll("#", ""); | ||
content.append(build.getProject().getName()).append(" build ").append(buildNo); | ||
content.append(" ").append(buildResult.getHumanResult()); | ||
|
||
Map<String,String> buildVars = build.getBuildVariables(); | ||
String rootUrl = Hudson.getInstance().getRootUrl(); | ||
String buildLink = (rootUrl == null) ? null : rootUrl + build.getUrl(); | ||
if(buildLink != null) content.append(" \n").append(buildLink); | ||
|
||
Cause buildCause = build.getCause(hudson.triggers.SCMTrigger.SCMTriggerCause.class); | ||
String pushedBy = (buildCause != null && buildCause.getShortDescription() != null ? buildCause.getShortDescription() : "Started by: Not Available").replaceAll("Started by GitHub push by ", "Change Pushed By GitHub UserId: "); | ||
|
||
String buildNo = build.getDisplayName().replaceAll("#", ""); | ||
content.append(build.getProject().getName()) | ||
.append(" #") | ||
.append(buildNo) | ||
.append(" ") | ||
.append(buildResult.getHumanResult().toUpperCase()) | ||
.append(" \n"); | ||
|
||
if (buildVars != null) { | ||
content.append("Build Parameters: ") | ||
.append(buildVars.toString()) | ||
.append(" \n"); | ||
} | ||
content.append("Build Link: ") | ||
.append(buildLink) | ||
.append(" \n") | ||
.append(pushedBy); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to the above point, |
||
|
||
msg.setContent(content.toString()); | ||
return msg; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import hudson.scm.ChangeLogSet; | ||
import hudson.scm.ChangeLogSet.Entry; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.Map; | ||
|
||
public class TeamInboxMessage extends FlowdockMessage { | ||
|
||
|
@@ -73,25 +74,28 @@ public static TeamInboxMessage fromBuild(AbstractBuild build, BuildResult buildR | |
TeamInboxMessage msg = new TeamInboxMessage(); | ||
msg.setProject(build.getProject().getName().replaceAll("[^a-zA-Z0-9\\-_ ]", "")); | ||
String buildNo = build.getDisplayName().replaceAll("#", ""); | ||
msg.setSubject(build.getProject().getName() + " build " + buildNo + " " + buildResult.getHumanResult()); | ||
|
||
Map<String,String> buildVars = build.getBuildVariables(); | ||
String rootUrl = Hudson.getInstance().getRootUrl(); | ||
String buildLink = (rootUrl == null) ? null : rootUrl + build.getUrl(); | ||
if(buildLink != null) msg.setLink(buildLink); | ||
|
||
msg.setSubject(build.getProject().getName() + " #" + buildNo + " " + buildResult.getHumanResult().toUpperCase()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
|
||
|
||
if(build.getResult().isWorseThan(Result.SUCCESS)) | ||
msg.setFromAddress(FLOWDOCK_BUILD_FAIL_EMAIL); | ||
|
||
StringBuffer content = new StringBuffer(); | ||
content.append("<h2>").append(build.getProject().getName()).append("</h2>"); | ||
content.append("Build: ").append(build.getDisplayName()).append("<br />"); | ||
content.append("Result: ").append(buildResult.toString()).append("<br />"); | ||
if(buildLink != null) | ||
content.append("URL: <a href=\"").append(buildLink).append("\">").append(buildLink).append("</a>").append("<br />"); | ||
if (buildVars != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason for removing everything but build parameters here? After this change the inbox messages are almost empty. |
||
content.append("Build Parameters: ") | ||
.append(buildVars.toString()) | ||
.append("<br/><br/> "); | ||
} | ||
|
||
List<Entry> commits = parseCommits(build); | ||
if(commits != null) { | ||
content.append("<h3>Changes</h3><div class=\"commits\"><ul class=\"commit-list clean\">"); | ||
content.append("<h3> Changes</h3><div class=\"commits\"><ul class=\"commit-list clean\">"); | ||
for(Entry commit : commits) { | ||
content.append("<li class=\"commit\"><span class=\"commit-details\">"); | ||
content.append("<span class=\"author-info\">"). | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on quick testing,
buildVars
is usually notnull
but doesn't contain variables. This causes output like:Build Parameters: {}
which could be omitted.