Skip to content

Commit

Permalink
Merge pull request #214 from uselagoon/parsed-logs-tasks
Browse files Browse the repository at this point in the history
Enables parsed logs for Tasks
  • Loading branch information
DaveDarsa authored Mar 1, 2024
2 parents 8fdb3d1 + 078f97b commit 8d61a6d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/components/LogViewer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@ import LogAccordion from 'components/LogViewer/LogAccordion';

import { StyledLogs } from './StyledLogViewer';

const LogViewer = ({ logs, status = 'NA', checkedParseState, changeState, forceLastSectionOpen = true }) => (
const LogViewer = ({
logs,
status = 'NA',
checkedParseState,
changeState,
forceLastSectionOpen = true,
logsTarget = 'Deployments',
}) => (
<React.Fragment>
<StyledLogs className="logs">
{logs !== null ? (
checkedParseState ? (
<div className="log-viewer">{logPreprocessor(logs, status, forceLastSectionOpen)}</div>
<div className="log-viewer">{logPreprocessor(logs, status, forceLastSectionOpen, logsTarget)}</div>
) : (
<div className="log-viewer with-padding">{logs}</div>
)
Expand Down Expand Up @@ -37,13 +44,13 @@ const isLogStateBad = status => {
* @param {*} status a status for the build - if not complete, we open the very last item
* @returns
*/
const logPreprocessor = (logs, status, forceLastSectionOpen = true) => {
const logPreprocessor = (logs, status, forceLastSectionOpen = true, logsTarget) => {
let ret = null;
let statusBad = isLogStateBad(status);
let openLastSection = forceLastSectionOpen || shouldLastSectionBeOpen(status);

try {
let tokens = logPreprocessorTokenize(logs);
let tokens = logPreprocessorTokenize(logs, logsTarget);
let sectionMetadata = logPreprocessorExtractSectionEndDetails(logs);
let AST = logPreprocessorProcessParse(tokens, sectionMetadata);
return logPreprocessorProcessASTToReact(AST, openLastSection, statusBad);
Expand Down Expand Up @@ -183,12 +190,11 @@ const logPreprocessorExtractSectionEndDetails = logs => {
return ret;
};

const logPreprocessorTokenize = logs => {
const logPreprocessorTokenize = (logs, logsTarget) => {
// tokenize
const regexp =
/##############################################\n(BEGIN) (.+)\n##############################################/;
const beginningSectionDefaultDetails = 'Build Setup';

const beginningSectionDefaultDetails = logsTarget === 'Deployments' ? 'Build Setup' : 'Task Setup';
// The regex above will split the logs into three separate token types
// 1. standard blocks of text
// 2. markers for section starts containing "SECTION" only
Expand Down
9 changes: 8 additions & 1 deletion src/components/Task/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,14 @@ const Task: FC<TaskProps> = ({ task, projectId, environmentId }) => {
</div>
)}
</div>
<LogViewer logs={task.logs} status={task.status} changeState={null} checkedParseState={null} />
<LogViewer
logs={task.logs}
status={task.status}
changeState={null}
checkedParseState={true}
forceLastSectionOpen={true}
logsTarget={'tasks'}
/>
</StyledTask>
);
};
Expand Down

0 comments on commit 8d61a6d

Please sign in to comment.