This repository was archived by the owner on Feb 13, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
199 additions
and
191 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 0 additions & 117 deletions
117
src/main/java/org/jenkinsci/plugins/typetalk/api/TypetalkMessage.java
This file was deleted.
Oops, something went wrong.
23 changes: 23 additions & 0 deletions
23
src/main/java/org/jenkinsci/plugins/typetalk/support/Emoji.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.jenkinsci.plugins.typetalk.support; | ||
|
||
public enum Emoji { | ||
LOUDSPEAKER(":loudspeaker:"), | ||
MEGA(":mega:"), | ||
ASTONISHED(":astonished:"), | ||
RAGE(":rage:"), | ||
CRY(":cry:"), | ||
SMILEY(":smiley:"), | ||
MASK(":mask:"), | ||
BOOK(":book:"), | ||
PAGE_FACING_UP(":page_facing_up:"); | ||
|
||
private String symbol; | ||
|
||
public String getSymbol() { | ||
return symbol; | ||
} | ||
|
||
Emoji(String symbol) { | ||
this.symbol = symbol; | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
src/main/java/org/jenkinsci/plugins/typetalk/support/ResultSupport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package org.jenkinsci.plugins.typetalk.support; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.AbstractProject; | ||
import hudson.model.Result; | ||
|
||
public class ResultSupport { | ||
|
||
public TypetalkMessage convertBuildToMessage(AbstractBuild build) { | ||
if (build.getResult().equals(Result.ABORTED)) { | ||
return new TypetalkMessage(Emoji.ASTONISHED, "Build aborted"); | ||
} else if (build.getResult().equals(Result.NOT_BUILT)) { | ||
return new TypetalkMessage(Emoji.ASTONISHED, "Not built"); | ||
} else if (build.getResult().equals(Result.FAILURE)) { | ||
return new TypetalkMessage(Emoji.RAGE, "Build failure"); | ||
} else if (build.getResult().equals(Result.UNSTABLE)) { | ||
return new TypetalkMessage(Emoji.CRY, "Build unstable"); | ||
} else if (build.getResult().equals(Result.SUCCESS)) { | ||
if (recoverSuccess(build)) { | ||
return new TypetalkMessage(Emoji.SMILEY, "Build recovery"); | ||
} else { | ||
return new TypetalkMessage(Emoji.SMILEY, "Build success"); | ||
} | ||
} | ||
|
||
throw new IllegalArgumentException("Unknown build result."); | ||
} | ||
|
||
public boolean recoverSuccess(AbstractBuild build) { | ||
if (build.getPreviousBuild() == null) { | ||
return false; | ||
} else { | ||
return build.getResult().equals(Result.SUCCESS) | ||
&& build.getPreviousBuild().getResult().isWorseThan(Result.SUCCESS); | ||
} | ||
} | ||
|
||
public Emoji convertProjectToEmoji(AbstractProject project) { | ||
switch (project.getIconColor()) { | ||
case RED: | ||
case RED_ANIME: | ||
return Emoji.RAGE; | ||
case YELLOW: | ||
case YELLOW_ANIME: | ||
return Emoji.CRY; | ||
case BLUE: | ||
case BLUE_ANIME: | ||
return Emoji.SMILEY; | ||
case DISABLED: | ||
case DISABLED_ANIME: | ||
case NOTBUILT: | ||
case NOTBUILT_ANIME: | ||
return Emoji.MASK; | ||
default: | ||
return Emoji.ASTONISHED; | ||
} | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
src/main/java/org/jenkinsci/plugins/typetalk/support/TypetalkMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.jenkinsci.plugins.typetalk.support; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.AbstractProject; | ||
import jenkins.model.Jenkins; | ||
import org.apache.commons.lang.StringUtils; | ||
|
||
public class TypetalkMessage { | ||
|
||
private final Emoji emoji; | ||
private final String message; | ||
|
||
public Emoji getEmoji() { | ||
return emoji; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public TypetalkMessage(Emoji emoji, String message) { | ||
this.emoji = emoji; | ||
this.message = message; | ||
} | ||
|
||
public String buildMessageWithBuild(AbstractBuild<?, ?> build) { | ||
final String rootUrl = Jenkins.getInstance().getRootUrl(); | ||
if (StringUtils.isEmpty(rootUrl)) { | ||
throw new IllegalStateException("Root URL isn't configured yet. Cannot compute absolute URL."); | ||
} | ||
|
||
final StringBuilder builder = new StringBuilder(); | ||
builder.append(emoji.getSymbol()); | ||
builder.append(" "); | ||
builder.append(message); | ||
builder.append(" [ "); | ||
builder.append(build.getProject().getDisplayName()); | ||
builder.append(" ]"); | ||
builder.append("\n"); | ||
builder.append(rootUrl); | ||
builder.append(build.getUrl()); | ||
|
||
return builder.toString(); | ||
} | ||
|
||
public String buildMessageWithProject(AbstractProject project) { | ||
final String rootUrl = Jenkins.getInstance().getRootUrl(); | ||
if (StringUtils.isEmpty(rootUrl)) { | ||
throw new IllegalStateException("Root URL isn't configured yet. Cannot compute absolute URL."); | ||
} | ||
|
||
final StringBuilder builder = new StringBuilder(); | ||
builder.append(emoji.getSymbol()); | ||
builder.append(" "); | ||
builder.append(message); | ||
builder.append("\n"); | ||
builder.append(rootUrl); | ||
if (project != null) { | ||
builder.append(project.getUrl()); | ||
} | ||
|
||
return builder.toString(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.