feat: add max depth for reminders

This commit is contained in:
Karl-Philipp Wulfert
2019-06-04 12:17:30 +02:00
parent 65a7233905
commit 3641ec4d00
2 changed files with 20 additions and 2 deletions

View File

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

View File

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