export async function applyProductionTopicAndMessageTeams()

in packages/repocop/src/remediation/topics/topic-monitor-production.ts [164:210]


export async function applyProductionTopicAndMessageTeams(
	unarchivedRepos: Repository[],
	stacks: AwsCloudFormationStack[],
	repoOwners: view_repo_ownership[],
	octokit: Octokit,
	config: Config,
): Promise<void> {
	const repos = findReposInProdWithoutProductionTopic(unarchivedRepos, stacks);

	const repoAndStackNames = repos
		.filter((repo) => !!repo.tags['gu:repo'])
		.filter((repo) => !!repo.stack_name)
		.map((repo) => {
			return { fullRepoName: repo.tags['gu:repo'], stackName: repo.stack_name };
		});

	const reposWithContactableOwners = repoAndStackNames
		.map((names) => {
			const fullRepoName = names.fullRepoName ?? '';
			const stackName = names.stackName;
			const teamNameSlugs = findContactableOwners(fullRepoName, repoOwners);
			return {
				fullName: fullRepoName,
				stackName: stackName,
				teamNameSlugs: teamNameSlugs,
			};
		})
		.filter((contactableRepo) => contactableRepo.teamNameSlugs.length > 0);

	if (reposWithContactableOwners.length > 0) {
		console.log(
			`Found ${reposWithContactableOwners.length} repos with contactable owners for addition of the production topic`,
		);
	}

	await Promise.all(
		reposWithContactableOwners.map((repo) =>
			applyProductionTopicToOneRepoAndMessageTeams(
				repo.fullName,
				repo.stackName,
				repo.teamNameSlugs,
				octokit,
				config,
			),
		),
	);
}