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 {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`,
);
);
}
}
});