Skip to content

Commit 53e8f03

Browse files
authored
license-check: fix --format=simple (#2076)
Signed-off-by: Łukasz 'sil2100' Zemczak <[email protected]>
1 parent 448cccf commit 53e8f03

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

pkg/renovate/copyright/copyright.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,26 @@ func populateSimpleCopyright(ctx context.Context, copyrightNode *yaml.Node, lice
207207
slices.Sort(ls)
208208
combined := strings.Join(ls, " AND ")
209209

210-
copyrightNode.Kind = yaml.ScalarNode
211-
copyrightNode.Value = combined
212-
copyrightNode.Tag = "!!str"
210+
// Create a single license entry with the combined license string
211+
licenseNode := &yaml.Node{
212+
Kind: yaml.MappingNode,
213+
Style: yaml.FlowStyle,
214+
Content: []*yaml.Node{},
215+
}
216+
217+
licenseNode.Content = append(licenseNode.Content, &yaml.Node{
218+
Kind: yaml.ScalarNode,
219+
Value: "license",
220+
Tag: "!!str",
221+
Style: yaml.FlowStyle,
222+
}, &yaml.Node{
223+
Kind: yaml.ScalarNode,
224+
Value: combined,
225+
Tag: "!!str",
226+
Style: yaml.FlowStyle,
227+
})
228+
229+
copyrightNode.Content = append(copyrightNode.Content, licenseNode)
213230

214231
return nil
215232
}

pkg/renovate/copyright/copyright_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,9 @@ func TestCopyright_updateSimple(t *testing.T) {
182182
resultData, err := os.ReadFile(testFile)
183183
assert.NoError(t, err)
184184

185-
// The copyright field should be a single string with both licenses joined by " AND "
185+
// The copyright field should contain a single license entry with both licenses joined by " AND "
186186
result := string(resultData)
187-
assert.Contains(t, result, "Apache-2.0 AND MIT")
187+
assert.Contains(t, result, "license: Apache-2.0 AND MIT")
188188
assert.NotContains(t, result, "GPL-3.0")
189189
assert.NotContains(t, result, "NOASSERTION")
190-
assert.NotContains(t, result, "license:")
191190
}

0 commit comments

Comments
 (0)