Skip to content

Commit 9fd8ff4

Browse files
authored
Merge pull request #139 from pangaeatech/add_outputs
Added directory, package-ecosystem and target_branch to output
2 parents ffa0846 + aa297d4 commit 9fd8ff4

File tree

11 files changed

+193
-28
lines changed

11 files changed

+193
-28
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ Subsequent actions will have access to the following outputs:
3737
- The highest semver change being made by this PR, e.g. `version-update:semver-major`. For all possible values, see [the `ignore` documentation](https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates#ignore).
3838
- `steps.dependabot-metadata.outputs.updated-dependencies-json`
3939
- A JSON string containing the full information about each updated Dependency.
40+
- `steps.dependabot-metadata.outputs.directory`
41+
- The `directory` configuration that was used by dependabot for this updated Dependency.
42+
- `steps.dependabot-metadata.outputs.package-ecosystem`
43+
- The `package-ecosystem` configuration that was used by dependabot for this updated Dependency.
44+
- `steps.dependabot-metadata.outputs.target_branch`
45+
- The `target_branch` configuration that was used by dependabot for this updated Dependency.
4046

4147
**Note:** These outputs will only be populated if the target Pull Request was opened by Dependabot and contains
4248
**only** Dependabot-created commits.

action.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ outputs:
1616
description: 'The highest semver change being made by this PR, e.g. "version-update:semver-major"'
1717
updated-dependencies-json:
1818
description: 'A JSON string containing the full information about each updated Dependency.'
19+
directory:
20+
description: 'The `directory` configuration that was used by dependabot for this updated Dependency.'
21+
package-ecosystem:
22+
description: 'The `package-ecosystem` configuration that was used by dependabot for this updated Dependency.'
23+
target_branch:
24+
description: 'The `target_branch` configuration that was used by dependabot for this updated Dependency.'
1925
runs:
2026
using: 'node12'
2127
main: 'dist/index.js'

dist/index.js

Lines changed: 36 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/dependabot/output.test.ts

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ test('when given a single dependency it sets its values', async () => {
1414
{
1515
dependencyName: 'coffee-rails',
1616
dependencyType: 'direct:production',
17-
updateType: 'version-update:semver-minor'
17+
updateType: 'version-update:semver-minor',
18+
directory: 'wwwroot',
19+
packageEcosystem: 'nuget',
20+
targetBranch: 'main'
1821
}
1922
]
2023

@@ -29,29 +32,44 @@ test('when given a single dependency it sets its values', async () => {
2932
expect(core.setOutput).toBeCalledWith('dependency-names', 'coffee-rails')
3033
expect(core.setOutput).toBeCalledWith('dependency-type', 'direct:production')
3134
expect(core.setOutput).toBeCalledWith('update-type', 'version-update:semver-minor')
35+
expect(core.setOutput).toBeCalledWith('directory', 'wwwroot')
36+
expect(core.setOutput).toBeCalledWith('package-ecosystem', 'nuget')
37+
expect(core.setOutput).toBeCalledWith('target_branch', 'main')
3238
})
3339

3440
test('when given a multiple dependencies, it uses the highest values for types', async () => {
3541
const updatedDependencies = [
3642
{
3743
dependencyName: 'rspec',
3844
dependencyType: 'direct:development',
39-
updateType: 'version-update:semver-minor'
45+
updateType: 'version-update:semver-minor',
46+
directory: '',
47+
packageEcosystem: '',
48+
targetBranch: ''
4049
},
4150
{
4251
dependencyName: 'coffee-rails',
4352
dependencyType: 'indirect',
44-
updateType: 'version-update:semver-minor'
53+
updateType: 'version-update:semver-minor',
54+
directory: '',
55+
packageEcosystem: '',
56+
targetBranch: ''
4557
},
4658
{
4759
dependencyName: 'coffeescript',
4860
dependencyType: 'indirect',
49-
updateType: 'version-update:semver-major'
61+
updateType: 'version-update:semver-major',
62+
directory: '',
63+
packageEcosystem: '',
64+
targetBranch: ''
5065
},
5166
{
5267
dependencyName: 'rspec-coffeescript',
5368
dependencyType: 'indirect',
54-
updateType: 'version-update:semver-patch'
69+
updateType: 'version-update:semver-patch',
70+
directory: '',
71+
packageEcosystem: '',
72+
targetBranch: ''
5573
}
5674
]
5775

@@ -62,14 +80,20 @@ test('when given a multiple dependencies, it uses the highest values for types',
6280
expect(core.setOutput).toBeCalledWith('dependency-names', 'rspec, coffee-rails, coffeescript, rspec-coffeescript')
6381
expect(core.setOutput).toBeCalledWith('dependency-type', 'direct:development')
6482
expect(core.setOutput).toBeCalledWith('update-type', 'version-update:semver-major')
83+
expect(core.setOutput).toBeCalledWith('directory', '')
84+
expect(core.setOutput).toBeCalledWith('package-ecosystem', '')
85+
expect(core.setOutput).toBeCalledWith('target_branch', '')
6586
})
6687

6788
test('when the dependency has no update type', async () => {
6889
const updatedDependencies = [
6990
{
7091
dependencyName: 'coffee-rails',
7192
dependencyType: 'direct:production',
72-
updateType: ''
93+
updateType: '',
94+
directory: '',
95+
packageEcosystem: '',
96+
targetBranch: ''
7397
}
7498
]
7599

@@ -84,29 +108,44 @@ test('when the dependency has no update type', async () => {
84108
expect(core.setOutput).toBeCalledWith('dependency-names', 'coffee-rails')
85109
expect(core.setOutput).toBeCalledWith('dependency-type', 'direct:production')
86110
expect(core.setOutput).toBeCalledWith('update-type', null)
111+
expect(core.setOutput).toBeCalledWith('directory', '')
112+
expect(core.setOutput).toBeCalledWith('package-ecosystem', '')
113+
expect(core.setOutput).toBeCalledWith('target_branch', '')
87114
})
88115

89116
test('when given a multiple dependencies, and some do not have update types', async () => {
90117
const updatedDependencies = [
91118
{
92119
dependencyName: 'rspec',
93120
dependencyType: 'direct:development',
94-
updateType: ''
121+
updateType: '',
122+
directory: '',
123+
packageEcosystem: '',
124+
targetBranch: ''
95125
},
96126
{
97127
dependencyName: 'coffee-rails',
98128
dependencyType: 'indirect',
99-
updateType: 'version-update:semver-minor'
129+
updateType: 'version-update:semver-minor',
130+
directory: '',
131+
packageEcosystem: '',
132+
targetBranch: ''
100133
},
101134
{
102135
dependencyName: 'coffeescript',
103136
dependencyType: 'indirect',
104-
updateType: ''
137+
updateType: '',
138+
directory: '',
139+
packageEcosystem: '',
140+
targetBranch: ''
105141
},
106142
{
107143
dependencyName: 'rspec-coffeescript',
108144
dependencyType: 'indirect',
109-
updateType: 'version-update:semver-patch'
145+
updateType: 'version-update:semver-patch',
146+
directory: '',
147+
packageEcosystem: '',
148+
targetBranch: ''
110149
}
111150
]
112151

@@ -117,4 +156,7 @@ test('when given a multiple dependencies, and some do not have update types', as
117156
expect(core.setOutput).toBeCalledWith('dependency-names', 'rspec, coffee-rails, coffeescript, rspec-coffeescript')
118157
expect(core.setOutput).toBeCalledWith('dependency-type', 'direct:development')
119158
expect(core.setOutput).toBeCalledWith('update-type', 'version-update:semver-minor')
159+
expect(core.setOutput).toBeCalledWith('directory', '')
160+
expect(core.setOutput).toBeCalledWith('package-ecosystem', '')
161+
expect(core.setOutput).toBeCalledWith('target_branch', '')
120162
})

src/dependabot/output.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,27 @@ export function set (updatedDependencies: Array<updatedDependency>): void {
2020
const dependencyType = maxDependencyTypes(updatedDependencies)
2121
const updateType = maxSemver(updatedDependencies)
2222

23+
const firstDependency = updatedDependencies[0]
24+
const directory = firstDependency?.directory
25+
const ecosystem = firstDependency?.packageEcosystem
26+
const target = firstDependency?.targetBranch
27+
2328
core.startGroup(`Outputting metadata for ${Pluralize('updated dependency', updatedDependencies.length, true)}`)
2429
core.info(`outputs.dependency-names: ${dependencyNames}`)
2530
core.info(`outputs.dependency-type: ${dependencyType}`)
2631
core.info(`outputs.update-type: ${updateType}`)
32+
core.info(`outputs.directory: ${directory}`)
33+
core.info(`outputs.package-ecosystem: ${ecosystem}`)
34+
core.info(`outputs.target_branch: ${target}`)
2735
core.endGroup()
2836

2937
core.setOutput('updated-dependencies-json', updatedDependencies)
3038
core.setOutput('dependency-names', dependencyNames)
3139
core.setOutput('dependency-type', dependencyType)
3240
core.setOutput('update-type', updateType)
41+
core.setOutput('directory', directory)
42+
core.setOutput('package-ecosystem', ecosystem)
43+
core.setOutput('target_branch', target)
3344
}
3445

3546
function maxDependencyTypes (updatedDependencies: Array<updatedDependency>): string {

src/dependabot/update_metadata.test.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as updateMetadata from './update_metadata'
22

33
test('it returns an empty array for a blank string', async () => {
4-
expect(updateMetadata.parse('')).toEqual([])
4+
expect(updateMetadata.parse('', 'dependabot/nuget/feature1', 'main')).toEqual([])
55
})
66

77
test('it returns an empty array for commit message with no dependabot yaml fragment', async () => {
@@ -12,7 +12,7 @@ test('it returns an empty array for commit message with no dependabot yaml fragm
1212
1313
Signed-off-by: dependabot[bot] <[email protected]>`
1414

15-
expect(updateMetadata.parse(commitMessage)).toEqual([])
15+
expect(updateMetadata.parse(commitMessage, 'dependabot/nuget/feature1', 'main')).toEqual([])
1616
})
1717

1818
test('it returns the updated dependency information when there is a yaml fragment', async () => {
@@ -31,13 +31,16 @@ test('it returns the updated dependency information when there is a yaml fragmen
3131
'\n' +
3232
'Signed-off-by: dependabot[bot] <[email protected]>'
3333

34-
const updatedDependencies = updateMetadata.parse(commitMessage)
34+
const updatedDependencies = updateMetadata.parse(commitMessage, 'dependabot/nuget/feature1', 'main')
3535

3636
expect(updatedDependencies).toHaveLength(1)
3737

3838
expect(updatedDependencies[0].dependencyName).toEqual('coffee-rails')
3939
expect(updatedDependencies[0].dependencyType).toEqual('direct:production')
4040
expect(updatedDependencies[0].updateType).toEqual('version-update:semver-minor')
41+
expect(updatedDependencies[0].directory).toEqual('/')
42+
expect(updatedDependencies[0].packageEcosystem).toEqual('nuget')
43+
expect(updatedDependencies[0].targetBranch).toEqual('main')
4144
})
4245

4346
test('it supports multiple dependencies within a single fragment', async () => {
@@ -59,17 +62,23 @@ test('it supports multiple dependencies within a single fragment', async () => {
5962
'\n' +
6063
'Signed-off-by: dependabot[bot] <[email protected]>'
6164

62-
const updatedDependencies = updateMetadata.parse(commitMessage)
65+
const updatedDependencies = updateMetadata.parse(commitMessage, 'dependabot/nuget/api/main/feature1', 'main')
6366

6467
expect(updatedDependencies).toHaveLength(2)
6568

6669
expect(updatedDependencies[0].dependencyName).toEqual('coffee-rails')
6770
expect(updatedDependencies[0].dependencyType).toEqual('direct:production')
6871
expect(updatedDependencies[0].updateType).toEqual('version-update:semver-minor')
72+
expect(updatedDependencies[0].directory).toEqual('api/main')
73+
expect(updatedDependencies[0].packageEcosystem).toEqual('nuget')
74+
expect(updatedDependencies[0].targetBranch).toEqual('main')
6975

7076
expect(updatedDependencies[1].dependencyName).toEqual('coffeescript')
7177
expect(updatedDependencies[1].dependencyType).toEqual('indirect')
7278
expect(updatedDependencies[1].updateType).toEqual('version-update:semver-patch')
79+
expect(updatedDependencies[1].directory).toEqual('api/main')
80+
expect(updatedDependencies[1].packageEcosystem).toEqual('nuget')
81+
expect(updatedDependencies[1].targetBranch).toEqual('main')
7382
})
7483

7584
test('it only returns information within the first fragment if there are multiple yaml documents', async () => {
@@ -95,11 +104,14 @@ test('it only returns information within the first fragment if there are multipl
95104
'\n' +
96105
'Signed-off-by: dependabot[bot] <[email protected]>'
97106

98-
const updatedDependencies = updateMetadata.parse(commitMessage)
107+
const updatedDependencies = updateMetadata.parse(commitMessage, 'dependabot|nuget|api|feature1', 'main')
99108

100109
expect(updatedDependencies).toHaveLength(1)
101110

102111
expect(updatedDependencies[0].dependencyName).toEqual('coffee-rails')
103112
expect(updatedDependencies[0].dependencyType).toEqual('direct:production')
104113
expect(updatedDependencies[0].updateType).toEqual('version-update:semver-minor')
114+
expect(updatedDependencies[0].directory).toEqual('api')
115+
expect(updatedDependencies[0].packageEcosystem).toEqual('nuget')
116+
expect(updatedDependencies[0].targetBranch).toEqual('main')
105117
})

src/dependabot/update_metadata.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,31 @@ export interface updatedDependency {
44
dependencyName: string,
55
dependencyType: string,
66
updateType: string,
7+
directory: string,
8+
packageEcosystem: string,
9+
targetBranch: string
710
}
811

9-
export function parse (commitMessage: string): Array<updatedDependency> {
12+
export function parse (commitMessage: string, branchName: string, mainBranch: string): Array<updatedDependency> {
1013
const yamlFragment = commitMessage.match(/^-{3}\n(?<dependencies>[\S|\s]*?)\n^\.{3}\n/m)
1114

12-
if (yamlFragment?.groups) {
15+
if (yamlFragment?.groups && branchName.startsWith('dependabot')) {
1316
const data = YAML.parse(yamlFragment.groups.dependencies)
1417

18+
// Since we are on the `dependabot` branch (9 letters), the 10th letter in the branch name is the delimiter
19+
const delim = branchName[10]
20+
const chunks = branchName.split(delim)
21+
const dirname = chunks.slice(2, -1).join(delim) || '/'
22+
1523
if (data['updated-dependencies']) {
1624
return data['updated-dependencies'].map(dependency => {
1725
return {
1826
dependencyName: dependency['dependency-name'],
1927
dependencyType: dependency['dependency-type'],
20-
updateType: dependency['update-type']
28+
updateType: dependency['update-type'],
29+
directory: dirname,
30+
packageEcosystem: chunks[1],
31+
targetBranch: mainBranch
2132
}
2233
})
2334
}

0 commit comments

Comments
 (0)