Skip to content

Commit

Permalink
Provide a copy button for link examples (#222)
Browse files Browse the repository at this point in the history
Use a more modern page layout with jelly instead of groovy layout.  Provide a copy button rather than using a borderless input field to provide easy copy and paste.  The copy button is used in multiple places in Jenkins.

Fix Bitbucket URL link error (Had unbalanced parentheses)

Add Asciidoc examples

Fixes #59
  • Loading branch information
MarkEWaite authored Aug 2, 2023
1 parent 5999f58 commit 09dadb1
Show file tree
Hide file tree
Showing 8 changed files with 570 additions and 228 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
import hudson.model.Action;
import hudson.model.Job;
import hudson.model.Run;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import org.jenkins.ui.icon.IconSpec;
import org.jenkinsci.plugins.badge.*;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.WebMethod;

/**
Expand Down Expand Up @@ -45,6 +49,31 @@ public String getUrlName() {
return "badge";
}

public String getUrl() {
/* Needed for the jelly syntax hints page */
String url = "";
StaplerRequest req = Stapler.getCurrentRequest();
if (req != null) {
url = req.getReferer();
if (url == null) {
url = "null-referer";
}
}
return url;
}

public String getUrlEncodedFullName() {
/* Needed for the jelly syntax hints page */
if (project == null) {
return "null-project-no-url-encoded-fullName";
}
if (project.getFullName() == null) {
return "null-project-fullName-no-url-encoded-fullName";
}
String fullName = URLEncoder.encode(project.getFullName(), StandardCharsets.UTF_8);
return fullName == null ? "null-url-encoded-fullName" : fullName;
}

@WebMethod(name = "icon")
public HttpResponse doIcon(
@QueryParameter String build,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
import hudson.model.Action;
import hudson.model.Job;
import hudson.model.Run;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import org.jenkins.ui.icon.IconSpec;
import org.jenkinsci.plugins.badge.*;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.WebMethod;

public class RunBadgeAction implements Action, IconSpec {
Expand Down Expand Up @@ -42,6 +45,26 @@ public String getUrlName() {
return "badge";
}

public String getUrl() {
/* TODO: Is a permission check needed here? */
/* Needed for the jelly syntax hints page */
String url = Stapler.getCurrentRequest().getReferer();
return url == null ? "null-referer" : url;
}

public String getUrlEncodedFullName() {
/* TODO: Is a permission check needed here? */
/* Needed for the jelly syntax hints page */
if (project == null) {
return "null-project-no-url-encoded-fullName";
}
if (project.getFullName() == null) {
return "null-project-fullName-no-url-encoded-fullName";
}
String fullName = URLEncoder.encode(project.getFullName(), StandardCharsets.UTF_8);
return fullName == null ? "null-url-encoded-fullName" : fullName;
}

@WebMethod(name = "icon")
public HttpResponse doIcon(
@QueryParameter String style,
Expand Down

This file was deleted.

Loading

0 comments on commit 09dadb1

Please sign in to comment.