@@ -96,6 +96,8 @@ sourcetool status myorg/myrepo@mybranch
96
96
97
97
cmd .SilenceUsage = true
98
98
99
+ actions := []recommendedAction {}
100
+
99
101
ctx := context .Background ()
100
102
ghc := ghcontrol .NewGhConnection (opts .owner , opts .repository , opts .branch )
101
103
@@ -110,11 +112,20 @@ sourcetool status myorg/myrepo@mybranch
110
112
return err
111
113
}
112
114
115
+ // Get the active repository controls
113
116
controls , err := srctool .GetRepoControls ()
114
117
if err != nil {
115
118
return fmt .Errorf ("fetching active controls: %w" , err )
116
119
}
117
120
121
+ // Check if the user has a fork of the policy repo:
122
+ policyForkFound , err := srctool .CheckPolicyRepoFork ()
123
+ if err != nil {
124
+ return fmt .Errorf ("checking for a fork of the policy repo: %w" , err )
125
+ }
126
+
127
+ // Check if the user has a fork of the repository we want to protect
128
+
118
129
// Check if there is a policy:
119
130
pcy , _ , err := policy .NewPolicyEvaluator ().GetPolicy (ctx , ghc )
120
131
if err != nil {
@@ -125,7 +136,7 @@ sourcetool status myorg/myrepo@mybranch
125
136
toplevel := policy .ComputeEligibleSlsaLevel (controls )
126
137
127
138
title := fmt .Sprintf (
128
- "SLSA Source Status for %s/%s@%s" , opts .owner , opts .repository ,
139
+ "\n SLSA Source Status for %s/%s@%s" , opts .owner , opts .repository ,
129
140
ghcontrol .BranchToFullRef (opts .branch ),
130
141
)
131
142
fmt .Printf ("" )
@@ -137,14 +148,63 @@ sourcetool status myorg/myrepo@mybranch
137
148
if slices .Contains (controls .Names (), c ) {
138
149
fmt .Println ("✅" )
139
150
} else {
151
+ //nolint:exhaustive // We don't display all labels here
152
+ switch c {
153
+ case slsa .ProvenanceAvailable :
154
+ prdata , err := srctool .FindWorkflowPR ()
155
+ if err != nil {
156
+ return err
157
+ }
158
+
159
+ if prdata != nil {
160
+ fmt .Printf ("⏳ (PR %s/%s#%d waiting to merge)\n " , prdata .Owner , prdata .Repo , prdata .Number )
161
+ actions = append (actions , recommendedAction {
162
+ Text : "Merge provenance workflow pull request" ,
163
+ })
164
+ continue
165
+ }
166
+
167
+ actions = append (actions , recommendedAction {
168
+ Text : fmt .Sprintf ("Start generating provenance on %s/%s" , opts .owner , opts .repository ),
169
+ Command : fmt .Sprintf ("sourcetool setup controls --config=CONFIG_PROVENANCE_WORKFLOW %s/%s" , opts .owner , opts .repository ),
170
+ })
171
+ case slsa .ContinuityEnforced :
172
+ actions = append (actions , recommendedAction {
173
+ Text : "Enable branch push/delete protection" ,
174
+ Command : fmt .Sprintf ("sourcetool setup controls --config=CONFIG_BRANCH_RULES %s/%s" , opts .owner , opts .repository ),
175
+ })
176
+ }
140
177
fmt .Println ("🚫" )
141
178
}
142
179
}
143
180
144
181
fmt .Println ("" )
145
182
fmt .Printf ("%-35s " , "Repo policy found:" )
146
183
if pcy == nil {
147
- fmt .Println ("🚫" )
184
+ prdata , err := srctool .FindPolicyPR ()
185
+ if err != nil {
186
+ return fmt .Errorf ("looking for policy PR: %w" , err )
187
+ }
188
+
189
+ if prdata != nil {
190
+ fmt .Printf ("⏳ (PR %s/%s#%d waiting to merge)\n " , prdata .Owner , prdata .Repo , prdata .Number )
191
+ actions = append (actions , recommendedAction {
192
+ Text : "Wait for policy pull request to merge" ,
193
+ })
194
+ } else {
195
+ if policyForkFound {
196
+ actions = append (actions , recommendedAction {
197
+ Text : fmt .Sprintf ("Create and commit a source policy for %s/%s" , opts .owner , opts .repository ),
198
+ Command : fmt .Sprintf ("sourcetool setup controls --config=CONFIG_POLICY %s/%s" , opts .owner , opts .repository ),
199
+ })
200
+ } else {
201
+ actions = append (actions , recommendedAction {
202
+ Text : fmt .Sprintf ("Create a fork of the SLSA policies repo (%s)" , srctool .Options .PolicyRepo ),
203
+ Command : fmt .Sprintf ("Open https://github.com/%s/fork" , srctool .Options .PolicyRepo ),
204
+ })
205
+ }
206
+ fmt .Println ("🚫" )
207
+ }
148
208
} else {
149
209
fmt .Println ("✅" )
150
210
}
@@ -153,9 +213,24 @@ sourcetool status myorg/myrepo@mybranch
153
213
fmt .Println (w ("Current SLSA Source level: " + toplevel ))
154
214
fmt .Println ("" )
155
215
216
+ fmt .Println ("Recommended actions:" )
217
+
218
+ for _ , a := range actions {
219
+ fmt .Printf (" - %s\n " , a .Text )
220
+ if a .Command != "" {
221
+ fmt .Printf (" > %s\n " , a .Command )
222
+ }
223
+ fmt .Println ()
224
+ }
225
+
156
226
return nil
157
227
},
158
228
}
159
229
opts .AddFlags (statusCmd )
160
230
parentCmd .AddCommand (statusCmd )
161
231
}
232
+
233
+ type recommendedAction struct {
234
+ Text string
235
+ Command string
236
+ }
0 commit comments