Skip to content

Commit

Permalink
Merge pull request #5 from jenkinsci/removeBadge
Browse files Browse the repository at this point in the history
Adding removeBadge(icon) and removeAllBadges() methods to remove existing badges
  • Loading branch information
bakito authored Apr 1, 2018
2 parents b443538 + 1c2cb2f commit f024f19
Show file tree
Hide file tree
Showing 35 changed files with 949 additions and 121 deletions.
162 changes: 144 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,41 +20,109 @@ This method allows to add build badge icons.
// addBadge
// ------------------------------------------
// minimal params
/**
* minimal params
*
* icon: The icon for this badge
* text: The text for this badge
*/
addBadge(icon, text)
// all params
addBadge(icon, text, link)
/**
* all params
*
* icon: The icon for this badge
* text: The text for this badge
* id: (optional) The id for this badge. This id can be used to selectively delete badges.
* link: (optional) The link to be added to this badge
*/
addBadge(icon, text, id, link)
// addInfoBadge
// ------------------------------------------
// minimal params
/**
* minimal params
*
* text: The info text for this badge
*/
addInfoBadge(text)
// all params
addInfoBadge(text, link)
/**
* all params
*
* text: The info text for this badge
* id: (optional) The id for this badge. This id can be used to selectively delete badges.
* link: (optional) The link to be added to this badge
*/
addInfoBadge(text, id, link)
// addWarningBadge
// ------------------------------------------
// minimal params
/**
* minimal params
*
* text: The text for this warning badge
*/
addWarningBadge(text)
// all params
addWarningBadge(text, link)
/**
* all params
*
* text: The text for this warning badge
* id: (optional) The id for this badge. This id can be used to selectively delete badges.
* link: (optional) The link to be added to this badge
*/
addWarningBadge(text, id, link)
// addErrorBadge
// ------------------------------------------
// minimal params
/**
* minimal params
*
* text: The text for this error badge
*/
addErrorBadge(text)
// all params
addErrorBadge(text, link)
/**
* all params
*
* text: The text for this error badge
* id: (optional) The id for this badge. This id can be used to selectively delete badges.
* link: (optional) The link to be added to this badge
*/
addErrorBadge(text, id, link)
```


## removeBadges

Removes badges

```groovy
// removes badges. If no id is provided all are removed, otherwise only the badges with a matching id
// removeBadges
// ------------------------------------------
/**
* minimal params
*
*/
removeBadges()
/**
* all params
*
* id: (optional) The id for this badge. This id can be used to selectively delete badges.
*/
removeBadges(id)
```

Expand All @@ -68,9 +136,44 @@ Puts a badge with custom html
// addHtmlBadge
// ------------------------------------------
// params
/**
* minimal params
*
* html: The html content to be used for this badge
*/
addHtmlBadge(html)
/**
* all params
*
* html: The html content to be used for this badge
* id: (optional) The id for this badge. This id can be used to selectively delete badges.
*/
addHtmlBadge(html, id)
```
## removeHtmlBadges

Removes html badges

```groovy
// removes html badges. If no id is provided all are removed, otherwise only the badges with a matching id
// removeHtmlBadges
// ------------------------------------------
/**
* minimal params
*
*/
removeHtmlBadges()
/**
* all params
*
* id: (optional) The id for this badge. This id can be used to selectively delete badges.
*/
removeHtmlBadges(id)
```

Expand All @@ -86,10 +189,23 @@ Puts a badge with a short text
// addShortText
// ------------------------------------------
// minimal params
/**
* minimal params
*
* text: The text to add fot this badge
*/
addShortText(text)
// all params
/**
* all params
*
* text: The text to add fot this badge
* background: (optional) The background-color for this short text
* border: (optional) The border width for this short text
* borderColor: (optional) The order color for this short text
* color: (optional) The color for this short text
* link: (optional) The link for this short text
*/
addShortText(text, background, border, borderColor, color, link)
```
Expand All @@ -108,11 +224,21 @@ Puts a badge with a short text
// createSummary
// ------------------------------------------
// minimal params
/**
* minimal params
*
* icon: The icon for this summary
*/
createSummary(icon)
// all params
createSummary(icon, text)
/**
* all params
*
* icon: The icon for this summary
* id: (optional) The id for this badge. This id can be used to selectively delete badges.
* text: (optional) The title text for this summary
*/
createSummary(icon, id, text)
def summary = createSummary(icon)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* The MIT License
*
* Copyright (c) 2004-2010, Sun Microsystems, Inc., Serban Iordache
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.jenkinsci.plugins.badge.action;

import hudson.model.BuildBadgeAction;
import org.kohsuke.stapler.export.Exported;

import java.io.Serializable;
import java.lang.annotation.Documented;

/**
* An abstract badge action providing a badge id
*/
public abstract class AbstractBadgeAction implements BuildBadgeAction, Serializable {
private String id;

public void setId(String id) {
this.id = id;
}

@Exported
public String getId() {
return id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@

import com.jenkinsci.plugins.badge.BadgePlugin;
import hudson.PluginWrapper;
import hudson.model.Action;
import hudson.model.BuildBadgeAction;
import hudson.model.Hudson;
import jenkins.model.Jenkins;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import java.io.File;
import java.io.Serializable;

@ExportedBean(defaultVisibility = 2)
public class BadgeAction implements BuildBadgeAction, Serializable {
public class BadgeAction extends AbstractBadgeAction {
private static final long serialVersionUID = 1L;
private final String iconPath;
private final String text;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,13 @@
*/
package com.jenkinsci.plugins.badge.action;

import java.io.Serializable;

import org.apache.commons.lang.StringEscapeUtils;
import org.jenkinsci.plugins.scriptsecurity.sandbox.whitelists.Whitelisted;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import hudson.model.Action;

@ExportedBean(defaultVisibility = 2)
public class BadgeSummaryAction implements Action, Serializable {
public class BadgeSummaryAction extends AbstractBadgeAction {
private static final long serialVersionUID = 1L;

private final String iconPath;
Expand Down Expand Up @@ -88,7 +84,7 @@ public void appendText(String text, boolean escapeHtml, boolean bold, boolean it
summaryText += "<i>";
}
if (color != null) {
summaryText += "<font color=\"" + color +"\">";
summaryText += "<font color=\"" + color + "\">";
}
if (escapeHtml) {
text = StringEscapeUtils.escapeHtml(text);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,11 @@
*/
package com.jenkinsci.plugins.badge.action;

import hudson.model.BuildBadgeAction;
import org.kohsuke.stapler.export.Exported;
import org.kohsuke.stapler.export.ExportedBean;

import java.io.Serializable;

@ExportedBean(defaultVisibility = 2)
public class HtmlBadgeAction implements BuildBadgeAction, Serializable {
public class HtmlBadgeAction extends AbstractBadgeAction {
private static final long serialVersionUID = 1L;
private final String html;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* The MIT License
*
* Copyright (c) 2004-2010, Sun Microsystems, Inc., Serban Iordache
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.jenkinsci.plugins.badge.annotations;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* An optional badge param
*/

@Documented
@Retention(RUNTIME)
@Target({ElementType.METHOD, ElementType.PARAMETER})
public @interface OptionalParam {

String description();
}
Loading

0 comments on commit f024f19

Please sign in to comment.