/
RunDetailsHeader.jsx
257 lines (228 loc) · 10.6 KB
/
RunDetailsHeader.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
import React, { Component, PropTypes } from 'react';
import { Icon } from '@jenkins-cd/design-language';
import { UrlConfig, AppConfig, logging, ResultPageHeader, TimeManager, UrlBuilder } from '@jenkins-cd/blueocean-core-js';
import { ExpandablePath, ReadableDate, TimeDuration, CommitId } from '@jenkins-cd/design-language';
import ChangeSetToAuthors from './ChangeSetToAuthors';
import { Link } from 'react-router';
import RunIdCell from './RunIdCell';
export class RunIdNavigation extends Component {
render() {
const { run, pipeline, branchName, t } = this.props;
const nextRunId = run._links.nextRun ? /[\/].*runs\/*([0-9]*)/g.exec(run._links.nextRun.href)[1] : '';
const prevRunId = run._links.prevRun ? /[\/].*runs\/*([0-9]*)/g.exec(run._links.prevRun.href)[1] : '';
const nextRunUrl = nextRunId ? UrlBuilder.buildRunUrl(pipeline.organization, pipeline.fullName, branchName, nextRunId, 'pipeline') : '';
const prevRunUrl = prevRunId ? UrlBuilder.buildRunUrl(pipeline.organization, pipeline.fullName, branchName, prevRunId, 'pipeline') : '';
return (
<span className="run-nav-container">
{prevRunUrl && (
<Link to={prevRunUrl} title={t('rundetail.header.prev_run', { defaultValue: 'Previous Run' })}>
<Icon size={24} icon="HardwareKeyboardArrowLeft" style={{ verticalAlign: 'bottom' }} />
</Link>
)}
<RunIdCell run={run} />
{nextRunUrl && (
<Link to={nextRunUrl} title={t('rundetail.header.next_run', { defaultValue: 'Next Run' })}>
<Icon size={24} icon="HardwareKeyboardArrowRight" style={{ verticalAlign: 'bottom' }} />
</Link>
)}
</span>
);
}
}
RunIdNavigation.propTypes = {
run: PropTypes.object,
pipeline: PropTypes.object,
branchName: PropTypes.string,
t: PropTypes.func,
};
class RunDetailsHeader extends Component {
componentWillMount() {
this._setDuration(this.props);
}
componentWillReceiveProps(nextProps) {
this._setDuration(nextProps);
}
_setDuration(props) {
const { data: run } = props;
const isRunning = () => run.isRunning() || run.isPaused() || run.isQueued();
// we need to make sure that we calculate with the correct time offset
const skewMillis = this.context.config.getServerBrowserTimeSkewMillis();
const { durationInMillis } = RunDetailsHeader.timeManager.harmonizeTimes(
{
startTime: run.startTime,
durationInMillis: run.durationInMillis,
isRunning: isRunning(),
},
skewMillis
);
this.durationInMillis = durationInMillis;
}
render() {
const { data: run, pipeline, t, locale, onCloseClick, onAuthorsClick, onOrganizationClick, topNavLinks, runButton, isMultiBranch } = this.props;
const { fullDisplayName } = pipeline;
const changeSet = run.changeSet;
const status = run.getComputedResult().toLowerCase();
const estimatedDurationInMillis = run.estimatedDurationInMillis;
const durationInMillis = run.durationInMillis; // Duration does not skew :)
// we need to make sure that we calculate with the correct time offset
const skewMillis = this.context.config.getServerBrowserTimeSkewMillis();
// the time when we started the run harmonized with offset
const isRunning = () => run.isRunning() || run.isPaused();
const { endTime, startTime } = RunDetailsHeader.timeManager.harmonizeTimes(
{
endTime: run.endTime,
startTime: run.startTime,
},
skewMillis
);
RunDetailsHeader.logger.debug('timeq:', { startTime, endTime, durationInMillis });
// pipeline name
const displayName = decodeURIComponent(run.pipeline);
// Messages
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 dateFormatShort = t('common.date.readable.short', { defaultValue: 'MMM DD h:mma Z' });
const dateFormatLong = t('common.date.readable.long', { defaultValue: 'MMM DD YYYY h:mma Z' });
const activityUrl = `${UrlBuilder.buildPipelineUrl(run.organization, pipeline.fullName)}/activity`;
// Sub-trees
const title = (
<h1 className="RunDetailsHeader-title">
{AppConfig.showOrg() && (
<span>
<a onClick={onOrganizationClick}>
{run.organization === AppConfig.getOrganizationName() ? AppConfig.getOrganizationDisplayName() : run.organization}
</a>
<span> / </span>
</span>
)}
<Link className="path-link" to={activityUrl}>
<ExpandablePath path={fullDisplayName} hideFirst className="dark-theme" iconSize={20} />
</Link>
<RunIdNavigation run={run} pipeline={pipeline} branchName={displayName} t={t} />
</h1>
);
const branchUrl = `${UrlBuilder.buildPipelineUrl(run.organization, pipeline.fullName)}/activity?branch=${run.pipeline}`;
const labelClassName = run.pullRequest ? 'pullRequest' : '';
const branchSourceDetails = (
<div className="u-label-value" title={branchLabel + ': ' + displayName}>
<label className={labelClassName}>{branchLabel}:</label>
{isMultiBranch ? (
<span className={labelClassName}>
<Link to={branchUrl}>{displayName}</Link>
{!run.pullRequest &&
run.branch &&
run.branch.url && (
<a className="inline-svg" title="Opens branch in a new window" target="_blank" href={run.branch.url}>
<Icon size={14} icon="ActionLaunch" />
</a>
)}
</span>
) : (
<span>—</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="ActionLaunch" />
</a>
</span>
)}
</div>
);
const commitIdString = run.commitId || '—';
const commitUrl = run.commitUrl || '';
const commitSourceDetails = (
<div className="u-label-value" title={commitLabel + ': ' + commitIdString}>
<label className={labelClassName}>{commitLabel}:</label>
<span className="commit">
<CommitId commitId={commitIdString} url={commitUrl} />
</span>
</div>
);
const durationDetails = (
<div>
<Icon size={16} icon="ImageTimelapse" />
<TimeDuration
millis={isRunning() ? this.durationInMillis : durationInMillis}
liveUpdate={isRunning()}
updatePeriod={1000}
locale={locale}
t={t}
/>
</div>
);
const endTimeDetails = (
<div>
<Icon size={16} icon="DeviceAccessTime" />
<ReadableDate date={endTime} liveUpdate locale={locale} shortFormat={dateFormatShort} longFormat={dateFormatLong} />
</div>
);
const cause = run => {
const lastCause = (run && run.causes.length > 0 && run.causes[run.causes.length - 1]) || null;
if (lastCause && lastCause.upstreamProject) {
const activityUrl = `${UrlConfig.getJenkinsRootURL()}/${lastCause.upstreamUrl}display/redirect?provider=blueocean`;
const runUrl = `${UrlConfig.getJenkinsRootURL()}/${lastCause.upstreamUrl}${lastCause.upstreamBuild}/display/redirect?provider=blueocean`;
return (
<div className="causes" title={lastCause.shortDescription}>
Started by upstream pipeline "<a href={activityUrl}>{lastCause.upstreamProject}</a>" build{' '}
<a href={runUrl}>#{lastCause.upstreamBuild}</a>
</div>
);
}
const causeMessage = (lastCause && lastCause.shortDescription) || null;
return (
<div className="causes" title={causeMessage}>
{causeMessage}
</div>
);
};
return (
<ResultPageHeader
startTime={startTime}
estimatedDurationInMillis={estimatedDurationInMillis}
title={title}
status={status}
onCloseClick={onCloseClick}
className="RunDetailsHeader"
topNavLinks={topNavLinks}
runButton={runButton}
t={t}
>
<div className="RunDetailsHeader-sources">
{branchSourceDetails}
{commitSourceDetails}
</div>
<div className="RunDetailsHeader-times">
{durationDetails}
{endTimeDetails}
</div>
<div className="RunDetailsHeader-messages">
<ChangeSetToAuthors changeSet={changeSet} onAuthorsClick={onAuthorsClick} t={t} />
{cause(run)}
</div>
</ResultPageHeader>
);
}
}
RunDetailsHeader.logger = logging.logger('io.jenkins.blueocean.dashboard.RunDetailsPipeline');
RunDetailsHeader.timeManager = new TimeManager();
RunDetailsHeader.propTypes = {
data: PropTypes.object.isRequired,
pipeline: PropTypes.object,
colors: PropTypes.object,
onOrganizationClick: PropTypes.func,
onAuthorsClick: PropTypes.func,
onCloseClick: PropTypes.func,
t: PropTypes.func,
locale: PropTypes.string,
topNavLinks: PropTypes.node,
runButton: PropTypes.node,
isMultiBranch: PropTypes.bool,
};
RunDetailsHeader.contextTypes = {
config: PropTypes.object.isRequired,
};
export { RunDetailsHeader };