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
4 changed files
with
136 additions
and
109 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
71 changes: 71 additions & 0 deletions
71
src/main/java/org/jenkinsci/plugins/typetalk/TypetalkResult.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,71 @@ | ||
package org.jenkinsci.plugins.typetalk; | ||
|
||
import hudson.model.AbstractBuild; | ||
import hudson.model.Result; | ||
|
||
public class TypetalkResult { | ||
|
||
public enum Emoji { | ||
ASTONISHED(":astonished:"), | ||
RAGE(":rage:"), | ||
CRY(":cry:"), | ||
SMILEY(":smiley:"); | ||
|
||
private String symbol; | ||
|
||
Emoji(String symbol) { | ||
this.symbol = symbol; | ||
} | ||
} | ||
|
||
private Emoji emoji; | ||
private String message; | ||
|
||
public Emoji getEmoji() { | ||
return emoji; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public TypetalkResult(Emoji emoji, String message) { | ||
this.emoji = emoji; | ||
this.message = message; | ||
} | ||
|
||
public static TypetalkResult convert(AbstractBuild<?, ?> build) { | ||
if (build.getResult().equals(Result.ABORTED)) { | ||
return new TypetalkResult(Emoji.ASTONISHED, "Build aborted"); | ||
} else if (build.getResult().equals(Result.NOT_BUILT)) { | ||
return new TypetalkResult(Emoji.ASTONISHED, "Not built"); | ||
} else if (build.getResult().equals(Result.FAILURE)) { | ||
return new TypetalkResult(Emoji.RAGE, "Build failure"); | ||
} else if (build.getResult().equals(Result.UNSTABLE)) { | ||
return new TypetalkResult(Emoji.CRY, "Build unstable"); | ||
} else if (build.getResult().equals(Result.SUCCESS)) { | ||
if (recoverSuccess(build)) { | ||
return new TypetalkResult(Emoji.SMILEY, "Build recovery"); | ||
} else { | ||
return new TypetalkResult(Emoji.SMILEY, "Build success"); | ||
} | ||
} | ||
|
||
throw new IllegalArgumentException("Unknown build result."); | ||
} | ||
|
||
private static boolean recoverSuccess(AbstractBuild<?, ?> build) { | ||
if (build.getPreviousBuild() == null) { | ||
return false; | ||
} else { | ||
return build.getResult().equals(Result.SUCCESS) | ||
&& build.getPreviousBuild().getResult().isWorseThan(Result.SUCCESS); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return emoji.symbol + " " + message; | ||
} | ||
|
||
} |
62 changes: 0 additions & 62 deletions
62
src/test/groovy/org/jenkinsci/plugins/typetalk/TypetalkNotifierSpec.groovy
This file was deleted.
Oops, something went wrong.
50 changes: 50 additions & 0 deletions
50
src/test/groovy/org/jenkinsci/plugins/typetalk/TypetalkResultSpec.groovy
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,50 @@ | ||
package org.jenkinsci.plugins.typetalk | ||
|
||
import hudson.model.AbstractBuild | ||
import hudson.model.Result | ||
import spock.lang.Specification | ||
import spock.lang.Unroll | ||
|
||
class TypetalkResultSpec extends Specification { | ||
|
||
@Unroll | ||
def convert() { | ||
setup: | ||
def build = makeMockBuild(result, previousResult) | ||
|
||
when: | ||
def typetalkResult = TypetalkResult.convert(build) | ||
|
||
then: | ||
typetalkResult.emoji == emoji | ||
typetalkResult.message.contains(message) | ||
|
||
where: | ||
previousResult | result || emoji | message | ||
Result.SUCCESS | Result.SUCCESS || TypetalkResult.Emoji.SMILEY | 'success' | ||
Result.SUCCESS | Result.UNSTABLE || TypetalkResult.Emoji.CRY | 'unstable' | ||
Result.SUCCESS | Result.FAILURE || TypetalkResult.Emoji.RAGE | 'failure' | ||
Result.SUCCESS | Result.ABORTED || TypetalkResult.Emoji.ASTONISHED | 'aborted' | ||
Result.SUCCESS | Result.NOT_BUILT || TypetalkResult.Emoji.ASTONISHED | 'Not built' | ||
|
||
Result.FAILURE | Result.SUCCESS || TypetalkResult.Emoji.SMILEY | 'recovery' | ||
Result.FAILURE | Result.UNSTABLE || TypetalkResult.Emoji.CRY | 'unstable' | ||
Result.FAILURE | Result.FAILURE || TypetalkResult.Emoji.RAGE | 'failure' | ||
Result.FAILURE | Result.ABORTED || TypetalkResult.Emoji.ASTONISHED | 'aborted' | ||
Result.FAILURE | Result.NOT_BUILT || TypetalkResult.Emoji.ASTONISHED | 'Not built' | ||
} | ||
|
||
def makeMockBuild(Result result, Result previousResult) { | ||
def build = Mock(AbstractBuild) | ||
|
||
build.result >> result | ||
build.previousBuild >> { | ||
def previousBuild = Mock(AbstractBuild) | ||
previousBuild.result >> previousResult | ||
|
||
return previousBuild | ||
} | ||
|
||
return build | ||
} | ||
} |