This repository has been archived by the owner on Jul 1, 2024. It is now read-only.
forked from kunalnagarco/action-cve
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Filter alerts by severity (kunalnagarco#151)
- Loading branch information
1 parent
0df7e7e
commit 73e22d9
Showing
10 changed files
with
162 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,31 @@ | ||
import { Alert, toAlert, isActiveAlert } from './entities' | ||
import { Repository } from '@octokit/graphql-schema' | ||
import { getOctokit } from '@actions/github' | ||
import fetch from 'node-fetch' | ||
import { Octokit } from '@octokit/rest' | ||
|
||
import { Alert, isActiveAlert, toAlert } from './entities' | ||
|
||
export const fetchAlerts = async ( | ||
gitHubPersonalAccessToken: string, | ||
repositoryName: string, | ||
repositoryOwner: string, | ||
severity: string, | ||
count: number, | ||
): Promise<Alert[] | []> => { | ||
const octokit = getOctokit(gitHubPersonalAccessToken) | ||
const { repository } = await octokit.graphql<{ | ||
repository: Repository | ||
}>(` | ||
query { | ||
repository(owner:"${repositoryOwner}" name:"${repositoryName}") { | ||
vulnerabilityAlerts(last: ${count}) { | ||
edges { | ||
node { | ||
id | ||
dismissedAt | ||
fixedAt | ||
repository { | ||
name | ||
owner { | ||
login | ||
} | ||
} | ||
securityAdvisory { | ||
id | ||
description | ||
cvss { | ||
score | ||
vectorString | ||
} | ||
permalink | ||
severity | ||
summary | ||
} | ||
securityVulnerability { | ||
firstPatchedVersion { | ||
identifier | ||
} | ||
package { | ||
ecosystem | ||
name | ||
} | ||
vulnerableVersionRange | ||
advisory { | ||
cvss { | ||
score | ||
vectorString | ||
} | ||
summary | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
`) | ||
const gitHubAlerts = repository.vulnerabilityAlerts?.edges | ||
if (gitHubAlerts) { | ||
const alerts: Alert[] = [] | ||
for (const gitHubAlert of gitHubAlerts) { | ||
if (gitHubAlert && gitHubAlert.node && isActiveAlert(gitHubAlert.node)) { | ||
alerts.push(toAlert(gitHubAlert.node)) | ||
} | ||
} | ||
return alerts | ||
} | ||
return [] | ||
const octokit = new Octokit({ | ||
auth: gitHubPersonalAccessToken, | ||
request: { | ||
fetch, | ||
}, | ||
}) | ||
const response = await octokit.dependabot.listAlertsForRepo({ | ||
owner: repositoryOwner, | ||
repo: repositoryName, | ||
severity, | ||
per_page: count, | ||
}) | ||
const alerts: Alert[] = response.data | ||
.filter((dependabotAlert) => isActiveAlert(dependabotAlert)) | ||
.map((dependabotAlert) => | ||
toAlert(dependabotAlert, repositoryName, repositoryOwner), | ||
) | ||
return alerts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.