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 waysNo matter how you like to participate in developer communities, Pulumi wants to meet you there. If you want to meet other Pulumi users to share use-cases and best practices, contribute code or documentation, see us at an event, or just tell a story about something cool you did with Pulumi, you are part of our community.
Powered by