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 @@
return "badge";
}

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

Check warning on line 56 in src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 56 is only partially covered, one branch is missing
url = req.getReferer();

Check warning on line 57 in src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 57 is not covered by tests
if (url == null) {

Check warning on line 58 in src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 58 is only partially covered, 2 branches are missing
url = "null-referer";

Check warning on line 59 in src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 59 is not covered by tests
}
}
return url;
}

public String getUrlEncodedFullName() {
/* Needed for the jelly syntax hints page */
if (project == null) {

Check warning on line 67 in src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 67 is only partially covered, one branch is missing
return "null-project-no-url-encoded-fullName";

Check warning on line 68 in src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 68 is not covered by tests
}
if (project.getFullName() == null) {

Check warning on line 70 in src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 70 is only partially covered, one branch is missing
return "null-project-fullName-no-url-encoded-fullName";

Check warning on line 71 in src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 71 is not covered by tests
}
String fullName = URLEncoder.encode(project.getFullName(), StandardCharsets.UTF_8);
return fullName == null ? "null-url-encoded-fullName" : fullName;

Check warning on line 74 in src/main/java/org/jenkinsci/plugins/badge/actions/JobBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 74 is only partially covered, one branch is missing
}

@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 @@
return "badge";
}

public String getUrl() {
/* TODO: Is a permission check needed here? */

Check warning on line 49 in src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: Is a permission check needed here? */
/* Needed for the jelly syntax hints page */
String url = Stapler.getCurrentRequest().getReferer();

Check warning on line 51 in src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 51 is not covered by tests
return url == null ? "null-referer" : url;

Check warning on line 52 in src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 52 is only partially covered, 2 branches are missing
}

public String getUrlEncodedFullName() {
/* TODO: Is a permission check needed here? */

Check warning on line 56 in src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java

View check run for this annotation

ci.jenkins.io / Open Tasks Scanner

TODO

NORMAL: Is a permission check needed here? */
/* Needed for the jelly syntax hints page */
if (project == null) {

Check warning on line 58 in src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 58 is only partially covered, 2 branches are missing
return "null-project-no-url-encoded-fullName";

Check warning on line 59 in src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 59 is not covered by tests
}
if (project.getFullName() == null) {

Check warning on line 61 in src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 61 is only partially covered, 2 branches are missing
return "null-project-fullName-no-url-encoded-fullName";

Check warning on line 62 in src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 62 is not covered by tests
}
String fullName = URLEncoder.encode(project.getFullName(), StandardCharsets.UTF_8);

Check warning on line 64 in src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 64 is not covered by tests
return fullName == null ? "null-url-encoded-fullName" : fullName;

Check warning on line 65 in src/main/java/org/jenkinsci/plugins/badge/actions/RunBadgeAction.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 65 is only partially covered, 2 branches are missing
}

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

This file was deleted.

Loading