Skip to content

Commit 01974f9

Browse files
authored
don't reset labels when updating gh issue for trivy scan (#551)
1 parent e873dd2 commit 01974f9

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
changelog:
2+
- type: NON_USER_FACING
3+
description: |
4+
Updated security scan GH issue writer to not purge existing labels.

securityscanutils/issuewriter/github_writer.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,24 @@ func (g *GithubIssueWriter) Write(
111111
if issue.GetTitle() == issueTitle {
112112
// Only create new issue if issue does not already exist
113113
createNewIssue = false
114+
115+
// Merge existing labels with desired labels, avoiding duplicates
116+
labelMap := map[string]struct{}{}
117+
for _, l := range issue.Labels {
118+
if l != nil && l.Name != nil {
119+
labelMap[*l.Name] = struct{}{}
120+
}
121+
}
122+
for _, l := range labels {
123+
labelMap[l] = struct{}{}
124+
}
125+
126+
mergedLabels := make([]string, 0, len(labelMap))
127+
for l := range labelMap {
128+
mergedLabels = append(mergedLabels, l)
129+
}
130+
issueRequest.Labels = &mergedLabels
131+
114132
err := githubutils.UpdateIssue(ctx, g.client, g.repo.Owner, g.repo.RepoName, issue.GetNumber(), issueRequest)
115133
if err != nil {
116134
return eris.Wrapf(err, "error updating issue with issue request %+v", issueRequest)

0 commit comments

Comments
 (0)