Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow to ignore specific dependencies #196

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ jobs:
# slack_webhook: ${{ secrets.SLACK_WEBHOOK }}
# severity: low,medium
# ecosystem: npm,rubygems
# ignore_dependencies: lodash,devise
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's call it ignore_packages since GitHub calls them packages instead of dependencies

# count: 20
# pager_duty_integration_key: ${{ secrets.PAGER_DUTY_INTEGRATION_KEY }}
# zenduty_api_key: ${{ secrets.ZENDUTY_API_KEY }}
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ inputs:
description: 'Comma separated list of severities. E.g. low,medium,high,critical (NO SPACES BETWEEN COMMA AND SEVERITY)'
ecosystem:
description: 'A comma-separated list of ecosystems. If specified, only alerts for these ecosystems will be returned.'
ignore_dependencies:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ignore_dependencies:
ignore_packages:

description: 'A comma-separated list of dependencies to ignore. If specified, these dependencies will not be alerted.'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
description: 'A comma-separated list of dependencies to ignore. If specified, these dependencies will not be alerted.'
description: 'A comma-separated list of package names. If specified, alerts for these packages will be ignored.'

branding:
icon: 'alert-octagon'
color: 'red'
Expand Down
36 changes: 27 additions & 9 deletions src/fetch-alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export const fetchRepositoryAlerts = async (
repositoryOwner: string,
severity: string,
ecosystem: string,
ignoreDependencies: string[],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ignoreDependencies: string[],
ignorePackages: string[],

count: number,
): Promise<Alert[] | []> => {
const octokit = new Octokit({
Expand All @@ -29,9 +30,14 @@ export const fetchRepositoryAlerts = async (
ecosystem: ecosystem.length > 0 ? ecosystem : undefined,
per_page: count,
})
const alerts: Alert[] = response.data.map((dependabotAlert) =>
toRepositoryAlert(dependabotAlert, repositoryName, repositoryOwner),
)
const alerts: Alert[] = response
.data
.filter((dependabotAlert) =>
!ignoreDependencies.includes(dependabotAlert.security_vulnerability.package.name)
)
.map((dependabotAlert) =>
toRepositoryAlert(dependabotAlert, repositoryName, repositoryOwner),
)
Comment on lines +33 to +40
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Do you mind running the lint task and see if it passes? I feel like your editor may not be set up correctly to format the code automatically.
  2. We only need to filter the alerts if the ignorePackages field contains a value. We should check for that, and only filter if required.

return alerts
}

Expand All @@ -40,6 +46,7 @@ export const fetchOrgAlerts = async (
org: string,
severity: string,
ecosystem: string,
ignoreDependencies: string[],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ignoreDependencies: string[],
ignorePackages: string[],

count: number,
): Promise<Alert[] | []> => {
const octokit = new Octokit({
Expand All @@ -55,9 +62,14 @@ export const fetchOrgAlerts = async (
ecosystem: ecosystem.length > 0 ? ecosystem : undefined,
per_page: count,
})
const alerts: Alert[] = response.data.map((dependabotOrgAlert) =>
toOrgAlert(dependabotOrgAlert),
)
const alerts: Alert[] = response
.data
.filter((dependabotOrgAlert) =>
!ignoreDependencies.includes(dependabotOrgAlert.security_vulnerability.package.name)
)
.map((dependabotOrgAlert) =>
toOrgAlert(dependabotOrgAlert),
)
Comment on lines +65 to +72
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

return alerts
}

Expand All @@ -66,6 +78,7 @@ export const fetchEnterpriseAlerts = async (
enterprise: string,
severity: string,
ecosystem: string,
ignoreDependencies: string[],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
ignoreDependencies: string[],
ignorePackages: string[],

count: number,
): Promise<Alert[] | []> => {
const octokit = new Octokit({
Expand All @@ -81,8 +94,13 @@ export const fetchEnterpriseAlerts = async (
ecosystem: ecosystem.length > 0 ? ecosystem : undefined,
per_page: count,
})
const alerts: Alert[] = response.data.map((dependabotEnterpriseAlert) =>
toEnterpriseAlert(dependabotEnterpriseAlert),
)
const alerts: Alert[] = response
.data
.filter((dependabotEnterpriseAlert) =>
!ignoreDependencies.includes(dependabotEnterpriseAlert.security_vulnerability.package.name)
)
.map((dependabotEnterpriseAlert) =>
toEnterpriseAlert(dependabotEnterpriseAlert),
)
Comment on lines +97 to +104
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

return alerts
}
7 changes: 6 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,20 @@ async function run(): Promise<void> {
const count = parseInt(getInput('count'))
const severity = getInput('severity')
const ecosystem = getInput('ecosystem')
const ignoreDependencies = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const ignoreDependencies = (
const ignorePackages = (

getInput('ignore_dependencies') || ''
).split(',').map((str: string) => str.trim())
Comment on lines +43 to +44
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's pass the value here directly using getInput and do the transform inside the logic where we check if this field has values. We don't need to do this transform if no values exist.


let alerts: Alert[] = []
if (org) {
alerts = await fetchOrgAlerts(token, org, severity, ecosystem, count)
alerts = await fetchOrgAlerts(token, org, severity, ecosystem, ignoreDependencies, count)
} else if (enterprise) {
alerts = await fetchEnterpriseAlerts(
token,
org,
severity,
ecosystem,
ignoreDependencies,
count,
)
} else {
Expand All @@ -59,6 +63,7 @@ async function run(): Promise<void> {
owner,
severity,
ecosystem,
ignoreDependencies,
count,
)
}
Expand Down