Skip to content
Permalink
Browse files

JENKINS-40446 Links broken in GitHub status for matrix projects (#3)

  • Loading branch information...
i386 committed Dec 15, 2016
1 parent 0918ac5 commit b69894665fccd09a2f9d84566ab91d3d1cd5fe1b
Showing with 74 additions and 22 deletions.
  1. +5 −0 pom.xml
  2. +69 −22 src/main/java/org/jenkinsci/plugins/blueoceandisplayurl/BlueOceanDisplayURLImpl.java
@@ -76,6 +76,11 @@
<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>
@@ -1,24 +1,43 @@
package org.jenkinsci.plugins.blueoceandisplayurl;

import com.google.common.collect.ImmutableSet;
import hudson.Extension;
import hudson.Util;
import hudson.maven.AbstractMavenBuild;
import hudson.maven.AbstractMavenProject;
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;

import java.util.Set;


/**
*`@author Ivan Meredith
*/
@Extension
public class BlueOceanDisplayURLImpl extends DisplayURLProvider {

private static final Set<Class> SUPPORTED_RUNS = ImmutableSet.<Class>of(
FreeStyleBuild.class,
WorkflowRun.class,
AbstractMavenBuild.class
);

private static final Set<Class> SUPPORTED_JOBS = ImmutableSet.<Class>of(
WorkflowJob.class,
MultiBranchProject.class,
FreeStyleProject.class,
AbstractMavenProject.class
);

@Override
public String getDisplayName() {
return "Blue Ocean";
@@ -39,41 +58,69 @@ 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 isInstance(run, SUPPORTED_RUNS);
}

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

static boolean isInstance(Object o, Set<Class> classes) {
for (Class<?> aClass : classes) {
if (aClass.isInstance(o)) {
return true;
}
}
return false;
}

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

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

0 comments on commit b698946

Please sign in to comment.
You can’t perform that action at this time.