From 98c73b575846fb342c4ffb6a2cf09152a3205f95 Mon Sep 17 00:00:00 2001 From: Karl-Philipp Wulfert Date: Wed, 13 Nov 2019 15:02:12 +0100 Subject: [PATCH] feat: update to new meeting date --- src/cli.ts | 20 ++++++++++++++------ src/configuration.ts | 21 +++++++++++++++++++++ src/tasks/report.ts | 20 ++------------------ src/tasks/unlabel.ts | 14 ++------------ 4 files changed, 39 insertions(+), 36 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index 3d6cbf9c..bae12e2d 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -27,8 +27,20 @@ import {tidy} from './tasks/tidy'; import {unlabel} from './tasks/unlabel'; // add default handler for unhandled rejections -process.on('unhandledRejection', async (err) => { - await Logger.error('UNHANDLED REJECTION', err.stack); +process.on('unhandledRejection', async (reason) => { + if (reason instanceof Error) { + await Logger.error('Unhandled rejection', reason.stack); + } else { + await Logger.error('Unhandled rejection', reason); + } + + process.exit(1); +}); + +// error on unknown commands +commander.on('command:*', async () => { + await Logger.error('Invalid command: %s\nSee --help for a list of available commands.', commander.args.join(' ')); + process.exit(1); }); @@ -78,7 +90,3 @@ commander commander .parse(process.argv); - -if (commander.args.length < 1) { - commander.help(); -} diff --git a/src/configuration.ts b/src/configuration.ts index b74c6cd7..908a391d 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -13,6 +13,7 @@ * this program. If not, see . */ import {Label} from '@openstapps/gitlab-api/lib/types'; +import * as moment from 'moment'; /** * List of schools with their IDs @@ -196,3 +197,23 @@ export const CONCURRENCY = 3; * Maximum depth for merge request reminders */ export const MAX_DEPTH_FOR_REMINDER = 2; + +/** + * Next meeting + */ +export const NEXT_MEETING = moment() + .startOf('week') + // tslint:disable-next-line:no-magic-numbers + .hour(15) + // tslint:disable-next-line:no-magic-numbers + .day(2); + +if (NEXT_MEETING.isBefore(moment())) { + NEXT_MEETING.add(1, 'week'); +} + +/** + * Last meeting + */ +export const LAST_MEETING = moment(NEXT_MEETING) + .subtract(1, 'week'); diff --git a/src/tasks/report.ts b/src/tasks/report.ts index 5455b986..d1a27a1a 100644 --- a/src/tasks/report.ts +++ b/src/tasks/report.ts @@ -21,7 +21,7 @@ import {render} from 'mustache'; import {join, resolve} from 'path'; import {cwd} from 'process'; import {flatten2dArray, getProjects, readFilePromisified, writeFilePromisified} from '../common'; -import {BOLD_LABELS, CONCURRENCY, GROUPS, LABEL_WEIGHTS} from '../configuration'; +import {BOLD_LABELS, CONCURRENCY, GROUPS, LABEL_WEIGHTS, NEXT_MEETING} from '../configuration'; /** * A structure for template compilation @@ -358,23 +358,7 @@ export async function getIssuesGroupedByAssignees(api: Api, label: string): Prom * Get next meeting day */ export function getNextMeetingDay() { - // get "now" - const now = moment(); - - // get first wednesday of month - const meetingDayMoment = moment() - .startOf('month') - // tslint:disable-next-line:no-magic-numbers - .hour(10) - // tslint:disable-next-line:no-magic-numbers - .isoWeekday(3); - - while (meetingDayMoment.isBefore(now)) { - // add one week until meeting day is after now - meetingDayMoment.add(1, 'weeks'); - } - - const meetingDay = meetingDayMoment.format('YYYY-MM-DD'); + const meetingDay = NEXT_MEETING.format('YYYY-MM-DD'); // log found meeting day Logger.info(`Generating report for '${meetingDay}' of '${GROUPS.length}' group(s)...`); diff --git a/src/tasks/unlabel.ts b/src/tasks/unlabel.ts index 9ecc36da..c449a5a8 100644 --- a/src/tasks/unlabel.ts +++ b/src/tasks/unlabel.ts @@ -18,7 +18,7 @@ import {IssueState, Scope} from '@openstapps/gitlab-api/lib/types'; import {Logger} from '@openstapps/logger'; import * as moment from 'moment'; import {flatten2dArray} from '../common'; -import {CONCURRENCY, GROUPS, NOTE_PREFIX} from '../configuration'; +import {CONCURRENCY, GROUPS, LAST_MEETING, NOTE_PREFIX} from '../configuration'; /** * Remove label `meeting` from closed issues @@ -37,21 +37,11 @@ export async function unlabel(api: Api) { Logger.log(`Fetched ${issues.length} closed issue(s).`); - const thisWeeksWednesday = moment() - .startOf('week') - // tslint:disable-next-line:no-magic-numbers - .hour(10) - // tslint:disable-next-line:no-magic-numbers - .day(3); - - const lastWeeksWednesday = moment(thisWeeksWednesday) - .subtract(1, 'week'); - await asyncPool(CONCURRENCY, issues, async (issue) => { if (issue.labels.indexOf('meeting') >= 0 && issue.closed_at !== null) { if (moment(issue.closed_at) - .isBefore(lastWeeksWednesday)) { + .isBefore(LAST_MEETING)) { Logger.info(`Issue ${issue.title} is closed before last meeting and has label "meeting". Removing it.`); await api.createNote(