Skip to content

Commit f4bf5d2

Browse files
author
Copybara
committed
Project import generated by Copybara.
GitOrigin-RevId: 6f3c95ae2657a15c02e0a8be73395cdb7b330771
1 parent 476f6df commit f4bf5d2

File tree

7 files changed

+197
-23
lines changed

7 files changed

+197
-23
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
jobs:
88
# Actually release the binaries including signing them
99
release:
10-
runs-on: depot-ubuntu-22.04-8
10+
runs-on: depot-ubuntu-22.04-32
1111
if: ${{ github.event_name != 'pull_request' }}
1212
permissions:
1313
contents: write

cmd/changes_get_change.go

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ var getChangeCmd = &cobra.Command{
3838
// to reflect the latest version
3939
//
4040
// This allows us to update the assets without fear of breaking older comments
41-
const assetVersion = "17c7fd2c365d4f4cdd8e414ca5148f825fa4febd"
41+
const assetVersion = "476f6df5bc783c17b1d0513a43e0a0aa9c075588" // tag from v1.6.1
4242

4343
func GetChange(cmd *cobra.Command, args []string) error {
4444
ctx := cmd.Context()
@@ -204,8 +204,10 @@ fetch:
204204
SeverityText string
205205
Title string
206206
Description string
207+
RiskUrl string
207208
}
208209
type TemplateData struct {
210+
BlastRadiusUrl string
209211
ChangeUrl string
210212
ExpectedChanges []TemplateItem
211213
UnmappedChanges []TemplateItem
@@ -214,6 +216,7 @@ fetch:
214216
Risks []TemplateRisk
215217
// Path to the assets folder on github
216218
AssetPath string
219+
TagsLine string
217220
}
218221
status := map[sdp.ItemDiffStatus]TemplateItem{
219222
sdp.ItemDiffStatus_ITEM_DIFF_STATUS_UNSPECIFIED: {
@@ -267,6 +270,7 @@ fetch:
267270
app, _ = strings.CutSuffix(app, "/")
268271
data := TemplateData{
269272
ChangeUrl: fmt.Sprintf("%v/changes/%v", app, changeUuid.String()),
273+
BlastRadiusUrl: fmt.Sprintf("%v/changes/%v/blast-radius", app, changeUuid.String()),
270274
ExpectedChanges: []TemplateItem{},
271275
UnmappedChanges: []TemplateItem{},
272276
BlastItems: int(changeRes.Msg.GetChange().GetMetadata().GetNumAffectedItems()),
@@ -326,14 +330,20 @@ fetch:
326330
}
327331

328332
for _, risk := range riskRes.Msg.GetChangeRiskMetadata().GetRisks() {
333+
// parse the risk UUID to a string
334+
riskUuid, _ := uuid.FromBytes(risk.GetUUID())
329335
data.Risks = append(data.Risks, TemplateRisk{
330336
SeverityAlt: severity[risk.GetSeverity()].SeverityAlt,
331337
SeverityIcon: severity[risk.GetSeverity()].SeverityIcon,
332338
SeverityText: severity[risk.GetSeverity()].SeverityText,
333339
Title: risk.GetTitle(),
334340
Description: risk.GetDescription(),
341+
RiskUrl: fmt.Sprintf("%v/changes/%v/blast-radius?selectedRisk=%v&activeTab=risks", app, changeUuid.String(), riskUuid.String()),
335342
})
336343
}
344+
// get the tags in
345+
data.TagsLine = getTagsLine(changeRes.Msg.GetChange().GetProperties().GetEnrichedTags().GetTagValue())
346+
data.TagsLine = strings.TrimSpace(data.TagsLine)
337347

338348
tmpl, err := template.New("comment").Parse(commentTemplate)
339349
if err != nil {
@@ -386,6 +396,32 @@ func renderRiskFilter(levels []sdp.Risk_Severity) string {
386396
return strings.Join(result, ", ")
387397
}
388398

399+
func getTagsLine(tags map[string]*sdp.TagValue) string {
400+
autoTags := ""
401+
userTags := ""
402+
403+
for key, value := range tags {
404+
if value.GetAutoTagValue() != nil {
405+
suffix := ""
406+
if value.GetAutoTagValue().GetValue() != "" {
407+
suffix = fmt.Sprintf("|%s", value.GetAutoTagValue().GetValue())
408+
}
409+
autoTags += fmt.Sprintf("`✨%s%s` ", key, suffix)
410+
} else if value.GetUserTagValue() != nil {
411+
suffix := ""
412+
if value.GetUserTagValue().GetValue() != "" {
413+
suffix = fmt.Sprintf("|%s", value.GetUserTagValue().GetValue())
414+
}
415+
userTags += fmt.Sprintf("`%s%s` ", key, suffix)
416+
} else {
417+
// we should never get here, but just in case.
418+
// its a tag jim, but not as we know it
419+
userTags += fmt.Sprintf("`%s` ", key)
420+
}
421+
}
422+
return autoTags + userTags
423+
}
424+
389425
func init() {
390426
changesCmd.AddCommand(getChangeCmd)
391427
addAPIFlags(getChangeCmd)

cmd/changes_get_change_test.go

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package cmd
2+
3+
import (
4+
"testing"
5+
6+
"github.com/overmindtech/cli/sdp-go"
7+
"github.com/stretchr/testify/assert"
8+
)
9+
10+
func TestGetTagsLine(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
tags map[string]*sdp.TagValue
14+
want string
15+
}{
16+
{
17+
name: "empty tags",
18+
tags: map[string]*sdp.TagValue{},
19+
want: "",
20+
},
21+
{
22+
name: "key only",
23+
tags: map[string]*sdp.TagValue{
24+
"key": {},
25+
},
26+
want: "`key` ",
27+
},
28+
{
29+
name: "auto tag without value",
30+
tags: map[string]*sdp.TagValue{
31+
"autoTag": {
32+
Value: &sdp.TagValue_AutoTagValue{
33+
AutoTagValue: &sdp.AutoTagValue{},
34+
},
35+
},
36+
},
37+
want: "`✨autoTag` ",
38+
},
39+
{
40+
name: "auto tag with value",
41+
tags: map[string]*sdp.TagValue{
42+
"autoTag": {
43+
Value: &sdp.TagValue_AutoTagValue{
44+
AutoTagValue: &sdp.AutoTagValue{
45+
Value: "value",
46+
},
47+
},
48+
},
49+
},
50+
want: "`✨autoTag|value` ",
51+
},
52+
{
53+
name: "user tag without value",
54+
tags: map[string]*sdp.TagValue{
55+
"userTag": {
56+
Value: &sdp.TagValue_UserTagValue{
57+
UserTagValue: &sdp.UserTagValue{},
58+
},
59+
},
60+
},
61+
want: "`userTag` ",
62+
},
63+
{
64+
name: "user tag with value",
65+
tags: map[string]*sdp.TagValue{
66+
"userTag": {
67+
Value: &sdp.TagValue_UserTagValue{
68+
UserTagValue: &sdp.UserTagValue{
69+
Value: "value",
70+
},
71+
},
72+
},
73+
},
74+
want: "`userTag|value` ",
75+
},
76+
{
77+
name: "mixed tags",
78+
tags: map[string]*sdp.TagValue{
79+
"autoTag": {
80+
Value: &sdp.TagValue_AutoTagValue{
81+
AutoTagValue: &sdp.AutoTagValue{
82+
Value: "value",
83+
},
84+
},
85+
},
86+
"userTag": {
87+
Value: &sdp.TagValue_UserTagValue{
88+
UserTagValue: &sdp.UserTagValue{
89+
Value: "value",
90+
},
91+
},
92+
},
93+
},
94+
want: "`✨autoTag|value` `userTag|value` ",
95+
},
96+
}
97+
98+
for _, tt := range tests {
99+
t.Run(tt.name, func(t *testing.T) {
100+
got := getTagsLine(tt.tags)
101+
assert.Equal(t, tt.want, got)
102+
})
103+
}
104+
}

cmd/changes_list_changes.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,18 @@ func printJson(_ context.Context, b []byte, prefix, id string, cmd *cobra.Comman
238238
return flagError{fmt.Sprintf("need --dir value to write to files\n\n%v", cmd.UsageString())}
239239
}
240240

241+
// attempt to create the directory
242+
err := os.MkdirAll(dir, 0755)
243+
if err != nil {
244+
return loggedError{
245+
err: err,
246+
fields: log.Fields{
247+
"output-dir": dir,
248+
},
249+
message: "failed to create output directory",
250+
}
251+
}
252+
241253
// write the change to a file
242254
fileName := fmt.Sprintf("%v/%v-%v.json", dir, prefix, id)
243255
file, err := os.Create(fileName)

cmd/comment.md

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
11
{{ $top := . -}}
2+
# <img alt="banner" src="{{ .AssetPath }}/banner_dark.svg#gh-dark-mode-only"><img alt="banner" src="{{ .AssetPath }}/banner_light.svg#gh-light-mode-only">
3+
{{ if .TagsLine -}}
4+
{{ .TagsLine }}
5+
{{ end -}}
6+
7+
# <img width="24" alt="warning" src="{{ .AssetPath }}/risks.svg"> Risks
8+
{{ if not .Risks }}
9+
Overmind has not identified any risks associated with this change.
10+
11+
This could be due to the change being low risk with no impact on other parts of the system, or involving resources that Overmind currently does not support.
12+
{{ else -}}
13+
{{ range .Risks }}
14+
## <img width="16" alt="{{ .SeverityAlt }}" src="{{ $top.AssetPath }}/{{ .SeverityIcon }}"> {{ .Title }} [{{ .SeverityText }}]
15+
16+
{{ .Description }} [Open Risk]({{ .RiskUrl }})
17+
{{ end }}
18+
{{ end -}}
19+
220
# <img width="24" alt="mapped" src="{{ .AssetPath }}/item.svg"> Expected Changes
321

422
{{ range .ExpectedChanges -}}
523
<details>
6-
<summary><img width="14" alt="{{ .StatusAlt }}" src="{{ $top.AssetPath }}/{{ .StatusIcon }}"> {{ .Type }} › {{ .Title }}</summary>
24+
<summary><img width="16" alt="{{ .StatusAlt }}" src="{{ $top.AssetPath }}/{{ .StatusIcon }}"> {{ .Type }} › {{ .Title }}</summary>
725

826
{{ if .Diff -}}
927
```diff
@@ -20,15 +38,15 @@ No expected changes found.
2038
{{ end }}
2139

2240
{{ if .UnmappedChanges -}}
23-
## <img width="20" alt="unmapped" src="{{ .AssetPath }}/unmapped.svg"> Unmapped Changes
41+
# <img width="24" alt="unmapped" src="{{ .AssetPath }}/unmapped.svg"> Unmapped Changes
2442

2543
> [!NOTE]
2644
> These changes couldn't be mapped to a discoverable cloud resource and therefore won't be included in the blast radius calculation.
2745
2846
{{ range .UnmappedChanges -}}
2947

3048
<details>
31-
<summary><img width="14" alt="{{ .StatusAlt }}" src="{{ $top.AssetPath }}/{{ .StatusIcon }}"> {{ .Type }} › {{ .Title }}</summary>
49+
<summary><img width="16" alt="{{ .StatusAlt }}" src="{{ $top.AssetPath }}/{{ .StatusIcon }}"> {{ .Type }} › {{ .Title }}</summary>
3250

3351
{{ if .Diff -}}
3452

@@ -44,23 +62,12 @@ No expected changes found.
4462
{{ end }}
4563
{{ end }}
4664

47-
# Blast Radius
65+
# <img width="24" alt="edges" src="{{ .AssetPath }}/edge.svg"> Blast Radius
4866

49-
| <img width="16" alt="items" src="{{ .AssetPath }}/item.svg"> Items | <img width="16" alt="edges" src="{{ .AssetPath }}/edge.svg"> Edges |
67+
| <img width="16" alt="items" src="{{ .AssetPath }}/item.svg"> Items | <img width="14" alt="edges" src="{{ .AssetPath }}/edge.svg"> Edges |
5068
| ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- |
5169
| {{ .BlastItems }} | {{ .BlastEdges }} |
5270

53-
[Open in Overmind]({{ .ChangeUrl }})
54-
55-
# <img width="24" alt="warning" src="{{ .AssetPath }}/risks.svg"> Risks
56-
{{ if not .Risks }}
57-
Overmind has not identified any risks associated with this change.
71+
[Open Blast Radius]({{ .BlastRadiusUrl }})
5872

59-
This could be due to the change being low risk with no impact on other parts of the system, or involving resources that Overmind currently does not support.
60-
{{ else -}}
61-
{{ range .Risks }}
62-
## <img width="18" alt="{{ .SeverityAlt }}" src="{{ $top.AssetPath }}/{{ .SeverityIcon }}"> {{ .Title }} [{{ .SeverityText }}]
63-
64-
{{ .Description }}
65-
{{ end }}
66-
{{ end -}}
73+
[<img alt="Open in Overmind" src="{{ .AssetPath }}/open_in_overmind.svg">]({{ .ChangeUrl }})

cmd/root.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func PreRunSetup(cmd *cobra.Command, args []string) {
7777

7878
// set up tracing
7979
if honeycombApiKey := viper.GetString("honeycomb-api-key"); honeycombApiKey != "" {
80-
if err := tracing.InitTracerWithUpstreams("cli", honeycombApiKey, ""); err != nil {
80+
if err := tracing.InitTracerWithUpstreams("overmind-cli", honeycombApiKey, ""); err != nil {
8181
log.Fatal(err)
8282
}
8383

@@ -578,7 +578,7 @@ func getAPIKeyToken(ctx context.Context, oi sdp.OvermindInstance, apiKey string,
578578
if !ok {
579579
return nil, fmt.Errorf("authenticated successfully against %s, but your API key is missing this permission: '%v'", app, missing)
580580
}
581-
pterm.Info.Println(fmt.Sprintf("Using Overmind API key for %s", app))
581+
log.WithField("app", app).Info("Using Overmind API key")
582582
return token, nil
583583
}
584584

sdp-go/changes.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,9 @@ func (cp *ChangeProperties) ToMap() map[string]any {
354354
"rawPlan": cp.GetRawPlan(),
355355
"codeChanges": cp.GetCodeChanges(),
356356
"repo": cp.GetRepo(),
357-
"tags": cp.GetTags(),
357+
"tags": cp.GetEnrichedTags(),
358+
"autoTaggingRuleSource": cp.GetAutoTaggingRuleSource().ToMessage(),
359+
"skippedAutoTags": cp.GetSkippedAutoTags(),
358360
}
359361
}
360362

@@ -429,6 +431,19 @@ func (s EndChangeResponse_State) ToMessage() string {
429431
}
430432
}
431433

434+
func (s ChangeProperties_AutoTaggingRuleSource) ToMessage() string {
435+
switch s {
436+
case ChangeProperties_AUTO_TAGGING_RULE_SOURCE_UNSPECIFIED:
437+
return "unknown"
438+
case ChangeProperties_AUTO_TAGGING_RULE_SOURCE_FILE:
439+
return "file"
440+
case ChangeProperties_AUTO_TAGGING_RULE_SOURCE_UI:
441+
return "ui"
442+
default:
443+
return "unknown"
444+
}
445+
}
446+
432447
// allow custom auto tag rules to be passed on the cli, via a yaml file
433448
//
434449
// rules:

0 commit comments

Comments
 (0)