From 8234d2e0fee37eb35444b7afb8760472fc1371be Mon Sep 17 00:00:00 2001 From: Sampfluger88 <108141731+Sampfluger88@users.noreply.github.com> Date: Sat, 29 Jul 2023 20:18:00 -0500 Subject: [PATCH] Automate ritual as yml (#13057) Co-authored-by: Mike McNeil --- .../company/{rituals.yaml => rituals.yml} | 38 +++++--- .../create-issues-for-todays-rituals.js | 92 +++++++++++++++++++ 2 files changed, 115 insertions(+), 15 deletions(-) rename handbook/company/{rituals.yaml => rituals.yml} (76%) create mode 100644 website/scripts/create-issues-for-todays-rituals.js diff --git a/handbook/company/rituals.yaml b/handbook/company/rituals.yml similarity index 76% rename from handbook/company/rituals.yaml rename to handbook/company/rituals.yml index 4deb643bbb..df985e757a 100644 --- a/handbook/company/rituals.yaml +++ b/handbook/company/rituals.yml @@ -1,53 +1,61 @@ -- task: "Prioritize for next sprint" +- + task: "Prioritize for next sprint" startedOn: "2023-08-09" frequency: "Triweekly" description: "Drag next sprint's priorities to the top of the 'Not yet' column." # example of a longer thing: description: "[Prioritizing next sprint](https://fleetdm.com/handbook/company/communication)" dri: "sampfluger88" autoIssue: - labels: "#g-ceo" -- task: "Process the CEO's inbox" + labels: [ "#g-ceo" ] +- + task: "Process the CEO's inbox" startedOn: "2023-07-29" frequency: "Daily, 4 times" description: "TODO" dri: "sampfluger88" -- task: "Process the CEO's calendar" +- + task: "Process the CEO's calendar" startedOn: "2023-07-29" frequency: "Daily, 4 times" description: "TODO" dri: "sampfluger88" -- task: "Fleet IT warehouse management" +- + task: "Fleet IT warehouse management" startedOn: "2023-07-29" frequency: "Weekly" description: "TODO" dri: "sampfluger88" -- task: "Send weekly update" +- + task: "Send weekly update" startedOn: "2023-07-28" frequency: "Weekly" description: "TODO" dri: "sampfluger88" -- task: "Wipe e-group agenda" +- + task: "Wipe e-group agenda" startedOn: "2023-07-26" frequency: "After each weekly e-group meeting" description: "TODO" dri: "sampfluger88" -- task: "Share recording of all hands meeting" - description: "[Sharing the all hands recording](https://fleetdm.com/handbook/company/ceo#after-the-all-hands)" +- + task: "Share recording of all hands meeting" startedOn: "2023-07-xx" frequency: "After each monthly all hands meeting" - description: "TODO" + description: "[Sharing the all hands recording](https://fleetdm.com/handbook/company/ceo#after-the-all-hands)" dri: "sampfluger88" -- task: "Prepare all hands deck" - description: "[Preparing the all hands deck](https://fleetdm.com/handbook/company/ceo#prep-for-the-all-hands-call)" +- + task: "Prepare all hands deck" startedOn: "2023-07-xx" frequency: "The night (CT) before each monthly all hands meeting" - description: "TODO" + description: "[Preparing the all hands deck](https://fleetdm.com/handbook/company/ceo#prep-for-the-all-hands-call)" dri: "sampfluger88" -- task: "Prepare board deck" +- + task: "Prepare board deck" startedOn: "2023-07-29" frequency: "Two nights (CT) before the day of the mock board meeting" description: "TODO" dri: "sampfluger88" -- task: "Process CEO GitHub review requests, mentions, and outstanding PRs" +- + task: "Process CEO GitHub review requests, mentions, and outstanding PRs" startedOn: "2023-07-29" frequency: "Daily" description: "TODO" diff --git a/website/scripts/create-issues-for-todays-rituals.js b/website/scripts/create-issues-for-todays-rituals.js new file mode 100644 index 0000000000..d174e1a221 --- /dev/null +++ b/website/scripts/create-issues-for-todays-rituals.js @@ -0,0 +1,92 @@ +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); + } + + + // Validate rituals + for (let ritual of rituals) { + + let KNOWN_AUTOMATABLE_FREQUENCIES = ['Daily', 'Weekly', 'Triweekly'];//TODO: others + if (ritual.autoIssue && !KNOWN_AUTOMATABLE_FREQUENCIES.includes(ritual.frequency)) { + throw new Error(`Invalid ritual: "${ritual.task}" indicates frequency "${ritual.frequency}", but that isn't supported with automations turned on. Supported frequencies: ${KNOWN_AUTOMATABLE_FREQUENCIES}`); + } + + // TODO: validate task + // TODO: validate description + // TODO: validate DRI (github username) + // TODO: validate ritual.autoIssue + // TODO: validate ritual.autoIssue.labels + + // TODO: other validations + + }//∞ + + 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); + } + + }//∞ + }//∞ + + } + + +}; +