Skip to content

Commit 09dadb1

Browse files
authored
Provide a copy button for link examples (#222)
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
1 parent 5999f58 commit 09dadb1

File tree

8 files changed

+570
-228
lines changed

8 files changed

+570
-228
lines changed

src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
import hudson.model.Action;
99
import hudson.model.Job;
1010
import hudson.model.Run;
11+
import java.net.URLEncoder;
12+
import java.nio.charset.StandardCharsets;
1113
import org.jenkins.ui.icon.IconSpec;
1214
import org.jenkinsci.plugins.badge.*;
1315
import org.kohsuke.stapler.HttpResponse;
1416
import org.kohsuke.stapler.QueryParameter;
17+
import org.kohsuke.stapler.Stapler;
18+
import org.kohsuke.stapler.StaplerRequest;
1519
import org.kohsuke.stapler.WebMethod;
1620

1721
/**
@@ -45,6 +49,31 @@ public String getUrlName() {
4549
return "badge";
4650
}
4751

52+
public String getUrl() {
53+
/* Needed for the jelly syntax hints page */
54+
String url = "";
55+
StaplerRequest req = Stapler.getCurrentRequest();
56+
if (req != null) {
57+
url = req.getReferer();
58+
if (url == null) {
59+
url = "null-referer";
60+
}
61+
}
62+
return url;
63+
}
64+
65+
public String getUrlEncodedFullName() {
66+
/* Needed for the jelly syntax hints page */
67+
if (project == null) {
68+
return "null-project-no-url-encoded-fullName";
69+
}
70+
if (project.getFullName() == null) {
71+
return "null-project-fullName-no-url-encoded-fullName";
72+
}
73+
String fullName = URLEncoder.encode(project.getFullName(), StandardCharsets.UTF_8);
74+
return fullName == null ? "null-url-encoded-fullName" : fullName;
75+
}
76+
4877
@WebMethod(name = "icon")
4978
public HttpResponse doIcon(
5079
@QueryParameter String build,

src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
import hudson.model.Action;
88
import hudson.model.Job;
99
import hudson.model.Run;
10+
import java.net.URLEncoder;
11+
import java.nio.charset.StandardCharsets;
1012
import org.jenkins.ui.icon.IconSpec;
1113
import org.jenkinsci.plugins.badge.*;
1214
import org.kohsuke.stapler.HttpResponse;
1315
import org.kohsuke.stapler.QueryParameter;
16+
import org.kohsuke.stapler.Stapler;
1417
import org.kohsuke.stapler.WebMethod;
1518

1619
public class RunBadgeAction implements Action, IconSpec {
@@ -42,6 +45,26 @@ public String getUrlName() {
4245
return "badge";
4346
}
4447

48+
public String getUrl() {
49+
/* TODO: Is a permission check needed here? */
50+
/* Needed for the jelly syntax hints page */
51+
String url = Stapler.getCurrentRequest().getReferer();
52+
return url == null ? "null-referer" : url;
53+
}
54+
55+
public String getUrlEncodedFullName() {
56+
/* TODO: Is a permission check needed here? */
57+
/* Needed for the jelly syntax hints page */
58+
if (project == null) {
59+
return "null-project-no-url-encoded-fullName";
60+
}
61+
if (project.getFullName() == null) {
62+
return "null-project-fullName-no-url-encoded-fullName";
63+
}
64+
String fullName = URLEncoder.encode(project.getFullName(), StandardCharsets.UTF_8);
65+
return fullName == null ? "null-url-encoded-fullName" : fullName;
66+
}
67+
4568
@WebMethod(name = "icon")
4669
public HttpResponse doIcon(
4770
@QueryParameter String style,

src/main/resources/org/jenkinsci/plugins/badge/actions/JobBadgeAction/index.groovy

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)