Skip to content

Commit

Permalink
Merge pull request #18 from Brantone/master
Browse files Browse the repository at this point in the history
New endpoint 'text' to return icon description
  • Loading branch information
R. Tyler Croy committed Nov 2, 2016
2 parents 9d6a4c8 + db371f1 commit df55576
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/main/java/org/jenkinsci/plugins/badge/BadgeAction.java
Expand Up @@ -38,4 +38,11 @@ public String getUrlName() {
public HttpResponse doIcon(@QueryParameter String style) {
return factory.getImage(project.getIconColor(), style);
}

/**
* Serves text.
*/
public String doText() {
return project.getIconColor().getDescription();
}
}
13 changes: 13 additions & 0 deletions src/main/java/org/jenkinsci/plugins/badge/PublicBadgeAction.java
Expand Up @@ -100,6 +100,19 @@ public HttpResponse doIcon(StaplerRequest req, StaplerResponse rsp, @QueryParame
}
}

/**
* Serves text.
*/
public String doText(StaplerRequest req, StaplerResponse rsp, @QueryParameter String job, @QueryParameter String build) {
if(build != null) {
Run run = getRun(job, build);
return run.getIconColor().getDescription();
} else {
Job<?, ?> project = getProject(job);
return project.getIconColor().getDescription();
}
}

private Job<?, ?> getProject(String job) {
Job<?, ?> p;

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/org/jenkinsci/plugins/badge/RunBadgeAction.java
Expand Up @@ -36,4 +36,11 @@ public String getUrlName() {
public HttpResponse doIcon(@QueryParameter String style) {
return factory.getImage(run.getIconColor(), style);
}

/**
* Serves text.
*/
public String doText() {
return project.getIconColor().getDescription();
}
}
Expand Up @@ -35,7 +35,10 @@ l.layout {
def jobUrlWithoutView = "${app.rootUrl}job/${fullJobName}";
def badgeUrlWithView = jobUrlWithView + "badge/icon"
def badgeUrlWithoutView = jobUrlWithoutView + "/badge/icon"
def textUrlWithView = jobUrlWithView + "badge/text"
def textUrlWithoutView = jobUrlWithoutView + "/badge/text"
def publicBadge = "${app.rootUrl}buildStatus/icon?job=${fullJobName}";
def publicText = "${app.rootUrl}buildStatus/text?job=${fullJobName}";


h3 {
Expand Down Expand Up @@ -104,5 +107,17 @@ l.layout {
input(type:"text",value:"[[image:${badgeUrlWithoutView}>>${jobUrlWithoutView}||target='__new']]",class:"select-all")
b {text(_("unprotected"))}
input(type:"text",value:"[[image:${publicBadge}>>${jobUrlWithoutView}||target='__new']]",class:"select-all")


h2(_("Embeddable Build Status Text"))
p(raw(_("blurb_text")))

h3(_("Text Only"))
b {text(_("protected (with view)"))}
input(type:"text",value:textUrlWithView,class:"select-all")
b {text(_("protected (without view)"))}
input(type:"text",value:textUrlWithoutView,class:"select-all")
b {text(_("unprotected"))}
input(type:"text",value:publicText,class:"select-all")
}
}
Expand Up @@ -17,3 +17,6 @@ blurb=Jenkins exposes the current status of your build as an image in a fixed UR
<li><b>plastic</b> (the one used in version 1.5)\
</ul> \
You can choose the one you prefer by appending <tt>?style=plastic</tt> to the URL.
blurb_text=Jenkins also exposes the current status of your build in plain text. \
You can use this in external scripts for easier interpretation of the current state of the build. \
Similar to the badge there are both <b>with view</b> and <b>without view</b> for <b>protected</b>, as well as <b>unprotected</b> variants.
Expand Up @@ -35,7 +35,10 @@ l.layout {
def jobUrlWithoutView = "${app.rootUrl}job/${fullJobName}/${my.run.number}/";
def badgeUrlWithView = jobUrlWithView + "badge/icon"
def badgeUrlWithoutView = jobUrlWithoutView + "/badge/icon"
def textUrlWithView = jobUrlWithView + "badge/text"
def textUrlWithoutView = jobUrlWithoutView + "/badge/text"
def publicBadge = "${app.rootUrl}buildStatus/icon?job=${fullJobName}&build=${my.run.number}";
def publicText = "${app.rootUrl}buildStatus/text?job=${fullJobName}&build=${my.run.number}";

h3 {
text(_("Image"))
Expand Down Expand Up @@ -104,5 +107,17 @@ l.layout {
input(type:"text",value:"[[image:${badgeUrlWithoutView}>>${jobUrlWithoutView}||target='__new']]",class:"select-all")
b {text(_("unprotected"))}
input(type:"text",value:"[[image:${publicBadge}>>${jobUrlWithoutView}||target='__new']]",class:"select-all")


h2(_("Embeddable Build Status Text"))
p(raw(_("blurb_text")))

h3(_("Text Only"))
b {text(_("protected (with view)"))}
input(type:"text",value:textUrlWithView,class:"select-all")
b {text(_("protected (without view)"))}
input(type:"text",value:textUrlWithoutView,class:"select-all")
b {text(_("unprotected"))}
input(type:"text",value:publicText,class:"select-all")
}
}
Expand Up @@ -17,3 +17,6 @@ blurb=Jenkins exposes the status of the specific build as an image in a fixed UR
<li><b>plastic</b> (the one used in version 1.5)\
</ul> \
You can choose the one you prefer by appending <tt>?style=plastic</tt> to the URL.
blurb_text=Jenkins also exposes the current status of your build in plain text. \
You can use this in external scripts for easier interpretation of the current state of the build. \
Similar to the badge there are both <b>with view</b> and <b>without view</b> for <b>protected</b>, as well as <b>unprotected</b> variants.
Expand Up @@ -27,6 +27,7 @@
import static org.junit.Assert.fail;

import hudson.model.FreeStyleProject;
import hudson.model.Run;
import hudson.security.GlobalMatrixAuthorizationStrategy;
import hudson.security.SecurityRealm;

Expand All @@ -36,8 +37,10 @@
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.recipes.PresetData;
import hudson.tasks.Shell;

import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException;
import com.gargoylesoftware.htmlunit.TextPage;

/**
* @author Dominik Bartholdi (imod)
Expand Down Expand Up @@ -161,4 +164,46 @@ public void validAnonymousAccess() throws Exception {
j.buildAndAssertSuccess(project);
wc.goTo("buildStatus/icon?job=free&build=1", "image/svg+xml");
}

@Test
public void validTextStatusNotBuilt() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject("free");
JenkinsRule.WebClient wc = j.createWebClient();

TextPage p = (com.gargoylesoftware.htmlunit.TextPage) wc.goTo("buildStatus/text?job=free", "text/plain");
assertEquals(p.getContent(), "Not built");
}

@Test
public void validTextStatusDisabled() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject("free");
JenkinsRule.WebClient wc = j.createWebClient();

project.makeDisabled(true);
TextPage p = (com.gargoylesoftware.htmlunit.TextPage) wc.goTo("buildStatus/text?job=free", "text/plain");
assertEquals(p.getContent(), "Disabled");
}

@Test
public void validTextStatusSuccess() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject("free");
JenkinsRule.WebClient wc = j.createWebClient();

j.buildAndAssertSuccess(project);
TextPage p = (com.gargoylesoftware.htmlunit.TextPage) wc.goTo("buildStatus/text?job=free&build=1", "text/plain");
assertEquals(p.getContent(), "Success");
}

@Test
public void validTextStatusFailed() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject("free");
JenkinsRule.WebClient wc = j.createWebClient();

Shell shell = new Shell("exit 1");
project.getBuildersList().add(shell);

Run r = project.scheduleBuild2(0).get();
TextPage p = (com.gargoylesoftware.htmlunit.TextPage) wc.goTo("buildStatus/text?job=free&build=1", "text/plain");
assertEquals(p.getContent(), "Failed");
}
}

0 comments on commit df55576

Please sign in to comment.