/
issue.sp
76 lines (72 loc) · 2.48 KB
/
issue.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
locals {
include_forks = "false"
}
benchmark "issue_best_practices" {
title = "Issue Best Practices"
description = "Best practices for your issues."
children = [
control.issue_has_assignee,
control.issue_has_labels,
control.issue_older_30_days
]
}
control "issue_has_assignee" {
title = "Issues should have at least 1 user assigned"
description = "Issues should have at least 1 assignee so it's clear who is responsible for it."
sql = <<-EOT
select
i.html_url as resource,
case
when jsonb_array_length(i.assignee_logins) < 1 then 'alarm'
when jsonb_array_length(i.assignee_logins) = 1 then 'ok'
-- More than 1 assignee could be ok, but let users know there's more than 1
else 'info'
end as status,
'#' || i.issue_number || ' ' || i.title || ' has ' || jsonb_array_length(i.assignee_logins) || ' assignee(s).' as reason,
i.repository_full_name
from
github_my_repository as r
left join github_issue as i on r.full_name = i.repository_full_name
where
r.fork = ${local.include_forks} and i.state = 'open'
EOT
}
control "issue_has_labels" {
title = "Issues should have labels applied"
description = "Labels help organize issues and provide users with more context."
sql = <<-EOT
select
i.html_url as resource,
case
when i.labels <> '[]' then 'ok'
else 'alarm'
end as status,
'#' || i.issue_number || ' ' || i.title || ' has ' || jsonb_array_length(i.labels) || ' label(s).' as reason,
i.repository_full_name
from
github_my_repository as r
left join github_issue as i on r.full_name = i.repository_full_name
where
r.fork = ${local.include_forks} and i.state = 'open'
EOT
}
control "issue_older_30_days" {
title = "Issues should not be open longer than 30 days"
description = "Issues should be resolved or closed in a timely manner."
sql = <<-EOT
select
i.html_url as resource,
case
when i.created_at <= (current_date - interval '30' day) then 'alarm'
else 'ok'
end as status,
'#' || i.issue_number || ' ' || i.title || ' created ' || to_char(i.created_at , 'DD-Mon-YYYY') ||
' (' || extract(day from current_timestamp - i.created_at) || ' days).' as reason,
i.repository_full_name
from
github_my_repository as r
left join github_issue as i on r.full_name = i.repository_full_name
where
r.fork = ${local.include_forks} and i.state = 'open'
EOT
}