Skip to content

Commit

Permalink
feat: Fetch alerts with open status only (#167)
Browse files Browse the repository at this point in the history
The existing call returns the first `count` alerts. Some of these alerts
may be fixed or dismissed, while there may be older open alerts which
were not returned. Moving the filter operation to the backend resolves
this problem.

N.B. Alert `state` is one of `auto_dismissed`, `dismissed`, `fixed`, and
`open`. Of these, we are only interested in `open`
  • Loading branch information
dan-serendipity authored Mar 12, 2024
1 parent 2cccd6a commit ff6dac4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
10 changes: 0 additions & 10 deletions src/entities/alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,3 @@ export const toAlert = (
: undefined,
createdAt: dependabotAlert.created_at,
})

export const isActiveAlert = (dependabotAlert: DependabotAlert): boolean => {
if (
dependabotAlert.dismissed_at === null &&
dependabotAlert.fixed_at === null
) {
return true
}
return false
}
11 changes: 5 additions & 6 deletions src/fetch-alerts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Octokit } from '@octokit/rest'

import { Alert, isActiveAlert, toAlert } from './entities'
import { Alert, toAlert } from './entities'

export const fetchAlerts = async (
gitHubPersonalAccessToken: string,
Expand All @@ -18,13 +18,12 @@ export const fetchAlerts = async (
const response = await octokit.dependabot.listAlertsForRepo({
owner: repositoryOwner,
repo: repositoryName,
state: 'open',
severity,
per_page: count,
})
const alerts: Alert[] = response.data
.filter((dependabotAlert) => isActiveAlert(dependabotAlert))
.map((dependabotAlert) =>
toAlert(dependabotAlert, repositoryName, repositoryOwner),
)
const alerts: Alert[] = response.data.map((dependabotAlert) =>
toAlert(dependabotAlert, repositoryName, repositoryOwner),
)
return alerts
}

0 comments on commit ff6dac4

Please sign in to comment.