Files
dependency-review-action/src/dependency-graph.ts

54 lines
1.3 KiB
TypeScript
Raw Normal View History

2022-03-31 18:31:39 +02:00
import * as core from '@actions/core'
import * as githubUtils from '@actions/github/lib/utils'
import * as retry from '@octokit/plugin-retry'
2023-03-22 21:13:20 +00:00
import {
ChangesSchema,
ComparisonResponse,
ComparisonResponseSchema
} from './schemas'
2022-03-31 18:31:39 +02:00
const retryingOctokit = githubUtils.GitHub.plugin(retry.retry)
2023-03-22 21:13:20 +00:00
const SnapshotWarningsHeader = 'x-github-dependency-graph-snapshot-warnings'
2022-03-31 18:31:39 +02:00
const octo = new retryingOctokit(
githubUtils.getOctokitOptions(core.getInput('repo-token', {required: true}))
)
export async function compare({
owner,
repo,
baseRef,
headRef
}: {
owner: string
repo: string
baseRef: string
headRef: string
2023-03-22 21:13:20 +00:00
}): Promise<ComparisonResponse> {
let snapshot_warnings = ''
2022-03-31 18:31:39 +02:00
const changes = await octo.paginate(
{
2023-03-22 21:13:20 +00:00
method: 'GET',
url: '/repos/{owner}/{repo}/dependency-graph/compare/{basehead}',
2022-03-31 18:31:39 +02:00
owner,
repo,
basehead: `${baseRef}...${headRef}`
2023-03-22 21:13:20 +00:00
},
response => {
if (
response.headers[SnapshotWarningsHeader] &&
typeof response.headers[SnapshotWarningsHeader] === 'string'
) {
snapshot_warnings = Buffer.from(
response.headers[SnapshotWarningsHeader],
'base64'
).toString('utf-8')
}
return ChangesSchema.parse(response.data)
2022-03-31 18:31:39 +02:00
}
)
2023-03-22 21:13:20 +00:00
return ComparisonResponseSchema.parse({
changes,
snapshot_warnings
})
2022-03-31 18:31:39 +02:00
}