mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-07 05:52:57 +00:00
feat: add merge request assignment
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
import {asyncPool} from '@krlwlfrt/async-pool';
|
||||
import {Api} from '@openstapps/gitlab-api';
|
||||
import {AccessLevel, IssueState, MembershipScope, Milestone, Project, Scope} from '@openstapps/gitlab-api/lib/types';
|
||||
import {AccessLevel, IssueState, MembershipScope, MergeRequestState, Milestone, Project, Scope} from '@openstapps/gitlab-api/lib/types';
|
||||
import {Logger} from '@openstapps/logger';
|
||||
import {flatten2dArray, getProjects} from '../common';
|
||||
import {
|
||||
@@ -360,6 +360,47 @@ export async function tidyIssuesWithoutAssignee(api: Api): Promise<void> {
|
||||
Logger.ok('Tidied issues without assignee.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tidy merge requests without assignee
|
||||
*
|
||||
* Set assignee to author if no assignee is set.
|
||||
*
|
||||
* @param api GitLab API instance to use for the requests
|
||||
*/
|
||||
export async function tidyMergeRequestsWithoutAssignee(api: Api): Promise<void> {
|
||||
const mergeRequestResults = await asyncPool(CONCURRENCY, GROUPS, async (groupId) => {
|
||||
return api.getMergeRequests(
|
||||
MembershipScope.GROUPS,
|
||||
groupId,
|
||||
MergeRequestState.OPENED,
|
||||
);
|
||||
});
|
||||
|
||||
// flatten structure, e.g. put all issues in one array
|
||||
const mergeRequests = flatten2dArray(mergeRequestResults);
|
||||
|
||||
const mergeRequestsWithoutAssignee = mergeRequests.filter((mergeRequest) => {
|
||||
return mergeRequest.assignee === null;
|
||||
});
|
||||
|
||||
Logger.info(`Found '${mergeRequestsWithoutAssignee.length}' merge requests without assignee.`);
|
||||
|
||||
await asyncPool(CONCURRENCY, mergeRequestsWithoutAssignee, async (mergeRequest) => {
|
||||
await api.setAssigneeForMergeRequest(mergeRequest, mergeRequest.author.id);
|
||||
|
||||
Logger.log(`Set assignee for '${mergeRequest.title}' to '${mergeRequest.author.name}'.`);
|
||||
|
||||
await api.createNote(
|
||||
mergeRequest.project_id,
|
||||
Scope.MERGE_REQUESTS,
|
||||
mergeRequest.iid,
|
||||
`${NOTE_PREFIX} Assignee was set automatically to author.`,
|
||||
);
|
||||
});
|
||||
|
||||
Logger.ok('Tidied merge requests without assignee.');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tidy
|
||||
*
|
||||
@@ -382,4 +423,5 @@ export async function tidy(api: Api) {
|
||||
|
||||
await tidyOpenIssuesWithoutMeetingLabel(api);
|
||||
await tidyIssuesWithoutAssignee(api);
|
||||
await tidyMergeRequestsWithoutAssignee(api);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user