narrow-guitar-10891
02/02/2023, 9:45 PMexport async function applyRules(group: string, rules: Approval[]) {
let groupId = await findGroupsIds([group]);
if (groupId.length == 0) return;
try {
const groupProjects = await gitlab.getProjects({
groupId: groupId[0],
orderBy: "name",
includeSubgroups: true,
withShared: false,
});
groupProjects.projects.forEach(async (project) => {
const branches = await gitlab.getProjectProtectedBranches({
projectId: project.pathWithNamespace,
});
let branchIds = branches.protectedBranches.map(branch => branch.id);
const repoName = `${project.path.toLowerCase()}-${project.id}`;
rules.forEach((rule) => {
const ruleName = rule.name.replace(/\s/g, '-').toLowerCase();
const projectApproval = new gitlab.ProjectApprovalRule(`${repoName}-${ruleName}`, {
approvalsRequired: 1,
project: project.id.toString(),
name: rule.name,
userIds: rule.userIds,
groupIds: rule.groupIds,
protectedBranchIds: branchIds,
});
});
});
} catch (err) {
console.log(`Error: ${String(err).split('*').pop()}`)
}
}
Sure, the code is not perfect in some ways