Skip to main content

Triggering Actions

Tasks gather data from analyzed files, and sometimes you want to help add emphasis to specific parts of the data. This is accomplished through the use of actions.

Actions are declarative triggers that can be attached to any task. They are ran as a post-processing step on the results of the task, and any triggered actions are stored as part of the output.

To add actions to a plugin for a task, use the following command:

npx checkup generate actions <actions name>

You'll be prompted to identify the task you want to add the actions to.

This will generate the following file:

- src/actions/actions-name.ts

Writing an Action

Actions are written in a declarative fashion, by evaluating specific values from the task results. The following is an example of a simple action that is triggered when the occurances of the task results are greater than a certain threshold:

/actions/actions-name.ts
import { ActionsEvaluator, TaskConfig } from '@checkup/core';
import { Result } from 'sarif';

export function evaluateActions(taskResults: Result[], taskConfig: TaskConfig) {
let actionsEvaluator = new ActionsEvaluator();
let occurances = taskResult.length;

actionsEvaluator.add({
taskName: 'task-name-to-run-actions-on',
name: 'task-name-bad-things',
summary: 'Reduce number of bad things',
details: `${occurances} usages of bad things`,
defaultThreshold: 2,
items: [`Total occurances: ${occurances}`],
input: occurances,
});

return actionsEvaluator.evaluate(taskConfig);
}