@@ -2,18 +2,16 @@ use crate::finding::{Confidence, Severity};
2
2
3
3
use super :: { audit_meta, AuditState , Finding , Step , WorkflowAudit } ;
4
4
5
- pub ( crate ) struct UnpinnedUses {
6
- pub ( crate ) state : AuditState ,
7
- }
5
+ pub ( crate ) struct UnpinnedUses ;
8
6
9
7
audit_meta ! ( UnpinnedUses , "unpinned-uses" , "unpinned action reference" ) ;
10
8
11
9
impl WorkflowAudit for UnpinnedUses {
12
- fn new ( state : AuditState ) -> anyhow:: Result < Self >
10
+ fn new ( _state : AuditState ) -> anyhow:: Result < Self >
13
11
where
14
12
Self : Sized ,
15
13
{
16
- Ok ( Self { state } )
14
+ Ok ( Self )
17
15
}
18
16
19
17
fn audit_step < ' w > ( & self , step : & Step < ' w > ) -> anyhow:: Result < Vec < Finding < ' w > > > {
@@ -23,27 +21,22 @@ impl WorkflowAudit for UnpinnedUses {
23
21
return Ok ( vec ! [ ] ) ;
24
22
} ;
25
23
26
- // Check twice, complain once
27
- let mut found_unpinned = false ;
28
- let mut annotation = "" ;
29
- if self . state . pedantic {
30
- if uses. unpinned_sha ( ) {
31
- found_unpinned = true ;
32
- annotation = "action is not pinned to a hash ref" ;
33
- }
24
+ let ( annotation, severity) = if uses. unpinned ( ) {
25
+ (
26
+ "action is not pinned to a tag, branch, or hash ref" ,
27
+ Severity :: Medium ,
28
+ )
29
+ } else if uses. unhashed ( ) {
30
+ ( "action is not pinned to a hash ref" , Severity :: Low )
34
31
} else {
35
- if uses. unpinned ( ) {
36
- found_unpinned = true ;
37
- annotation = "action is not pinned to a tag, branch, or hash ref" ;
38
- }
39
- }
32
+ ( "" , Severity :: Informational )
33
+ } ;
40
34
41
- // If one of the checks failed, add a finding
42
- if found_unpinned {
35
+ if !annotation. is_empty ( ) {
43
36
findings. push (
44
37
Self :: finding ( )
45
38
. confidence ( Confidence :: High )
46
- . severity ( Severity :: Informational )
39
+ . severity ( severity )
47
40
. add_location (
48
41
step. location ( )
49
42
. with_keys ( & [ "uses" . into ( ) ] )
0 commit comments