Skip to content

Commit

Permalink
Add dependency group metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Nishnha committed Jun 8, 2023
1 parent 73e8a46 commit cfab22f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ Subsequent actions will have access to the following outputs:
- If this PR has a known compatibility score and `compat-lookup` is `true`, this contains the compatibility score (otherwise it contains 0).
- `steps.dependabot-metadata.outputs.maintainer-changes`
- 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.
- `steps.dependabot-metadata.outputs.dependency-group`
- The dependency group that the PR is associated with (otherwise it is an empty string).

**Note:** By default, these outputs will only be populated if the target Pull Request was opened by Dependabot and contains
**only** Dependabot-created commits. To override, see `skip-commit-verification` / `skip-verification`.
Expand Down
3 changes: 3 additions & 0 deletions src/dependabot/output.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export function set (updatedDependencies: Array<updatedDependency>): void {
const newVersion = firstDependency?.newVersion
const compatScore = firstDependency?.compatScore
const maintainerChanges = firstDependency?.maintainerChanges
const dependencyGroup = firstDependency?.dependencyGroup
const alertState = firstDependency?.alertState
const ghsaId = firstDependency?.ghsaId
const cvss = firstDependency?.cvss
Expand All @@ -43,6 +44,7 @@ export function set (updatedDependencies: Array<updatedDependency>): void {
core.info(`outputs.new-version: ${newVersion}`)
core.info(`outputs.compatibility-score: ${compatScore}`)
core.info(`outputs.maintainer-changes: ${maintainerChanges}`)
core.info(`outputs.dependency-group: ${dependencyGroup}`)
core.info(`outputs.alert-state: ${alertState}`)
core.info(`outputs.ghsa-id: ${ghsaId}`)
core.info(`outputs.cvss: ${cvss}`)
Expand All @@ -59,6 +61,7 @@ export function set (updatedDependencies: Array<updatedDependency>): void {
core.setOutput('new-version', newVersion)
core.setOutput('compatibility-score', compatScore)
core.setOutput('maintainer-changes', maintainerChanges)
core.setOutput('dependency-group', dependencyGroup)
core.setOutput('alert-state', alertState)
core.setOutput('ghsa-id', ghsaId)
core.setOutput('cvss', cvss)
Expand Down
6 changes: 5 additions & 1 deletion src/dependabot/update_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export interface updatedDependency extends dependencyAlert {
prevVersion: string,
newVersion: string,
compatScore: number,
maintainerChanges: boolean
maintainerChanges: boolean,
dependencyGroup: string
}

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

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

0 comments on commit cfab22f

Please sign in to comment.