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

JENKINS-40877 PR link on run details. #894

Merged
merged 6 commits into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 14 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,12 +93,20 @@ 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>
<Link to={ branchUrl }>{ displayName }</Link>
{ run.pullRequest && run.pullRequest.url &&
<a title="Display the log in new window" target="_blank" href={run.pullRequest.url}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Display the log"??? copy paste error?

Also, can the .url be null? What is it in the case of general SCMs like git vs github?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah hadnt actually reviewed because I was having css issues and wnated help.

And yes the url can be null. Specifically if you have PR from an old version of github-branch-source it will be null

<Icon size={14} icon="launch" />
</a>
}
</span>
) : (
<span>&mdash;</span>
)}
Expand All @@ -106,7 +116,7 @@ class RunDetailsHeader extends Component {
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
16 changes: 16 additions & 0 deletions blueocean-dashboard/src/main/less/run-details-header.less
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,28 @@
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 {
fill: #ffffff;
opacity: 50%;
vertical-align: middle;
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