Skip to content

Commit cfab22f

Browse files
committed
Add dependency group metadata
1 parent 73e8a46 commit cfab22f

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Subsequent actions will have access to the following outputs:
8484
- If this PR has a known compatibility score and `compat-lookup` is `true`, this contains the compatibility score (otherwise it contains 0).
8585
- `steps.dependabot-metadata.outputs.maintainer-changes`
8686
- Whether or not the the body of this PR contains the phrase "Maintainer changes" which is an indicator of whether or not any maintainers have changed.
87+
- `steps.dependabot-metadata.outputs.dependency-group`
88+
- The dependency group that the PR is associated with (otherwise it is an empty string).
8789

8890
**Note:** By default, these outputs will only be populated if the target Pull Request was opened by Dependabot and contains
8991
**only** Dependabot-created commits. To override, see `skip-commit-verification` / `skip-verification`.

src/dependabot/output.ts

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function set (updatedDependencies: Array<updatedDependency>): void {
2828
const newVersion = firstDependency?.newVersion
2929
const compatScore = firstDependency?.compatScore
3030
const maintainerChanges = firstDependency?.maintainerChanges
31+
const dependencyGroup = firstDependency?.dependencyGroup
3132
const alertState = firstDependency?.alertState
3233
const ghsaId = firstDependency?.ghsaId
3334
const cvss = firstDependency?.cvss
@@ -43,6 +44,7 @@ export function set (updatedDependencies: Array<updatedDependency>): void {
4344
core.info(`outputs.new-version: ${newVersion}`)
4445
core.info(`outputs.compatibility-score: ${compatScore}`)
4546
core.info(`outputs.maintainer-changes: ${maintainerChanges}`)
47+
core.info(`outputs.dependency-group: ${dependencyGroup}`)
4648
core.info(`outputs.alert-state: ${alertState}`)
4749
core.info(`outputs.ghsa-id: ${ghsaId}`)
4850
core.info(`outputs.cvss: ${cvss}`)
@@ -59,6 +61,7 @@ export function set (updatedDependencies: Array<updatedDependency>): void {
5961
core.setOutput('new-version', newVersion)
6062
core.setOutput('compatibility-score', compatScore)
6163
core.setOutput('maintainer-changes', maintainerChanges)
64+
core.setOutput('dependency-group', dependencyGroup)
6265
core.setOutput('alert-state', alertState)
6366
core.setOutput('ghsa-id', ghsaId)
6467
core.setOutput('cvss', cvss)

src/dependabot/update_metadata.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ export interface updatedDependency extends dependencyAlert {
1616
prevVersion: string,
1717
newVersion: string,
1818
compatScore: number,
19-
maintainerChanges: boolean
19+
maintainerChanges: boolean,
20+
dependencyGroup: string
2021
}
2122

2223
export interface alertLookup {
@@ -31,6 +32,7 @@ export async function parse (commitMessage: string, body: string, branchName: st
3132
const bumpFragment = commitMessage.match(/^Bumps .* from (?<from>v?\d[^ ]*) to (?<to>v?\d[^ ]*)\.$/m)
3233
const updateFragment = commitMessage.match(/^Update .* requirement from \S*? ?(?<from>v?\d\S*) to \S*? ?(?<to>v?\d\S*)$/m)
3334
const yamlFragment = commitMessage.match(/^-{3}\n(?<dependencies>[\S|\s]*?)\n^\.{3}\n/m)
35+
const groupName = body.match(/^Bumps the (?<name>\S*) group with/m)
3436
const newMaintainer = !!body.match(/Maintainer changes/m)
3537
const lookupFn = lookup ?? (() => Promise.resolve({ alertState: '', ghsaId: '', cvss: 0 }))
3638
const scoreFn = getScore ?? (() => Promise.resolve(0))
@@ -43,6 +45,7 @@ export async function parse (commitMessage: string, body: string, branchName: st
4345
const chunks = branchName.split(delim)
4446
const prev = bumpFragment?.groups?.from ?? (updateFragment?.groups?.from ?? '')
4547
const next = bumpFragment?.groups?.to ?? (updateFragment?.groups?.to ?? '')
48+
const dependencyGroup = groupName?.groups?.name ?? ''
4649

4750
if (data['updated-dependencies']) {
4851
return await Promise.all(data['updated-dependencies'].map(async (dependency, index) => {
@@ -61,6 +64,7 @@ export async function parse (commitMessage: string, body: string, branchName: st
6164
newVersion: nextVersion,
6265
compatScore: await scoreFn(dependency['dependency-name'], lastVersion, nextVersion, chunks[1]),
6366
maintainerChanges: newMaintainer,
67+
dependencyGroup: dependencyGroup,
6468
...await lookupFn(dependency['dependency-name'], lastVersion, dirname)
6569
}
6670
}))

0 commit comments

Comments
 (0)