Skip to content

Commit

Permalink
feat(ci): ci-keep-alive message
Browse files Browse the repository at this point in the history
- Increase interval to 4m30s
- Include tasks to the log
  • Loading branch information
AriPerkkio committed Nov 17, 2020
1 parent 25609ea commit 35c79c6
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/progress-logger/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default } from './progress-logger';
export { default, resolveColor } from './progress-logger';
export * from './log-templates';
13 changes: 11 additions & 2 deletions lib/progress-logger/log-templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ import { Task } from './types';
import config from '@config';
import { CACHE_LOCATION } from '@file-client';

// Regexp for converting `[INFO][LINTING] reponame` to `[INFO/LINTING] reponame`
const CI_TEMPLATE_TASK_REGEXP = /\]\[/;

export const TASK_TEMPLATE = (task: Task): string => {
switch (task.step) {
case 'START':
Expand Down Expand Up @@ -33,8 +36,14 @@ export const REPOSITORIES_STATUS_TEMPLATE = (
): string =>
`Repositories (${scannedRepositories}/${config.repositories.length})`;

export const CI_STATUS_TEMPLATE = (scannedRepositories: number): string =>
`[INFO] ${REPOSITORIES_STATUS_TEMPLATE(scannedRepositories)}\n`;
export const CI_STATUS_TEMPLATE = (
scannedRepositories: number,
tasks: Task[]
): string => `[INFO/STATUS] ${REPOSITORIES_STATUS_TEMPLATE(scannedRepositories)}
${tasks.map(task => CI_TASK_TEMPLATE(task)).join('\n')}\n`;

const CI_TASK_TEMPLATE = (task: Task): string =>
`[INFO]${TASK_TEMPLATE(task)}`.replace(CI_TEMPLATE_TASK_REGEXP, '/');

export const LINT_END_TEMPLATE = (
repository: string,
Expand Down
19 changes: 17 additions & 2 deletions lib/progress-logger/progress-logger.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import chalk from 'chalk';

import * as Templates from './log-templates';
import { LogMessage, Task, Listeners, Listener, ListenerType } from './types';
import config from '@config';

const CI_KEEP_ALIVE_INTERVAL_MS = 15 * 1000;
const CI_KEEP_ALIVE_INTERVAL_MS = 4.5 * 60 * 1000;
const DEFAULT_COLOR = (text: string) => text;

/**
* Resolve color for message or task
*/
export function resolveColor(
taskOrMessage: Task | LogMessage
): typeof DEFAULT_COLOR {
return (taskOrMessage.color && chalk[taskOrMessage.color]) || DEFAULT_COLOR;
}

/**
* Logger for holding state of current progress
Expand Down Expand Up @@ -305,7 +317,10 @@ class ProgressLogger {
* Log status of scanning to CI
*/
onCiStatus() {
const message = Templates.CI_STATUS_TEMPLATE(this.scannedRepositories);
const message = Templates.CI_STATUS_TEMPLATE(
this.scannedRepositories,
this.tasks
);

this.listeners.ciKeepAlive.forEach(listener => listener(message));
}
Expand Down
9 changes: 1 addition & 8 deletions lib/ui/components/AppCI.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import React, { useLayoutEffect } from 'react';
import { useStdout } from 'ink';
import chalk from 'chalk';

import Results from './Results';
import { useOnExit } from '../hooks';
import ProgressLogger, { TASK_TEMPLATE } from '@progress-logger';
import ProgressLogger, { resolveColor, TASK_TEMPLATE } from '@progress-logger';
import { LogMessage, Task } from '@progress-logger/types';

const DEFAULT_COLOR = (text: string) => text;

function resolveColor(taskOrMessage: Task | LogMessage) {
return (taskOrMessage.color && chalk[taskOrMessage.color]) || DEFAULT_COLOR;
}

/**
* Application for CIs
* - Message and task updates are rendered directly to stdout due to ink not
Expand Down

0 comments on commit 35c79c6

Please sign in to comment.