summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorKushal Pandya <kushalspandya@gmail.com>2019-09-03 12:28:18 +0000
committerKushal Pandya <kushalspandya@gmail.com>2019-09-03 12:28:18 +0000
commitf3b9ddb11bd28952eeb9ce544e9bf8014d42a923 (patch)
treee81848f17f17022f1359d20c2c37aa731d26feb6 /app
parentb07bfbcdf616864be7d41ef3f582082f860286ae (diff)
parent876ae19d9efac7675ae60bf75d792e308e4d6ad2 (diff)
downloadgitlab-ce-f3b9ddb11bd28952eeb9ce544e9bf8014d42a923.tar.gz
Merge branch '66454-utils-parser' into 'master'
Creates utility parser for the job log See merge request gitlab-org/gitlab-ce!32555
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/jobs/store/utils.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/app/assets/javascripts/jobs/store/utils.js b/app/assets/javascripts/jobs/store/utils.js
new file mode 100644
index 00000000000..de7de92ed2e
--- /dev/null
+++ b/app/assets/javascripts/jobs/store/utils.js
@@ -0,0 +1,40 @@
+/**
+ * Parses the job log content into a structure usable by the template
+ *
+ * For collaspible lines (section_header = true):
+ * - creates a new array to hold the lines that are collpasible,
+ * - adds a isClosed property to handle toggle
+ * - adds a isHeader property to handle template logic
+ * For each line:
+ * - adds the index as lineNumber
+ *
+ * @param {Array} lines
+ * @returns {Array}
+ */
+export default (lines = []) =>
+ lines.reduce((acc, line, index) => {
+ if (line.section_header) {
+ acc.push({
+ isClosed: true,
+ isHeader: true,
+ line: {
+ ...line,
+ lineNumber: index,
+ },
+
+ lines: [],
+ });
+ } else if (acc.length && acc[acc.length - 1].isHeader) {
+ acc[acc.length - 1].lines.push({
+ ...line,
+ lineNumber: index,
+ });
+ } else {
+ acc.push({
+ ...line,
+ lineNumber: index,
+ });
+ }
+
+ return acc;
+ }, []);