Skip to content

Commit b3b21e8

Browse files
authored
✨ support impact by name (#5869)
* ✨ support impact by name You can now specify the impact as a name, instead of just a number. For example: ```yaml - uid: my-query title: A critical check that needs to succeed impact: critical ... ``` The keywords are: `critical`, `high`, `medium`, `low`, and `none`. Signed-off-by: Dominik Richter <dominik.richter@gmail.com> * 🟢 register 406 codes as being alive in the link checker See: gaurav-nelson/github-action-markdown-link-check#92 We are getting 406 on the arista links Signed-off-by: Dominik Richter <dominik.richter@gmail.com> --------- Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
1 parent 8c8e91c commit b3b21e8

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"aliveStatusCodes": [429, 200]
2+
"aliveStatusCodes": [429, 406, 200]
33
}

explorer/impact.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ func (v *Impact) HumanReadable() string {
2929
}
3030
}
3131

32+
var ImpactValues = map[string]int32{
33+
"critical": 95,
34+
"high": 80,
35+
"medium": 55,
36+
"low": 20,
37+
"none": 0,
38+
}
39+
3240
func (v *Impact) AddBase(base *Impact) {
3341
if base == nil {
3442
return
@@ -76,6 +84,16 @@ func (v *Impact) UnmarshalJSON(data []byte) error {
7684
return nil
7785
}
7886

87+
var word string
88+
if err := json.Unmarshal(data, &word); err == nil {
89+
num, ok := ImpactValues[word]
90+
if !ok {
91+
return errors.New("impact can only be critical, high, medium, low, or none or a numeric value")
92+
}
93+
v.Value = &ImpactValue{Value: num}
94+
return nil
95+
}
96+
7997
type tmp Impact
8098
return json.Unmarshal(data, (*tmp)(v))
8199
}

explorer/impact_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@ func TestImpactParsing(t *testing.T) {
1919
data string
2020
res *Impact
2121
}{
22-
{
23-
"simple number",
24-
"30",
25-
&Impact{
26-
Value: &ImpactValue{Value: 30},
27-
},
28-
},
22+
{"simple number", "30", &Impact{Value: &ImpactValue{Value: 30}}},
23+
{"critical", "\"critical\"", &Impact{Value: &ImpactValue{Value: 95}}},
24+
{"high", "\"high\"", &Impact{Value: &ImpactValue{Value: 80}}},
25+
{"medium", "\"medium\"", &Impact{Value: &ImpactValue{Value: 55}}},
26+
{"low", "\"low\"", &Impact{Value: &ImpactValue{Value: 20}}},
27+
{"none", "\"none\"", &Impact{Value: &ImpactValue{Value: 0}}},
2928
{
3029
"complex definition",
3130
`{"weight": 20, "value": 40}`,

0 commit comments

Comments
 (0)