summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/jobs/store
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-01 15:06:05 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-01 15:06:05 +0000
commit05f4b2fb34dbb051b2ce5ddbc801ec42998c019c (patch)
tree0fd7a153f3ed7d00d40e428c08ab81ae3d863afe /app/assets/javascripts/jobs/store
parent9e27f0d920cc3891fa7644c5cc0bc280c519fb20 (diff)
downloadgitlab-ce-05f4b2fb34dbb051b2ce5ddbc801ec42998c019c.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/assets/javascripts/jobs/store')
-rw-r--r--app/assets/javascripts/jobs/store/mutations.js4
-rw-r--r--app/assets/javascripts/jobs/store/state.js1
-rw-r--r--app/assets/javascripts/jobs/store/utils.js106
3 files changed, 54 insertions, 57 deletions
diff --git a/app/assets/javascripts/jobs/store/mutations.js b/app/assets/javascripts/jobs/store/mutations.js
index 540c3e2ad69..412ae146ca0 100644
--- a/app/assets/javascripts/jobs/store/mutations.js
+++ b/app/assets/javascripts/jobs/store/mutations.js
@@ -26,8 +26,7 @@ export default {
if (log.append) {
if (isNewJobLogActive()) {
- state.originalTrace = state.originalTrace.concat(log.trace);
- state.trace = updateIncrementalTrace(state.originalTrace, state.trace, log.lines);
+ state.trace = updateIncrementalTrace(log.lines, state.trace);
} else {
state.trace += log.html;
}
@@ -38,7 +37,6 @@ export default {
// html or size. We keep the old value otherwise these
// will be set to `undefined`
if (isNewJobLogActive()) {
- state.originalTrace = log.lines || state.trace;
state.trace = logLinesParser(log.lines) || state.trace;
} else {
state.trace = log.html || state.trace;
diff --git a/app/assets/javascripts/jobs/store/state.js b/app/assets/javascripts/jobs/store/state.js
index 585878f8240..cdc1780f3d6 100644
--- a/app/assets/javascripts/jobs/store/state.js
+++ b/app/assets/javascripts/jobs/store/state.js
@@ -19,7 +19,6 @@ export default () => ({
isScrolledToBottomBeforeReceivingTrace: true,
trace: isNewJobLogActive() ? [] : '',
- originalTrace: [],
isTraceComplete: false,
traceSize: 0,
isTraceSizeVisible: false,
diff --git a/app/assets/javascripts/jobs/store/utils.js b/app/assets/javascripts/jobs/store/utils.js
index 4a7d870674b..12069e0c123 100644
--- a/app/assets/javascripts/jobs/store/utils.js
+++ b/app/assets/javascripts/jobs/store/utils.js
@@ -64,6 +64,30 @@ export const isCollapsibleSection = (acc = [], last = {}, section = {}) =>
section.section === last.line.section;
/**
+ * Returns the lineNumber of the last line in
+ * a parsed log
+ *
+ * @param Array acc
+ * @returns Number
+ */
+export const getIncrementalLineNumber = acc => {
+ let lineNumberValue;
+ const lastIndex = acc.length - 1;
+ const lastElement = acc[lastIndex];
+ const nestedLines = lastElement.lines;
+
+ if (lastElement.isHeader && !nestedLines.length && lastElement.line) {
+ lineNumberValue = lastElement.line.lineNumber;
+ } else if (lastElement.isHeader && nestedLines.length) {
+ lineNumberValue = nestedLines[nestedLines.length - 1].lineNumber;
+ } else {
+ lineNumberValue = lastElement.lineNumber;
+ }
+
+ return lineNumberValue === 0 ? 1 : lineNumberValue + 1;
+};
+
+/**
* Parses the job log content into a structure usable by the template
*
* For collaspible lines (section_header = true):
@@ -75,32 +99,35 @@ export const isCollapsibleSection = (acc = [], last = {}, section = {}) =>
* - adds the index as lineNumber
*
* @param Array lines
- * @param Number lineNumberStart
* @param Array accumulator
* @returns Array parsed log lines
*/
-export const logLinesParser = (lines = [], lineNumberStart, accumulator = []) =>
- lines.reduce((acc, line, index) => {
- const lineNumber = lineNumberStart ? lineNumberStart + index : index;
- const last = acc[acc.length - 1];
-
- // If the object is an header, we parse it into another structure
- if (line.section_header) {
- acc.push(parseHeaderLine(line, lineNumber));
- } else if (isCollapsibleSection(acc, last, line)) {
- // if the object belongs to a nested section, we append it to the new `lines` array of the
- // previously formated header
- last.lines.push(parseLine(line, lineNumber));
- } else if (line.section_duration) {
- // if the line has section_duration, we look for the correct header to add it
- addDurationToHeader(acc, line);
- } else {
- // otherwise it's a regular line
- acc.push(parseLine(line, lineNumber));
- }
+export const logLinesParser = (lines = [], accumulator = []) =>
+ lines.reduce(
+ (acc, line, index) => {
+ const lineNumber = accumulator.length > 0 ? getIncrementalLineNumber(acc) : index;
+
+ const last = acc[acc.length - 1];
+
+ // If the object is an header, we parse it into another structure
+ if (line.section_header) {
+ acc.push(parseHeaderLine(line, lineNumber));
+ } else if (isCollapsibleSection(acc, last, line)) {
+ // if the object belongs to a nested section, we append it to the new `lines` array of the
+ // previously formated header
+ last.lines.push(parseLine(line, lineNumber));
+ } else if (line.section_duration) {
+ // if the line has section_duration, we look for the correct header to add it
+ addDurationToHeader(acc, line);
+ } else {
+ // otherwise it's a regular line
+ acc.push(parseLine(line, lineNumber));
+ }
- return acc;
- }, accumulator);
+ return acc;
+ },
+ [...accumulator],
+ );
/**
* Finds the repeated offset, removes the old one
@@ -113,7 +140,7 @@ export const logLinesParser = (lines = [], lineNumberStart, accumulator = []) =>
* @returns Array
*
*/
-export const findOffsetAndRemove = (newLog, oldParsed) => {
+export const findOffsetAndRemove = (newLog = [], oldParsed = []) => {
const cloneOldLog = [...oldParsed];
const lastIndex = cloneOldLog.length - 1;
const last = cloneOldLog[lastIndex];
@@ -140,40 +167,13 @@ export const findOffsetAndRemove = (newLog, oldParsed) => {
* We need to check if that is the case by looking for the offset property
* before parsing the incremental part
*
- * @param array originalTrace
* @param array oldLog
* @param array newLog
*/
-export const updateIncrementalTrace = (originalTrace = [], oldLog = [], newLog = []) => {
- const firstLine = newLog[0];
- const firstLineOffset = firstLine.offset;
+export const updateIncrementalTrace = (newLog, oldParsed = []) => {
+ const parsedLog = findOffsetAndRemove(newLog, oldParsed);
- // We are going to return a new array,
- // let's make a shallow copy to make sure we
- // are not updating the state outside of a mutation first.
- const cloneOldLog = [...oldLog];
-
- const lastIndex = cloneOldLog.length - 1;
- const lastLine = cloneOldLog[lastIndex];
-
- // The last line may be inside a collpasible section
- // If it is, we use the not parsed saved log, remove the last element
- // and parse the first received part togheter with the incremental log
- if (
- lastLine.isHeader &&
- (lastLine.line.offset === firstLineOffset ||
- (lastLine.lines.length &&
- lastLine.lines[lastLine.lines.length - 1].offset === firstLineOffset))
- ) {
- const cloneOriginal = [...originalTrace];
- cloneOriginal.splice(cloneOriginal.length - 1);
- return logLinesParser(cloneOriginal.concat(newLog));
- } else if (lastLine.offset === firstLineOffset) {
- cloneOldLog.splice(lastIndex);
- return cloneOldLog.concat(logLinesParser(newLog, cloneOldLog.length));
- }
- // there are no matches, let's parse the new log and return them together
- return cloneOldLog.concat(logLinesParser(newLog, cloneOldLog.length));
+ return logLinesParser(newLog, parsedLog);
};
export const isNewJobLogActive = () => gon && gon.features && gon.features.jobLogJson;