Skip to content

Commit

Permalink
JENKINS-40446 Links broken in GitHub status for matrix projects
Browse files Browse the repository at this point in the history
  • Loading branch information
James Dumay committed Dec 15, 2016
1 parent c8d78b5 commit 983465e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 23 deletions.
7 changes: 6 additions & 1 deletion pom.xml
Expand Up @@ -69,13 +69,18 @@
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>display-url-api</artifactId>
<version>0.6</version>
<version>1.0-beta-2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>2.14</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-multibranch</artifactId>
Expand Down
@@ -1,13 +1,16 @@
package org.jenkinsci.plugins.blueoceandisplayurl;

import com.google.common.collect.ImmutableSet;
import hudson.Extension;
import hudson.Util;
import hudson.maven.AbstractMavenBuild;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Job;
import hudson.model.Run;
import jenkins.model.Jenkins;

import hudson.tasks.test.TestResult;
import jenkins.branch.MultiBranchProject;
import jenkins.model.Jenkins;
import org.jenkinsci.plugins.displayurlapi.DisplayURLProvider;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;
Expand All @@ -19,6 +22,9 @@
@Extension
public class BlueOceanDisplayURLImpl extends DisplayURLProvider {

private static final ImmutableSet<? extends Class<? extends Run>> SUPPORTED_RUNS = ImmutableSet.of(FreeStyleBuild.class, WorkflowRun.class, AbstractMavenBuild.class);
private static final ImmutableSet<? extends Class<? extends hudson.model.AbstractItem>> SUPPORTED_JOBS = ImmutableSet.of(MultiBranchProject.class, FreeStyleProject.class);

@Override
public String getDisplayName() {
return "Blue Ocean";
Expand All @@ -39,41 +45,60 @@ public String getRoot() {

@Override
public String getRunURL(Run<?, ?> run) {
if(run instanceof WorkflowRun) {
WorkflowJob job = ((WorkflowRun) run).getParent();
if(job.getParent() instanceof MultiBranchProject) {
return getJobURL(((MultiBranchProject) job.getParent()))+ "detail/" + Util.rawEncode(job.getDisplayName()) + "/" + run.getNumber() + "/";
if (isSupported(run)) {
if (run instanceof WorkflowRun) {
WorkflowJob job = ((WorkflowRun) run).getParent();
if (job.getParent() instanceof MultiBranchProject) {
return getJobURL(((MultiBranchProject) job.getParent())) + "detail/" + Util.rawEncode(job.getDisplayName()) + "/" + run.getNumber() + "/";
}
}
Job job = run.getParent();
return getJobURL(job) + "detail/" + Util.rawEncode(job.getDisplayName()) + "/" + run.getNumber() + "/";
} else {
return DisplayURLProvider.getDefault().getRunURL(run);
}

Job job = run.getParent();
return getJobURL(job) + "detail/" + Util.rawEncode(job.getDisplayName()) + "/" + run.getNumber() + "/";
}

@Override
public String getChangesURL(Run<?, ?> run) {
return getRunURL(run) + "changes";
if (isSupported(run)) {
return getRunURL(run) + "changes";
} else {
return DisplayURLProvider.getDefault().getChangesURL(run);
}
}

public String getJobURL(MultiBranchProject<?, ?> project) {
String jobPath = Util.rawEncode(project.getFullName());

return getRoot() + "organizations/jenkins/" + jobPath + "/";
}
@Override
public String getJobURL(Job<?, ?> project) {
String jobPath;
if(project.getParent() instanceof MultiBranchProject) {
jobPath = Util.rawEncode(project.getParent().getFullName());
public String getJobURL(Job<?, ?> job) {
if (isSupported(job)) {
String jobPath;
if(job.getParent() instanceof MultiBranchProject) {
jobPath = Util.rawEncode(job.getParent().getFullName());
} else {
jobPath = Util.rawEncode(job.getFullName());
}
return getRoot() + "organizations/jenkins/" + jobPath + "/";
} else {
jobPath = Util.rawEncode(project.getFullName());
return DisplayURLProvider.getDefault().getJobURL(job);
}

return getRoot() + "organizations/jenkins/" + jobPath + "/";
}

@Override
public String getTestUrl(TestResult result) {
return getRunURL(result.getRun()) + "/tests";
}

static boolean isSupported(Run<?, ?> run) {
return SUPPORTED_RUNS.contains(run.getClass());
}

static boolean isSupported(Job<?, ?> job) {
return SUPPORTED_JOBS.contains(job.getClass());
}

private String getJobURL(MultiBranchProject<?, ?> project) {
String jobPath = Util.rawEncode(project.getFullName());

return getRoot() + "organizations/jenkins/" + jobPath + "/";
}
}

0 comments on commit 983465e

Please sign in to comment.