Skip to content

Commit

Permalink
refactor: update/add tests for exempted repos
Browse files Browse the repository at this point in the history
  • Loading branch information
tjsilver committed Jan 9, 2025
1 parent 0ca2403 commit 92dc4d4
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type {
github_languages,
github_repository_custom_properties,
guardian_github_actions_usage,
view_repo_ownership,
} from '@prisma/client';
Expand Down Expand Up @@ -119,6 +120,32 @@ describe('When trying to find repos using Scala', () => {
});
});

function exemptedCustomProperty(): github_repository_custom_properties {
return {
cq_sync_time: null,
cq_source_name: null,
cq_id: 'id1',
cq_parent_id: null,
org: 'guardian',
property_name: 'gu_dependency_graph_integrator_ignore',
repository_id: BigInt(1),
value: 'Scala',
};
}

function nonExemptedCustomProperty(): github_repository_custom_properties {
return {
cq_sync_time: null,
cq_source_name: null,
cq_id: 'id1',
cq_parent_id: null,
org: 'guardian',
property_name: 'gu_dependency_graph_integrator_ignore',
repository_id: BigInt(12345),
value: 'Scala',
};
}

describe('When checking a repo for an existing dependency submission workflow', () => {
test('return true if repo workflow is present', () => {
const result = doesRepoHaveDepSubmissionWorkflowForLanguage(
Expand All @@ -138,12 +165,13 @@ describe('When checking a repo for an existing dependency submission workflow',
});
});

describe('When getting suitable events to send to SNS', () => {
describe('When getting suitable repos to send to SNS', () => {
test('return the repo when a Scala repo is found without an existing workflow', () => {
const result = getSuitableReposWithoutWorkflows(
[repoWithTargetLanguage(fullName)],
[repository(fullName)],
[repoWithoutWorkflow(fullName)],
[],
);
const expected = [repositoryWithDepGraphLanguage(fullName, 'Scala')];

Expand All @@ -154,6 +182,7 @@ describe('When getting suitable events to send to SNS', () => {
[repoWithTargetLanguage(fullName)],
[repository(fullName)],
[repoWithDepSubmissionWorkflow(fullName)],
[],
);
expect(result).toEqual([]);
});
Expand All @@ -162,14 +191,16 @@ describe('When getting suitable events to send to SNS', () => {
[repoWithoutTargetLanguage(fullName)],
[repository(fullName)],
[repoWithoutWorkflow(fullName)],
[],
);
expect(result).toEqual([]);
});
test('return 2 events when 2 Scala repos are found without an existing workflow', () => {
test('return both repos when 2 Scala repos are found without an existing workflow', () => {
const result = getSuitableReposWithoutWorkflows(
[repoWithTargetLanguage(fullName), repoWithTargetLanguage(fullName2)],
[repository(fullName), repository(fullName2)],
[repoWithoutWorkflow(fullName), repoWithoutWorkflow(fullName2)],
[],
);
const expected = [
repositoryWithDepGraphLanguage(fullName, 'Scala'),
Expand All @@ -178,6 +209,26 @@ describe('When getting suitable events to send to SNS', () => {

expect(result).toEqual(expected);
});
test('return the repo when a Scala repo is found without an existing workflow and repo is not exempt', () => {
const result = getSuitableReposWithoutWorkflows(
[repoWithTargetLanguage(fullName)],
[repository(fullName)],
[repoWithoutWorkflow(fullName)],
[nonExemptedCustomProperty()],
);
const expected = [repositoryWithDepGraphLanguage(fullName, 'Scala')];

expect(result).toEqual(expected);
});
test('return empty repo array when a Scala repo is found without an existing workflow but is exempt', () => {
const result = getSuitableReposWithoutWorkflows(
[repoWithTargetLanguage(fullName)],
[repository(fullName)],
[repoWithoutWorkflow(fullName)],
[exemptedCustomProperty()],
);
expect(result).toEqual([]);
});

const ownershipRecord1: view_repo_ownership = {
full_repo_name: fullName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ export async function sendReposToDependencyGraphIntegrator(

const selectedRepos: RepositoryWithDepGraphLanguage[] = [];

let reposWithPrs = 0;

while (selectedRepos.length < repoCount && shuffledRepos.length > 0) {
const repo = shuffledRepos.pop();
if (repo) {
Expand All @@ -221,14 +219,10 @@ export async function sendReposToDependencyGraphIntegrator(
);
if (!existingPr) {
selectedRepos.push(repo);
} else {
reposWithPrs++;
}
}
}

console.log(`Found ${reposWithPrs} repos with existing PRs`);

const eventsToSend: DependencyGraphIntegratorEvent[] =
createSnsEventsForDependencyGraphIntegration(selectedRepos, repoOwners);

Expand Down
3 changes: 1 addition & 2 deletions packages/repocop/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { Action } from '@guardian/anghammarad';
import type { Endpoints } from '@octokit/types';
import type {
aws_cloudformation_stacks,
github_repository_custom_properties,
github_teams,
repocop_github_repository_rules,
} from '@prisma/client';
Expand Down Expand Up @@ -150,4 +149,4 @@ export interface VulnerabilityDigest {
subject: string;
message: string;
actions: Action[];
}
}

0 comments on commit 92dc4d4

Please sign in to comment.