refactor: migrate @krlwlfrt/async-pool to @openstapps/collection-utils

This commit is contained in:
2023-06-29 17:29:49 +02:00
parent 64caebafe5
commit 98546a97a3
58 changed files with 621 additions and 1175 deletions

View File

@@ -23,14 +23,15 @@ import {
} from '@openstapps/gitlab-api';
import {Logger} from '@openstapps/logger';
import {WebClient} from '@slack/web-api';
import {GROUPS, MAX_DEPTH_FOR_REMINDER, NOTE_PREFIX, SLACK_CHANNEL} from '../configuration.js';
import {CONCURRENCY, GROUPS, MAX_DEPTH_FOR_REMINDER, NOTE_PREFIX, SLACK_CHANNEL} from '../configuration.js';
import {mapAsyncLimit} from '@openstapps/collection-utils';
/**
* Remind people of open merge requests
* @param api GitLab API to make requests with
*/
export async function remind(api: Api): Promise<void> {
// get list of open merge requests
// get a list of open merge requests
const allMergeRequests = await api.getMergeRequests(
MembershipScope.GROUPS,
GROUPS[0],
@@ -55,7 +56,7 @@ export async function remind(api: Api): Promise<void> {
const client =
process.env.SLACK_API_TOKEN === undefined ? undefined : new WebClient(process.env.SLACK_API_TOKEN);
// get members of main group
// get members of the main group
const members = await api.getMembers(MembershipScope.GROUPS, GROUPS[0]);
// filter members with at least maintainer status
@@ -71,8 +72,9 @@ export async function remind(api: Api): Promise<void> {
Logger.info(`Found ${maintainers.length} maintainer(s).`);
await Promise.all(
mergeRequests.map(async mergeRequest => {
await mapAsyncLimit(
mergeRequests,
async mergeRequest => {
// check if merge request is WIP
if (mergeRequest.work_in_progress) {
Logger.info(`Merge request '${mergeRequest.title}' is WIP.`);
@@ -118,7 +120,7 @@ export async function remind(api: Api): Promise<void> {
// get possible appropers, prefixed with '@' and joined with commas
const possibleApprovers = maintainerUsernames
.filter(username => {
if (mergeRequest.assignee.username === username) {
if (mergeRequest!.assignee.username === username) {
return false;
}
if (username.includes('openstapps') || username.includes('kphilipp')) {
@@ -168,7 +170,7 @@ export async function remind(api: Api): Promise<void> {
// prefix maintainers with '@' and join with commas
const possibleMergers = maintainerUsernames
.filter(username => {
return mergeRequest.assignee.username !== username;
return mergeRequest!.assignee.username !== username;
})
.map(username => `@${username}`)
.join(', ');
@@ -182,6 +184,7 @@ export async function remind(api: Api): Promise<void> {
);
}
}
}),
},
CONCURRENCY,
);
}