screwdriver-api 8.0.51 → 8.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugins/builds/steps/logs.js +109 -3
package/package.json
CHANGED
|
@@ -140,6 +140,74 @@ async function loadLines({ baseUrl, linesFrom, authToken, pagesToLoad = 10, sort
|
|
|
140
140
|
return [lines, morePages];
|
|
141
141
|
}
|
|
142
142
|
|
|
143
|
+
/**
|
|
144
|
+
* Convert unix milliseconds to ISO 8610 with timezone format
|
|
145
|
+
* @param {number} timestamp TimeStamp in unix milliseconds format
|
|
146
|
+
* @param {string} timeZone Timezone of timestamp
|
|
147
|
+
* @returns {string} Datetime in ISO 8610 with timezone format (e.g., YYYY-MM-DDThh:mm:ss.sssZ, YYYY-MM-DDThh:mm:ss.sss+09:00)
|
|
148
|
+
*/
|
|
149
|
+
function unixToFullTime(timestamp, timeZone) {
|
|
150
|
+
const date = new Date(timestamp);
|
|
151
|
+
const formatter = new Intl.DateTimeFormat('en-US', {
|
|
152
|
+
timeZone,
|
|
153
|
+
year: 'numeric',
|
|
154
|
+
month: '2-digit',
|
|
155
|
+
day: '2-digit',
|
|
156
|
+
hour: '2-digit',
|
|
157
|
+
minute: '2-digit',
|
|
158
|
+
second: '2-digit',
|
|
159
|
+
fractionalSecondDigits: 3,
|
|
160
|
+
hour12: false,
|
|
161
|
+
timeZoneName: 'longOffset'
|
|
162
|
+
});
|
|
163
|
+
const { year, day, month, hour, minute, second, fractionalSecond, timeZoneName } = Object.fromEntries(
|
|
164
|
+
formatter.formatToParts(date).map(({ type, value }) => [type, value])
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
const offsetMatch = timeZoneName.match(/GMT(.*)/)[1];
|
|
168
|
+
|
|
169
|
+
const timezoneOffset = offsetMatch === '' ? 'Z' : offsetMatch;
|
|
170
|
+
|
|
171
|
+
return `${year}-${month}-${day}T${hour}:${minute}:${second}.${fractionalSecond}${timezoneOffset}`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Convert unix milliseconds to Datetime with Timezone
|
|
176
|
+
* @param {number} timestamp TimeStamp in unix milliseconds format
|
|
177
|
+
* @param {string} timeZone Timezone of timestamp
|
|
178
|
+
* @returns {string} Datetime in hh:mm:ss format
|
|
179
|
+
*/
|
|
180
|
+
function unixToSimpleTime(timestamp, timeZone) {
|
|
181
|
+
const date = new Date(timestamp);
|
|
182
|
+
const options = {
|
|
183
|
+
timeZone,
|
|
184
|
+
hour: '2-digit',
|
|
185
|
+
minute: '2-digit',
|
|
186
|
+
second: '2-digit',
|
|
187
|
+
hour12: false
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
return date.toLocaleString(undefined, options);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* Convert to target and source unix milliseconds duration
|
|
195
|
+
* @param {number} sourceTimestamp Source timeStamp in unix milliseconds format
|
|
196
|
+
* @param {number} targetTimestamp Target timeStamp in unix milliseconds format
|
|
197
|
+
* @returns {string} Duration in hh:mm:ss format
|
|
198
|
+
*/
|
|
199
|
+
function durationTime(sourceTimestamp, targetTimestamp) {
|
|
200
|
+
const differenceInMilliSeconds = targetTimestamp - sourceTimestamp;
|
|
201
|
+
const differenceInSeconds = Math.floor(differenceInMilliSeconds / 1000);
|
|
202
|
+
const differenceInSecondsMod = differenceInSeconds % 3600;
|
|
203
|
+
|
|
204
|
+
const hours = Math.floor(differenceInSeconds / 3600);
|
|
205
|
+
const minutes = Math.floor(differenceInSecondsMod / 60);
|
|
206
|
+
const seconds = (differenceInSecondsMod % 60).toString().padStart(2, '0');
|
|
207
|
+
|
|
208
|
+
return `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
|
|
209
|
+
}
|
|
210
|
+
|
|
143
211
|
module.exports = config => ({
|
|
144
212
|
method: 'GET',
|
|
145
213
|
path: '/builds/{id}/steps/{name}/logs',
|
|
@@ -158,6 +226,7 @@ module.exports = config => ({
|
|
|
158
226
|
const { stepFactory, buildFactory, eventFactory } = req.server.app;
|
|
159
227
|
const buildId = req.params.id;
|
|
160
228
|
const stepName = req.params.name;
|
|
229
|
+
let buildModel;
|
|
161
230
|
|
|
162
231
|
return buildFactory
|
|
163
232
|
.get(buildId)
|
|
@@ -165,6 +234,7 @@ module.exports = config => ({
|
|
|
165
234
|
if (!build) {
|
|
166
235
|
throw boom.notFound('Build does not exist');
|
|
167
236
|
}
|
|
237
|
+
buildModel = build;
|
|
168
238
|
|
|
169
239
|
return eventFactory.get(build.eventId);
|
|
170
240
|
})
|
|
@@ -203,7 +273,9 @@ module.exports = config => ({
|
|
|
203
273
|
jwtid: uuidv4()
|
|
204
274
|
}
|
|
205
275
|
);
|
|
206
|
-
|
|
276
|
+
|
|
277
|
+
const { sort, type, timestamp, timezone, timestampFormat } = req.query;
|
|
278
|
+
|
|
207
279
|
let pagesToLoad = req.query.pages;
|
|
208
280
|
let linesFrom = req.query.from;
|
|
209
281
|
|
|
@@ -231,8 +303,42 @@ module.exports = config => ({
|
|
|
231
303
|
|
|
232
304
|
let res = '';
|
|
233
305
|
|
|
234
|
-
|
|
235
|
-
|
|
306
|
+
if (timestamp) {
|
|
307
|
+
const buildTime = new Date(buildModel.startTime).getTime();
|
|
308
|
+
const stepTime = new Date(stepModel.startTime).getTime();
|
|
309
|
+
|
|
310
|
+
switch (timestampFormat) {
|
|
311
|
+
case 'full-time':
|
|
312
|
+
for (const line of lines) {
|
|
313
|
+
res += `${unixToFullTime(line.t, timezone)}\t${line.m}\n`;
|
|
314
|
+
}
|
|
315
|
+
break;
|
|
316
|
+
case 'simple-time':
|
|
317
|
+
for (const line of lines) {
|
|
318
|
+
res += `${unixToSimpleTime(line.t, timezone)}\t${line.m}\n`;
|
|
319
|
+
}
|
|
320
|
+
break;
|
|
321
|
+
case 'elapsed-build':
|
|
322
|
+
for (const line of lines) {
|
|
323
|
+
const duration = durationTime(buildTime, line.t);
|
|
324
|
+
|
|
325
|
+
res += `${duration}\t${line.m}\n`;
|
|
326
|
+
}
|
|
327
|
+
break;
|
|
328
|
+
case 'elapsed-step':
|
|
329
|
+
for (const line of lines) {
|
|
330
|
+
const duration = durationTime(stepTime, line.t);
|
|
331
|
+
|
|
332
|
+
res += `${duration}\t${line.m}\n`;
|
|
333
|
+
}
|
|
334
|
+
break;
|
|
335
|
+
default:
|
|
336
|
+
throw boom.badRequest('Unexpected timestampFormat parameter');
|
|
337
|
+
}
|
|
338
|
+
} else {
|
|
339
|
+
for (const line of lines) {
|
|
340
|
+
res += `${line.m}\n`;
|
|
341
|
+
}
|
|
236
342
|
}
|
|
237
343
|
|
|
238
344
|
return h
|