feat: update to new meeting date

This commit is contained in:
Karl-Philipp Wulfert
2019-11-13 15:02:12 +01:00
parent b1c019bece
commit 98c73b5758
4 changed files with 39 additions and 36 deletions

View File

@@ -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();
}

View File

@@ -13,6 +13,7 @@
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
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');

View File

@@ -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)...`);

View File

@@ -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(