Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a copy button for the link examples #222

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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