From d7b68ae45c8321f0a1d9cba998b604507445f9fb Mon Sep 17 00:00:00 2001 From: Karl-Philipp Wulfert Date: Tue, 20 Aug 2019 10:18:01 +0200 Subject: [PATCH] feat: only unlabel closed issues before last meeting --- src/tasks/unlabel.ts | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/tasks/unlabel.ts b/src/tasks/unlabel.ts index 7af900df..9ecc36da 100644 --- a/src/tasks/unlabel.ts +++ b/src/tasks/unlabel.ts @@ -16,6 +16,7 @@ import {asyncPool} from '@krlwlfrt/async-pool'; import {Api} from '@openstapps/gitlab-api'; 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'; @@ -36,17 +37,31 @@ export async function unlabel(api: Api) { Logger.log(`Fetched ${issues.length} closed issue(s).`); - await asyncPool(CONCURRENCY, issues, async (issue) => { - if (issue.labels.indexOf('meeting') >= 0) { - Logger.info(`Issue ${issue.title} is closed and has label "meeting". Removing it.`); + const thisWeeksWednesday = moment() + .startOf('week') + // tslint:disable-next-line:no-magic-numbers + .hour(10) + // tslint:disable-next-line:no-magic-numbers + .day(3); - await api.createNote( - issue.project_id, - Scope.ISSUES, - issue.iid, - `${NOTE_PREFIX} Removed label \`meeting\` automatically. + 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)) { + Logger.info(`Issue ${issue.title} is closed before last meeting and has label "meeting". Removing it.`); + + await api.createNote( + issue.project_id, + Scope.ISSUES, + issue.iid, + `${NOTE_PREFIX} Removed label \`meeting\` automatically. /unlabel ~meeting`, - ); + ); + } } });