Skip to content

Commit

Permalink
fix: correct logic after local testing
Browse files Browse the repository at this point in the history
  • Loading branch information
tjsilver committed Jul 5, 2024
1 parent 1bada9f commit df456d3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
24 changes: 11 additions & 13 deletions packages/repocop/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
getTeams,
} from './query';
import { protectBranches } from './remediation/branch-protector/branch-protection';
import { sendOneRepo } from './remediation/dependency_graph-integrator/send-to-sns';
import { sendOneRepoToDepGraphIntegrator } from './remediation/dependency_graph-integrator/send-to-sns';
import { sendUnprotectedRepo } from './remediation/snyk-integrator/send-to-sns';
import { sendPotentialInteractives } from './remediation/topics/topic-monitor-interactive';
import { applyProductionTopicAndMessageTeams } from './remediation/topics/topic-monitor-production';
Expand Down Expand Up @@ -156,18 +156,6 @@ export async function main() {
await sendUnprotectedRepo(repocopRules, config, repoLanguages);
}

if (config.dependencyGraphIntegrationPrEnabled) {
const productionWorkflowUsages: guardian_github_actions_usage[] =
await getProductionWorkflowUsages(prisma, productionRepos);

await sendOneRepo(
config,
repoLanguages,
productionRepos,
productionWorkflowUsages,
);
}

await writeEvaluationTable(repocopRules, prisma);
if (config.enableMessaging) {
await sendPotentialInteractives(repocopRules, config);
Expand Down Expand Up @@ -204,5 +192,15 @@ export async function main() {
);
}

// Dependency Graph Integrator
const productionWorkflowUsages: guardian_github_actions_usage[] =
await getProductionWorkflowUsages(prisma, productionRepos);
await sendOneRepoToDepGraphIntegrator(
config,
repoLanguages,
productionRepos,
productionWorkflowUsages,
);

console.log('Done');
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,20 @@ export function checkRepoForLanguage(
const languagesInRepo: string[] =
languages.find((language) => language.full_name === repo.full_name)
?.languages ?? [];

return languagesInRepo.includes(targetLanguage);
}

export function doesRepoHaveWorkflow(
repo: Repository,
workflow_usages: guardian_github_actions_usage[],
): boolean {
const usagesForRepo = workflow_usages.find(
(usages) => repo.full_name === usages.full_name,
) as guardian_github_actions_usage;

const actionsForRepo: string[] = usagesForRepo.workflow_uses;
const actionsForRepo = workflow_usages
.filter((usages) => repo.full_name === usages.full_name)
.flatMap((workflow) => workflow.workflow_uses);

const dependencySubmissionWorkflow = actionsForRepo.find((action) =>
action.includes('scalacenter/sbt-dependency-submission'),
);

if (dependencySubmissionWorkflow) {
return true;
}
Expand All @@ -53,20 +49,24 @@ export function getSuitableRepoEvents(
checkRepoForLanguage(repo, languages, 'Scala'),
);

console.log(`Found ${scalaRepos.length} Scala repos in production`);

const scalaReposWithoutWorkflows = scalaRepos.filter(
(repo) => !doesRepoHaveWorkflow(repo, workflow_usages),
);

console.log(
`Found ${scalaRepos.length} production Scala repos without dependency submission workflows`,
);

const events = scalaReposWithoutWorkflows.map((repo) => ({
name: removeRepoOwner(repo.full_name),
}));

console.log(events);

console.log(`Found ${events.length} events to send to SNS`);
return events;
}

export async function sendOneRepo(
export async function sendOneRepoToDepGraphIntegrator(
config: Config,
repoLanguages: github_languages[],
productionRepos: Repository[],
Expand All @@ -81,7 +81,6 @@ export async function sendOneRepo(
Message: JSON.stringify(eventToSend),
TopicArn: config.dependencyGraphIntegratorTopic,
});

console.log(`Sending ${eventToSend.name} to Dependency Graph Integrator`);
await new SNSClient(awsClientConfig(config.stage)).send(
publishRequestEntry,
Expand Down

0 comments on commit df456d3

Please sign in to comment.