Skip to content

Commit 5cb9bb2

Browse files
committed
Make action name a required field
Fixes #66 This is a BREAKING CHANGE! We've found that specifying action name is best practice because it makes it easier to relate a failure back to which action failed. This makes naming an action no longer optional.
1 parent a6d2ea7 commit 5cb9bb2

File tree

10 files changed

+36
-45
lines changed

10 files changed

+36
-45
lines changed

examples/group-1.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ spec:
88
needs:
99
- bar
1010
actions:
11-
- description: foo1
11+
- name: action1
12+
description: foo1
1213
check:
1314
paths:
1415
- 'flig/bar/**/*'
@@ -21,7 +22,8 @@ spec:
2122
There is a good way to fix this, maybe...
2223
helpUrl: https://go.example.com/fixit
2324
required: false
24-
- description: foo2
25+
- name: action2
26+
description: foo2
2527
check:
2628
paths:
2729
- '*/*.txt'

examples/v1alpha/DoctorGroup.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ spec:
88
needs:
99
- bar
1010
actions:
11-
- description: foo1
11+
- name: action1
12+
description: foo1
1213
check:
1314
paths:
1415
- 'flig/bar/**/*'
@@ -21,7 +22,8 @@ spec:
2122
There is a good way to fix this, maybe...
2223
helpUrl: https://go.example.com/fixit
2324
required: false
24-
- description: foo2
25+
- name: action2
26+
description: foo2
2527
check:
2628
paths:
2729
- '*/*.txt'

schema/merged.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@
114114
"description": "An action is a single step used to check in a group. This is most commonly used to build a series of tasks for a system, like `ruby`, `python`, and databases.",
115115
"type": "object",
116116
"required": [
117-
"check"
117+
"check",
118+
"name"
118119
],
119120
"properties": {
120121
"check": {
@@ -142,12 +143,8 @@
142143
"nullable": true
143144
},
144145
"name": {
145-
"description": "Name of the \"action\". When not provided, it will be the index of the action within the group. This is used when reporting status to the users.",
146-
"type": [
147-
"string",
148-
"null"
149-
],
150-
"nullable": true
146+
"description": "Name of the \"action\" used when reporting status to the users.",
147+
"type": "string"
151148
},
152149
"required": {
153150
"description": "If false, the action is allowed to fail and let other actions in the group execute. Defaults to `true`.",

schema/v1alpha.com.github.scope.ScopeDoctorGroup.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@
130130
"description": "An action is a single step used to check in a group. This is most commonly used to build a series of tasks for a system, like `ruby`, `python`, and databases.",
131131
"type": "object",
132132
"required": [
133-
"check"
133+
"check",
134+
"name"
134135
],
135136
"properties": {
136137
"check": {
@@ -158,12 +159,8 @@
158159
"nullable": true
159160
},
160161
"name": {
161-
"description": "Name of the \"action\". When not provided, it will be the index of the action within the group. This is used when reporting status to the users.",
162-
"type": [
163-
"string",
164-
"null"
165-
],
166-
"nullable": true
162+
"description": "Name of the \"action\" used when reporting status to the users.",
163+
"type": "string"
167164
},
168165
"required": {
169166
"description": "If false, the action is allowed to fail and let other actions in the group execute. Defaults to `true`.",

schema/v1alpha.com.github.scope.ScopeKnownError.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@
130130
"description": "An action is a single step used to check in a group. This is most commonly used to build a series of tasks for a system, like `ruby`, `python`, and databases.",
131131
"type": "object",
132132
"required": [
133-
"check"
133+
"check",
134+
"name"
134135
],
135136
"properties": {
136137
"check": {
@@ -158,12 +159,8 @@
158159
"nullable": true
159160
},
160161
"name": {
161-
"description": "Name of the \"action\". When not provided, it will be the index of the action within the group. This is used when reporting status to the users.",
162-
"type": [
163-
"string",
164-
"null"
165-
],
166-
"nullable": true
162+
"description": "Name of the \"action\" used when reporting status to the users.",
163+
"type": "string"
167164
},
168165
"required": {
169166
"description": "If false, the action is allowed to fail and let other actions in the group execute. Defaults to `true`.",

schema/v1alpha.com.github.scope.ScopeReportLocation.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,8 @@
130130
"description": "An action is a single step used to check in a group. This is most commonly used to build a series of tasks for a system, like `ruby`, `python`, and databases.",
131131
"type": "object",
132132
"required": [
133-
"check"
133+
"check",
134+
"name"
134135
],
135136
"properties": {
136137
"check": {
@@ -158,12 +159,8 @@
158159
"nullable": true
159160
},
160161
"name": {
161-
"description": "Name of the \"action\". When not provided, it will be the index of the action within the group. This is used when reporting status to the users.",
162-
"type": [
163-
"string",
164-
"null"
165-
],
166-
"nullable": true
162+
"description": "Name of the \"action\" used when reporting status to the users.",
163+
"type": "string"
167164
},
168165
"required": {
169166
"description": "If false, the action is allowed to fail and let other actions in the group execute. Defaults to `true`.",

src/models/v1alpha/doctor_group.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,8 @@ pub struct DoctorFixPromptSpec {
6969
#[serde(rename_all = "camelCase")]
7070
#[schemars(deny_unknown_fields)]
7171
pub struct DoctorGroupActionSpec {
72-
/// Name of the "action". When not provided, it will be the index of the action within the group.
73-
/// This is used when reporting status to the users.
74-
pub name: Option<String>,
72+
/// Name of the "action" used when reporting status to the users.
73+
pub name: String,
7574

7675
/// A description of this specific action, used for information to the users.
7776
pub description: Option<String>,

src/shared/models/internal/doctor_group.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ impl TryFrom<V1AlphaDoctorGroup> for DoctorGroup {
7575

7676
fn try_from(model: V1AlphaDoctorGroup) -> Result<Self, Self::Error> {
7777
let mut actions: Vec<_> = Default::default();
78-
for (count, spec_action) in model.spec.actions.iter().enumerate() {
79-
actions.push(parse_action(count, &model, spec_action)?);
78+
for spec_action in model.spec.actions.iter() {
79+
actions.push(parse_action(&model, spec_action)?);
8080
}
8181

8282
Ok(DoctorGroup {
@@ -92,7 +92,6 @@ impl TryFrom<V1AlphaDoctorGroup> for DoctorGroup {
9292
}
9393

9494
fn parse_action(
95-
idx: usize,
9695
group_model: &V1AlphaDoctorGroup,
9796
action: &DoctorGroupActionSpec,
9897
) -> Result<DoctorGroupAction> {
@@ -123,7 +122,7 @@ fn parse_action(
123122
};
124123

125124
Ok(DoctorGroupAction {
126-
name: spec_action.name.unwrap_or_else(|| format!("{}", idx + 1)),
125+
name: spec_action.name,
127126
required: spec_action.required,
128127
description: spec_action
129128
.description
@@ -174,7 +173,7 @@ mod tests {
174173
assert_eq!(
175174
dg.actions[0],
176175
DoctorGroupAction {
177-
name: "1".to_string(),
176+
name: "action1".to_string(),
178177
required: false,
179178
description: "foo1".to_string(),
180179
fix: DoctorFix {
@@ -195,7 +194,7 @@ mod tests {
195194
assert_eq!(
196195
dg.actions[1],
197196
DoctorGroupAction {
198-
name: "2".to_string(),
197+
name: "action2".to_string(),
199198
required: true,
200199
description: "foo2".to_string(),
201200
fix: DoctorFix {

tests/scope_doctor.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ fn test_cache_invalidation() {
100100
result
101101
.success()
102102
.stdout(predicate::str::contains(
103-
"Check initially failed, fix was successful, group: \"setup\", name: \"1\"",
103+
"Check initially failed, fix was successful, group: \"setup\", name: \"install\"",
104104
))
105105
.stdout(predicate::str::contains("Failed to write updated cache to disk").not());
106106

@@ -109,7 +109,7 @@ fn test_cache_invalidation() {
109109
result
110110
.success()
111111
.stdout(predicate::str::contains(
112-
"Check was successful, group: \"setup\", name: \"1\"",
112+
"Check was successful, group: \"setup\", name: \"install\"",
113113
))
114114
.stdout(predicate::str::contains("Failed to write updated cache to disk").not());
115115

@@ -124,7 +124,7 @@ fn test_cache_invalidation() {
124124
result
125125
.success()
126126
.stdout(predicate::str::contains(
127-
"Check initially failed, fix was successful, group: \"setup\", name: \"1\"",
127+
"Check initially failed, fix was successful, group: \"setup\", name: \"install\"",
128128
))
129129
.stdout(predicate::str::contains("Failed to write updated cache to disk").not());
130130
}

tests/test-cases/file-cache-check/.scope/group.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ metadata:
55
description: Run dep install
66
spec:
77
actions:
8-
- check:
8+
- name: install
9+
check:
910
paths:
1011
- '**/requirements.txt'
1112
fix:

0 commit comments

Comments
 (0)