From eef8c15e6bc641f5239b32b0898375a9c459970b Mon Sep 17 00:00:00 2001 From: TJ Silver Date: Mon, 23 Dec 2024 15:27:22 +0000 Subject: [PATCH 1/2] feat: add functionality to ignore repos in dep graph integrator --- packages/repocop/src/config.ts | 10 ++++++ .../send-to-sns.ts | 31 ++++++++++++++----- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/packages/repocop/src/config.ts b/packages/repocop/src/config.ts index 35eb57482..61fc1a441 100644 --- a/packages/repocop/src/config.ts +++ b/packages/repocop/src/config.ts @@ -6,6 +6,7 @@ import { getDevDatabaseConfig, } from 'common/src/database-setup'; import type { DatabaseConfig, PrismaConfig } from 'common/src/database-setup'; +import type { DepGraphLanguage } from 'common/types'; export interface Config extends PrismaConfig { /** @@ -58,6 +59,11 @@ export interface Config extends PrismaConfig { */ dependencyGraphIntegratorTopic: string; + /** + * A list of repos to be excluded by the dependency graph integrator, by language. + */ + dependencyGraphIgnoredRepos: Record; + /** * The name of the GitHub organisation that owns the repositories. */ @@ -92,6 +98,10 @@ export async function getConfig(): Promise { dependencyGraphIntegratorTopic: getEnvOrThrow( 'DEPENDENCY_GRAPH_INPUT_TOPIC_ARN', ), + dependencyGraphIgnoredRepos: { + Scala: ['identity-platform'], + Kotlin: [], + }, gitHubOrg: process.env['GITHUB_ORG'] ?? 'guardian', }; } diff --git a/packages/repocop/src/remediation/dependency_graph-integrator/send-to-sns.ts b/packages/repocop/src/remediation/dependency_graph-integrator/send-to-sns.ts index 419e7fd03..0d1684e9d 100644 --- a/packages/repocop/src/remediation/dependency_graph-integrator/send-to-sns.ts +++ b/packages/repocop/src/remediation/dependency_graph-integrator/send-to-sns.ts @@ -7,6 +7,7 @@ import type { } from '@prisma/client'; import { awsClientConfig } from 'common/src/aws'; import { shuffle } from 'common/src/functions'; +import { logger } from 'common/src/logs'; import type { DependencyGraphIntegratorEvent, DepGraphLanguage, @@ -28,6 +29,22 @@ export function checkRepoForLanguage( return languagesInRepo.includes(targetLanguage); } +export function isRepoIgnored( + repoName: string, + language: DepGraphLanguage, + ignoredRepos: Record, +): boolean { + const isIgnored = ignoredRepos[language].includes(repoName); + if (isIgnored) { + logger.log({ + message: `Repo is being ignored by dependency graph integrator`, + depGraphLanguage: language, + repo: repoName, + }); + } + return isIgnored; +} + export function doesRepoHaveDepSubmissionWorkflowForLanguage( repo: Repository, workflowUsagesForRepo: guardian_github_actions_usage[], @@ -123,16 +140,17 @@ export function getReposWithoutWorkflows( languages: github_languages[], productionRepos: Repository[], productionWorkflowUsages: guardian_github_actions_usage[], + ignoredRepos: Record, ): RepositoryWithDepGraphLanguage[] { const depGraphLanguages: DepGraphLanguage[] = ['Scala', 'Kotlin']; const allReposWithoutWorkflows: RepositoryWithDepGraphLanguage[] = depGraphLanguages.flatMap((language) => { - const reposWithDepGraphLanguages: Repository[] = productionRepos.filter( - (repo) => checkRepoForLanguage(repo, languages, language), - ); + const reposWithDepGraphLanguages: Repository[] = productionRepos + .filter((repo) => checkRepoForLanguage(repo, languages, language)) + .filter((repo) => !isRepoIgnored(repo.name, language, ignoredRepos)); console.log( - `Found ${reposWithDepGraphLanguages.length} ${language} repos in production`, + `Found ${reposWithDepGraphLanguages.length} ${language} repos in production suitable for dependency graph integration`, ); return reposWithDepGraphLanguages @@ -148,10 +166,6 @@ export function getReposWithoutWorkflows( }) .map((repo) => ({ ...repo, dependency_graph_language: language })); }); - - console.log( - `Found ${allReposWithoutWorkflows.length} production repos without dependency submission workflows`, - ); return allReposWithoutWorkflows; } @@ -169,6 +183,7 @@ export async function sendReposToDependencyGraphIntegrator( repoLanguages, productionRepos, productionWorkflowUsages, + config.dependencyGraphIgnoredRepos, ); if (reposRequiringDepGraphIntegration.length !== 0) { From e6073501564a91014b4a632784ae1a1aad593d66 Mon Sep 17 00:00:00 2001 From: TJ Silver Date: Mon, 23 Dec 2024 16:12:17 +0000 Subject: [PATCH 2/2] update tests --- .../send-to-sns.test.ts | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/repocop/src/remediation/dependency_graph-integrator/send-to-sns.test.ts b/packages/repocop/src/remediation/dependency_graph-integrator/send-to-sns.test.ts index a37a5d278..40228efc3 100644 --- a/packages/repocop/src/remediation/dependency_graph-integrator/send-to-sns.test.ts +++ b/packages/repocop/src/remediation/dependency_graph-integrator/send-to-sns.test.ts @@ -20,7 +20,12 @@ import { const fullName = 'guardian/repo-name'; const fullName2 = 'guardian/repo2'; +const ignoredRepo = 'guardian/ignore-me'; const scalaLang = 'Scala'; +const ignoredRepos = { + Scala: ['ignore-me'], + Kotlin: [], +}; function createActionsUsage( fullName: string, @@ -144,6 +149,7 @@ describe('When getting suitable events to send to SNS', () => { [repoWithTargetLanguage(fullName)], [repository(fullName)], [repoWithoutWorkflow(fullName)], + ignoredRepos, ); const expected = [repositoryWithDepGraphLanguage(fullName, 'Scala')]; @@ -154,6 +160,7 @@ describe('When getting suitable events to send to SNS', () => { [repoWithTargetLanguage(fullName)], [repository(fullName)], [repoWithDepSubmissionWorkflow(fullName)], + ignoredRepos, ); expect(result).toEqual([]); }); @@ -162,14 +169,16 @@ describe('When getting suitable events to send to SNS', () => { [repoWithoutTargetLanguage(fullName)], [repository(fullName)], [repoWithoutWorkflow(fullName)], + ignoredRepos, ); expect(result).toEqual([]); }); - test('return 2 events when 2 Scala repos are found without an existing workflow', () => { + test('return 2 repos when 2 Scala repos are found without an existing workflow', () => { const result = getReposWithoutWorkflows( [repoWithTargetLanguage(fullName), repoWithTargetLanguage(fullName2)], [repository(fullName), repository(fullName2)], [repoWithoutWorkflow(fullName), repoWithoutWorkflow(fullName2)], + ignoredRepos, ); const expected = [ repositoryWithDepGraphLanguage(fullName, 'Scala'), @@ -178,6 +187,16 @@ describe('When getting suitable events to send to SNS', () => { expect(result).toEqual(expected); }); + test('return empty array when an ignored Scala repo is found with without an existing workflow', () => { + const result = getReposWithoutWorkflows( + [repoWithTargetLanguage(ignoredRepo)], + [repository(ignoredRepo)], + [repoWithoutWorkflow(ignoredRepo)], + ignoredRepos, + ); + + expect(result).toEqual([]); + }); const ownershipRecord1: view_repo_ownership = { full_repo_name: fullName,