Skip to content

Commit

Permalink
JENKINS-40877 PR link on run details. (#894)
Browse files Browse the repository at this point in the history
* Include branch and pr info in run model

* [JENKINS-40877] Link to PR's

* Add some padding to icon

* More attemps

* [JENKINS-40877] fix alignment of PR link icon
  • Loading branch information
imeredith authored Mar 20, 2017
1 parent ec4d3c6 commit 7727363
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 34 deletions.
21 changes: 17 additions & 4 deletions blueocean-dashboard/src/main/js/components/RunDetailsHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ class RunDetailsHeader extends Component {
const displayName = decodeURIComponent(run.pipeline);

// Messages
const branchLabel = t('rundetail.header.branch', { defaultValue: 'Branch' });
const branchLabel = run.pullRequest ?
t('rundetail.header.pullRequest', { defaultValue: 'Pull Request' }) :
t('rundetail.header.branch', { defaultValue: 'Branch' });
const commitLabel = t('rundetail.header.commit', { defaultValue: 'Commit' });
const durationDisplayFormat = t('common.date.duration.display.format', { defaultValue: 'M[ month] d[ days] h[ hours] m[ minutes] s[ seconds]' });
const durationFormat = t('common.date.duration.format', { defaultValue: 'm[ minutes] s[ seconds]' });
Expand All @@ -91,22 +93,33 @@ class RunDetailsHeader extends Component {
);

const branchUrl = `${buildPipelineUrl(run.organization, pipeline.fullName)}/activity/${run.pipeline}`;
const labelClassName = run.pullRequest ? 'pullRequest' : '';

const branchSourceDetails = (
<div className="u-label-value" title={branchLabel + ': ' + displayName}>
<label>{ branchLabel }:</label>
<label className={labelClassName}>{ branchLabel }:</label>
{isMultiBranch ? (
<span><Link to={ branchUrl }>{ displayName }</Link></span>
<span className={labelClassName}>
<Link to={ branchUrl }>{ displayName }</Link>
</span>
) : (
<span>&mdash;</span>
)}

{ run.pullRequest && run.pullRequest.url &&
<span>
<a title="Opens pull request in a new window" target="_blank" href={run.pullRequest.url}>
<Icon size={14} icon="launch" />
</a>
</span>
}
</div>
);

const commitIdString = run.commitId || '—';
const commitSourceDetails = (
<div className="u-label-value" title={commitLabel + ': ' + commitIdString}>
<label>{ commitLabel }:</label>
<label className={labelClassName}>{ commitLabel }:</label>
<span className="commit">
{ commitIdString.substring(0, 7) }
</span>
Expand Down
19 changes: 10 additions & 9 deletions blueocean-dashboard/src/main/js/components/records.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export const ChangeSetRecord = Record({
timestamp: null,
});

export const PullRequestRecord = Record({
pullRequest: {
author: null,
id: null,
title: null,
url: null,
},
});

export class RunRecord extends Record({
_class: null,
_capabilities: [],
Expand All @@ -67,6 +76,7 @@ export class RunRecord extends Record({
commitId: null,
parameters: null,
artifactsZipFile: null,
pullRequest: PullRequestRecord,
}) {
isQueued() {
return this.state === 'QUEUED';
Expand All @@ -93,15 +103,6 @@ export class RunRecord extends Record({
}
}

export const PullRequestRecord = Record({
pullRequest: {
author: null,
id: null,
title: null,
url: null,
},
});

export const RunsRecord = Record({
_class: null,
_capabilities: [],
Expand Down
19 changes: 18 additions & 1 deletion blueocean-dashboard/src/main/less/run-details-header.less
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,30 @@
overflow: hidden;
white-space: nowrap;
}


label.pullRequest {
display: block;
width: 85px;
flex-shrink: 0;
overflow: hidden;
white-space: nowrap;
}

span {
display: block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;

svg {
display: block;
fill: #ffffff;
opacity: 50%;
margin-left: 3px;
}
}


}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
@Capability({BLUE_BRANCH, JENKINS_WORKFLOW_JOB, PULL_REQUEST})
public class BranchImpl extends PipelineImpl {

private static final String PULL_REQUEST = "pullRequest";
private static final String BRANCH = "branch";

private final Link parent;
protected final Job job;

Expand All @@ -46,25 +43,12 @@ public BranchImpl(Job job, Link parent) {
this.parent = parent;
}

@Exported(name = PULL_REQUEST, inline = true)
@Exported(name = PullRequest.PULL_REQUEST, inline = true, skipNull = true)
public PullRequest getPullRequest() {
// TODO probably want to be using SCMHeadCategory instances to categorize them instead of hard-coding for PRs
SCMHead head = SCMHead.HeadByItem.findHead(job);
if(head instanceof ChangeRequestSCMHead) {
ChangeRequestSCMHead cr = (ChangeRequestSCMHead)head;
ObjectMetadataAction om = job.getAction(ObjectMetadataAction.class);
ContributorMetadataAction cm = job.getAction(ContributorMetadataAction.class);
return new PullRequest(
cr.getId(),
om != null ? om.getObjectUrl() : null,
om != null ? om.getObjectDisplayName() : null,
cm != null ? cm.getContributor() : null
);
}
return null;
return PullRequest.get(job);
}

@Exported(name = BRANCH, inline = true)
@Exported(name = Branch.BRANCH, inline = true)
public Branch getBranch() {
ObjectMetadataAction om = job.getAction(ObjectMetadataAction.class);
PrimaryInstanceMetadataAction pima = job.getAction(PrimaryInstanceMetadataAction.class);
Expand Down Expand Up @@ -109,6 +93,8 @@ public Resource resolve(Item context, Reachable parent, Item target) {

@ExportedBean
public static class Branch {

public static final String BRANCH = "branch";
private static final String BRANCH_URL = "url";
private static final String BRANCH_PRIMARY = "isPrimary";

Expand All @@ -129,10 +115,22 @@ public String getUrl() {
public boolean isPrimary() {
return primary;
}

public static Branch getBranch(Job job) {
ObjectMetadataAction om = job.getAction(ObjectMetadataAction.class);
PrimaryInstanceMetadataAction pima = job.getAction(PrimaryInstanceMetadataAction.class);
if (om == null && pima == null) {
return null;
}
String url = om != null && om.getObjectUrl() != null ? om.getObjectUrl() : null;
return new Branch(url, pima != null);
}
}

@ExportedBean
public static class PullRequest {

public static final String PULL_REQUEST = "pullRequest";
private static final String PULL_REQUEST_NUMBER = "id";
private static final String PULL_REQUEST_AUTHOR = "author";
private static final String PULL_REQUEST_TITLE = "title";
Expand Down Expand Up @@ -175,5 +173,22 @@ public String getTitle() {
public String getAuthor() {
return author;
}

public static PullRequest get(Job job) {
// TODO probably want to be using SCMHeadCategory instances to categorize them instead of hard-coding for PRs
SCMHead head = SCMHead.HeadByItem.findHead(job);
if(head instanceof ChangeRequestSCMHead) {
ChangeRequestSCMHead cr = (ChangeRequestSCMHead)head;
ObjectMetadataAction om = job.getAction(ObjectMetadataAction.class);
ContributorMetadataAction cm = job.getAction(ContributorMetadataAction.class);
return new PullRequest(
cr.getId(),
om != null ? om.getObjectUrl() : null,
om != null ? om.getObjectDisplayName() : null,
cm != null ? cm.getContributor() : null
);
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import io.jenkins.blueocean.rest.Reachable;
import io.jenkins.blueocean.rest.annotation.Capability;
import io.jenkins.blueocean.rest.hal.Link;
import io.jenkins.blueocean.rest.impl.pipeline.BranchImpl.Branch;
import io.jenkins.blueocean.rest.impl.pipeline.BranchImpl.PullRequest;
import io.jenkins.blueocean.rest.model.BlueChangeSetEntry;
import io.jenkins.blueocean.rest.model.BluePipelineNodeContainer;
import io.jenkins.blueocean.rest.model.BluePipelineStepContainer;
Expand All @@ -27,7 +29,6 @@
import org.jenkinsci.plugins.workflow.support.steps.input.InputAction;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.export.Exported;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -49,6 +50,16 @@ public PipelineRunImpl(WorkflowRun run, Link parent) {
super(run, parent);
}

@Exported(name = Branch.BRANCH, inline = true)
public Branch getBranch() {
return Branch.getBranch(run.getParent());
}

@Exported(name = PullRequest.PULL_REQUEST, inline = true)
public PullRequest getPullRequest() {
return PullRequest.get(run.getParent());
}

@Override
public Container<BlueChangeSetEntry> getChangeSet() {
Map<String, BlueChangeSetEntry> m = new LinkedHashMap<>();
Expand Down

0 comments on commit 7727363

Please sign in to comment.