Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enables parsed logs for Tasks #214

Merged
merged 6 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading