From 3641ec4d00890f81b24301b61d689cd113e33997 Mon Sep 17 00:00:00 2001 From: Karl-Philipp Wulfert Date: Tue, 4 Jun 2019 12:17:30 +0200 Subject: [PATCH] feat: add max depth for reminders --- src/configuration.ts | 5 +++++ src/tasks/remind.ts | 17 +++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/configuration.ts b/src/configuration.ts index 8f858c5f..b74c6cd7 100644 --- a/src/configuration.ts +++ b/src/configuration.ts @@ -191,3 +191,8 @@ export const SLACK_CHANNEL = 'C762UG76Z'; * Concurrency for async pool */ export const CONCURRENCY = 3; + +/** + * Maximum depth for merge request reminders + */ +export const MAX_DEPTH_FOR_REMINDER = 2; diff --git a/src/tasks/remind.ts b/src/tasks/remind.ts index 2ee578a2..ac1dce5f 100644 --- a/src/tasks/remind.ts +++ b/src/tasks/remind.ts @@ -24,7 +24,7 @@ import { } from '@openstapps/gitlab-api/lib/types'; import {Logger} from '@openstapps/logger'; import {WebClient} from '@slack/client'; -import {CONCURRENCY, GROUPS, NOTE_PREFIX, SLACK_CHANNEL} from '../configuration'; +import {CONCURRENCY, GROUPS, MAX_DEPTH_FOR_REMINDER, NOTE_PREFIX, SLACK_CHANNEL} from '../configuration'; /** * Remind people of open merge requests @@ -33,7 +33,20 @@ import {CONCURRENCY, GROUPS, NOTE_PREFIX, SLACK_CHANNEL} from '../configuration' */ export async function remind(api: Api): Promise { // get list of open merge requests - const mergeRequests = await api.getMergeRequests(MembershipScope.GROUPS, GROUPS[0], MergeRequestState.OPENED); + const allMergeRequests = await api + .getMergeRequests(MembershipScope.GROUPS, GROUPS[0], MergeRequestState.OPENED); + + const mergeRequests = allMergeRequests.filter((mergeRequest) => { + const parts = mergeRequest.web_url.split('/'); + + // remove protocol, server name and main group + parts.splice(0, parts.indexOf('gitlab.com') + 1 + 1); + + // remove merge_requests and INDEX parts + parts.splice(parts.length - 1 - 1); + + return parts.length <= MAX_DEPTH_FOR_REMINDER; + }); Logger.info(`Found ${mergeRequests.length} open merge requests.`);