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
- Yarn
npx checkup generate actions <actions name>
yarn 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:
- TypeScript project
- JavaScript project
- src/actions/actions-name.ts
- src/actions/actions-name.js
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:
- TypeScript
- JavaScript
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);
}
const { ActionsEvaluator } = require('@checkup/core');
module.exports = function evaluateActions(taskResults, 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);
};