Skip to content
This repository has been archived by the owner on Jul 18, 2024. It is now read-only.

add repo id to secret scanning finding _key #307

Merged
merged 2 commits into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/steps/secretScanningAlerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ export async function fetchSecretScanningAlerts({
const restClient = getOrCreateRestClient(config, logger);

await restClient.iterateSecretScanningAlerts(async (alert) => {
const secretScanningAlertEntity = (await jobState.addEntity(
createSecretScanningAlertEntity(alert),
)) as SecretScanningFindingEntity;

const repoEntityKey =
alert.repository?.node_id &&
getRepositoryEntityKey(alert.repository.node_id);
if (!alert.repository?.node_id) {
return;
}
const secretScanningAlertEntity = await jobState.addEntity(
createSecretScanningAlertEntity(alert) as SecretScanningFindingEntity,
);

if (repoEntityKey && jobState.hasKey(repoEntityKey)) {
const repoEntityKey = getRepositoryEntityKey(alert.repository.node_id);
if (jobState.hasKey(repoEntityKey)) {
await jobState.addRelationship(
createDirectRelationship({
_class: RelationshipClass.HAS,
Expand Down
10 changes: 7 additions & 3 deletions src/sync/converters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ export function createCodeScanningFindingEntity(
});
}

export function getSecretScanningAlertKey(id: string) {
return `github_secret_scanning_finding:${id}`;
export function getSecretScanningAlertKey(
data: SecretScanningAlertQueryResponse,
) {
return `github_secret_scanning_finding:${data.repository!.node_id}:${
data.number
}`;
}

export function createSecretScanningAlertEntity(
Expand All @@ -206,7 +210,7 @@ export function createSecretScanningAlertEntity(
assign: {
_class: GithubEntities.GITHUB_SECRET_SCANNING_ALERT._class,
_type: GithubEntities.GITHUB_SECRET_SCANNING_ALERT._type,
_key: getSecretScanningAlertKey(String(data.number)),
_key: getSecretScanningAlertKey(data),
displayName: data.secret_type_display_name,
name: data.secret_type_display_name,
severity: 'CRITICAL',
Expand Down
Loading