fleet/website/scripts/create-issues-for-todays-rituals.js
Eric 3e1936d9c7
Website: add <rituals> component, add ritualsTables (parsed from YAML) to website configuration (#13084)
Changes:
- Updated the `build-static-content` script to parse files named
`rituals.yml` in the handbook folder, and add the contents to the
website's configuration as
`sails.config.builtStaticContent.ritualsTables`, and to throw errors if
a `rituals.yml` file contains a ritual that is missing a required value.
- Created the `<rituals>` component, a component that takes a single
prop (`ritualsTable`) and renders a table containing a row for each
ritual.
- Added a new property to `handbook/company/rituals.yml` - moreInfoUrl.
If this value is present, the description in the rendered HTML table (of
the `<rituals>` component) will link to the URL provided.
- updated view-basic-handbook to send
`sails.config.builtStaticContent.ritualsTables` in `SAILS_LOCALS`

---------

Co-authored-by: Sampfluger88 <[email protected]>
2023-08-03 21:58:02 -05:00

75 lines
2.1 KiB
JavaScript
Vendored

module.exports = {
friendlyName: 'Create issues for todays rituals',
description: '',
inputs: {
dry: { type: 'boolean', defaultsTo: false, description: 'Whether to do a dry run instead.' },
},
fn: async function ({ dry }) {
let path = require('path');
let YAML = require('yaml');
let topLvlRepoPath = path.resolve(sails.config.appPath, '../');
let baseHeaders = {// (for github api)
'User-Agent': 'Fleetie pie',
'Authorization': `token ${sails.config.custom.githubAccessToken}`
};
let ritualSources = [
{ path: 'handbook/company/rituals.yml', },
];
for (let ritualSource of ritualSources) {
// Load rituals
let pathToRituals = path.resolve(topLvlRepoPath, ritualSource.path);
let rituals = [];
let ritualsYml = await sails.helpers.fs.read(pathToRituals);
try {
rituals = YAML.parse(ritualsYml, { prettyErrors: true });
} catch (err) {
throw new Error(`Could not parse the YAMl for rituals at ${pathToRituals} on line ${err.linePos.start.line}. To resolve, make sure the YAML is valid, and try again: ` + err.stack);
}
for (let ritual of rituals) {
if (!ritual.autoIssue) {// « Skip to the next ritual if automations aren't enabled.
continue;
}
// Skip to the next ritual if it isn't time yet.
if (false) {// TODO
continue;
}
// Create an issue with right labels and assignee, in the right repo.
if (!dry) {
let owner = 'fleetdm';
let repo = 'fleet';// TODO: support confidential and classified also
// [?] https://docs.github.com/en/rest/issues/issues#create-an-issue
await sails.helpers.http.post(`https://api.github.com/repos/${owner}/${repo}/issues`, {
title: ritual.task,
body: ritual.description,
labels: ritual.autoIssue.labels,
assignees: [ ritual.dri ]
}, baseHeaders);
} else {
sails.log('Dry run: Would have created an issue for ritual:', ritual);
}
}//∞
}//∞
}
};