feat: only unlabel closed issues before last meeting

This commit is contained in:
Karl-Philipp Wulfert
2019-08-20 10:18:01 +02:00
parent 78e71910f4
commit d7b68ae45c

View File

@@ -16,6 +16,7 @@ import {asyncPool} from '@krlwlfrt/async-pool';
import {Api} from '@openstapps/gitlab-api'; import {Api} from '@openstapps/gitlab-api';
import {IssueState, Scope} from '@openstapps/gitlab-api/lib/types'; import {IssueState, Scope} from '@openstapps/gitlab-api/lib/types';
import {Logger} from '@openstapps/logger'; import {Logger} from '@openstapps/logger';
import * as moment from 'moment';
import {flatten2dArray} from '../common'; import {flatten2dArray} from '../common';
import {CONCURRENCY, GROUPS, NOTE_PREFIX} from '../configuration'; import {CONCURRENCY, GROUPS, NOTE_PREFIX} from '../configuration';
@@ -36,9 +37,22 @@ export async function unlabel(api: Api) {
Logger.log(`Fetched ${issues.length} closed issue(s).`); 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) => { await asyncPool(CONCURRENCY, issues, async (issue) => {
if (issue.labels.indexOf('meeting') >= 0) { if (issue.labels.indexOf('meeting') >= 0 && issue.closed_at !== null) {
Logger.info(`Issue ${issue.title} is closed and has label "meeting". Removing it.`);
if (moment(issue.closed_at)
.isBefore(lastWeeksWednesday)) {
Logger.info(`Issue ${issue.title} is closed before last meeting and has label "meeting". Removing it.`);
await api.createNote( await api.createNote(
issue.project_id, issue.project_id,
@@ -48,6 +62,7 @@ export async function unlabel(api: Api) {
/unlabel ~meeting`, /unlabel ~meeting`,
); );
} }
}
}); });
Logger.ok('Label `meeting` has been removed from closed issues.'); Logger.ok('Label `meeting` has been removed from closed issues.');