cloud-platform-repository-checker 1.0.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +15 -0
- data/bin/check.rb +27 -0
- data/bin/cloud-platform-repository-checker +0 -1
- data/bin/list-master-repos.rb +31 -0
- data/lib/repository_lister.rb +1 -1
- data/lib/repository_report.rb +19 -6
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f05e40d9433c30d78cd29862228c8b3da6fa23cc57390595ecc9bd8e389d73d
|
4
|
+
data.tar.gz: 567a2f1ff63266369bd6aabca971ff679b1021af6766228e19ab825fe34aa7ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c72bc3a0990b27069e130ff6a7469779449e5893c51d1be1671a0057262a56e2ef45952e174c5787ee4131ee296a8f67e556a693500c411828c9e9bc8c81b9d9
|
7
|
+
data.tar.gz: 9af549c15131b5914b0691ebebc0d3eff7c3dbccbb2aa8480717a9d68c6f31f7fcab037ca55764a5d8bc76b6c557cf9c8f1ec96dc964f6dfe03be24e4b7d050e
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -5,6 +5,7 @@ GEM
|
|
5
5
|
public_suffix (>= 2.0.2, < 5.0)
|
6
6
|
byebug (11.1.3)
|
7
7
|
coderay (1.1.2)
|
8
|
+
diff-lcs (1.3)
|
8
9
|
faraday (1.0.1)
|
9
10
|
multipart-post (>= 1.2, < 3)
|
10
11
|
method_source (1.0.0)
|
@@ -19,6 +20,19 @@ GEM
|
|
19
20
|
byebug (~> 11.0)
|
20
21
|
pry (~> 0.13.0)
|
21
22
|
public_suffix (4.0.5)
|
23
|
+
rspec (3.9.0)
|
24
|
+
rspec-core (~> 3.9.0)
|
25
|
+
rspec-expectations (~> 3.9.0)
|
26
|
+
rspec-mocks (~> 3.9.0)
|
27
|
+
rspec-core (3.9.2)
|
28
|
+
rspec-support (~> 3.9.3)
|
29
|
+
rspec-expectations (3.9.2)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.9.0)
|
32
|
+
rspec-mocks (3.9.1)
|
33
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
+
rspec-support (~> 3.9.0)
|
35
|
+
rspec-support (3.9.3)
|
22
36
|
sawyer (0.8.2)
|
23
37
|
addressable (>= 2.3.5)
|
24
38
|
faraday (> 0.8, < 2.0)
|
@@ -29,6 +43,7 @@ PLATFORMS
|
|
29
43
|
DEPENDENCIES
|
30
44
|
octokit
|
31
45
|
pry-byebug
|
46
|
+
rspec
|
32
47
|
|
33
48
|
BUNDLED WITH
|
34
49
|
2.1.2
|
data/bin/check.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Script to list repositories in the ministryofjustice organisation whose names
|
4
|
+
# match a regular expression, and output a JSON report of how well they
|
5
|
+
# do/don't comply with our team-wide standards for how github repositories
|
6
|
+
# should be configured.
|
7
|
+
|
8
|
+
require "json"
|
9
|
+
require "net/http"
|
10
|
+
require "uri"
|
11
|
+
require "octokit"
|
12
|
+
|
13
|
+
require_relative "../lib/github_graph_ql_client"
|
14
|
+
require_relative "../lib/repository_lister"
|
15
|
+
require_relative "../lib/repository_report"
|
16
|
+
|
17
|
+
############################################################
|
18
|
+
|
19
|
+
params = {
|
20
|
+
organization: ENV.fetch("ORGANIZATION"),
|
21
|
+
regexp: Regexp.new(ENV.fetch("REGEXP")),
|
22
|
+
team: ENV.fetch("TEAM"),
|
23
|
+
github_token: ENV.fetch("GITHUB_TOKEN")
|
24
|
+
}
|
25
|
+
|
26
|
+
repo_name = ARGV.shift
|
27
|
+
pp RepositoryReport.new(params.merge(repo_name: repo_name)).fetch_repo_data
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# Script to list repositories in the ministryofjustice organisation whose names
|
4
|
+
# match a regular expression, and whose default branch is "master"
|
5
|
+
|
6
|
+
require "json"
|
7
|
+
require "net/http"
|
8
|
+
require "uri"
|
9
|
+
require "octokit"
|
10
|
+
|
11
|
+
require_relative "../lib/github_graph_ql_client"
|
12
|
+
require_relative "../lib/repository_lister"
|
13
|
+
require_relative "../lib/repository_report"
|
14
|
+
|
15
|
+
############################################################
|
16
|
+
|
17
|
+
params = {
|
18
|
+
organization: ENV.fetch("ORGANIZATION"),
|
19
|
+
regexp: Regexp.new(ENV.fetch("REGEXP")),
|
20
|
+
team: ENV.fetch("TEAM"),
|
21
|
+
github_token: ENV.fetch("GITHUB_TOKEN")
|
22
|
+
}
|
23
|
+
|
24
|
+
repositories = RepositoryLister.new(params)
|
25
|
+
.repository_names
|
26
|
+
.inject([]) do |arr, repo_name|
|
27
|
+
report = RepositoryReport.new(params.merge(repo_name: repo_name)).report
|
28
|
+
arr << report
|
29
|
+
end
|
30
|
+
|
31
|
+
repositories.filter { |report| report.fetch(:default_branch) == "master" }.each { |report| puts report.fetch(:name) }
|
data/lib/repository_lister.rb
CHANGED
@@ -12,7 +12,7 @@ class RepositoryLister < GithubGraphQlClient
|
|
12
12
|
# Returns a list of repository names which match `regexp`
|
13
13
|
def repository_names
|
14
14
|
list_repos
|
15
|
-
.
|
15
|
+
.select { |repo| repo["name"] =~ regexp }
|
16
16
|
.map { |repo| repo["name"] }
|
17
17
|
end
|
18
18
|
|
data/lib/repository_report.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class RepositoryReport < GithubGraphQlClient
|
2
2
|
attr_reader :organization, :repo_name, :team
|
3
3
|
|
4
|
-
|
4
|
+
MAIN_BRANCH = "main"
|
5
5
|
ADMIN = "admin"
|
6
6
|
PASS = "PASS"
|
7
7
|
FAIL = "FAIL"
|
@@ -23,6 +23,7 @@ class RepositoryReport < GithubGraphQlClient
|
|
23
23
|
{
|
24
24
|
organization: organization,
|
25
25
|
name: repo_name,
|
26
|
+
default_branch: default_branch,
|
26
27
|
url: repo_url,
|
27
28
|
status: status,
|
28
29
|
report: all_checks_result
|
@@ -45,7 +46,8 @@ class RepositoryReport < GithubGraphQlClient
|
|
45
46
|
|
46
47
|
def all_checks_result
|
47
48
|
@all_checks_result ||= {
|
48
|
-
|
49
|
+
default_branch_main: default_branch_main?,
|
50
|
+
has_main_branch_protection: has_main_branch_protection?,
|
49
51
|
requires_approving_reviews: has_branch_protection_property?("requiresApprovingReviews"),
|
50
52
|
requires_code_owner_reviews: has_branch_protection_property?("requiresCodeOwnerReviews"),
|
51
53
|
administrators_require_review: has_branch_protection_property?("isAdminEnforced"),
|
@@ -81,6 +83,9 @@ class RepositoryReport < GithubGraphQlClient
|
|
81
83
|
owner {
|
82
84
|
login
|
83
85
|
}
|
86
|
+
defaultBranchRef {
|
87
|
+
name
|
88
|
+
}
|
84
89
|
branchProtectionRules(first: 50) {
|
85
90
|
edges {
|
86
91
|
node {
|
@@ -98,11 +103,15 @@ class RepositoryReport < GithubGraphQlClient
|
|
98
103
|
]
|
99
104
|
end
|
100
105
|
|
106
|
+
def default_branch
|
107
|
+
repo_data.dig("data", "repository", "defaultBranchRef", "name")
|
108
|
+
end
|
109
|
+
|
101
110
|
def is_team_admin?
|
102
111
|
client = Octokit::Client.new(access_token: github_token)
|
103
112
|
|
104
|
-
client.repo_teams([organization, repo_name].join("/")).
|
105
|
-
|
113
|
+
client.repo_teams([organization, repo_name].join("/")).select do |t|
|
114
|
+
t[:name] == team && t[:permission] == ADMIN
|
106
115
|
end.any?
|
107
116
|
rescue Octokit::NotFound
|
108
117
|
# This happens if our token does not have permission to view repo settings
|
@@ -113,11 +122,15 @@ class RepositoryReport < GithubGraphQlClient
|
|
113
122
|
@rules ||= repo_data.dig("data", "repository", "branchProtectionRules", "edges")
|
114
123
|
end
|
115
124
|
|
116
|
-
def
|
125
|
+
def default_branch_main?
|
126
|
+
default_branch == MAIN_BRANCH
|
127
|
+
end
|
128
|
+
|
129
|
+
def has_main_branch_protection?
|
117
130
|
requiring_branch_protection_rules do |rules|
|
118
131
|
|
119
132
|
rules
|
120
|
-
.
|
133
|
+
.select { |edge| edge.dig("node", "pattern") == MAIN_BRANCH }
|
121
134
|
.any?
|
122
135
|
end
|
123
136
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloud-platform-repository-checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Salgado
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: octokit
|
@@ -27,7 +27,9 @@ dependencies:
|
|
27
27
|
description:
|
28
28
|
email: platforms@digital.justice.gov.uk
|
29
29
|
executables:
|
30
|
+
- check.rb
|
30
31
|
- cloud-platform-repository-checker
|
32
|
+
- list-master-repos.rb
|
31
33
|
extensions: []
|
32
34
|
extra_rdoc_files:
|
33
35
|
- README.md
|
@@ -36,7 +38,9 @@ files:
|
|
36
38
|
- Gemfile.lock
|
37
39
|
- LICENSE
|
38
40
|
- README.md
|
41
|
+
- bin/check.rb
|
39
42
|
- bin/cloud-platform-repository-checker
|
43
|
+
- bin/list-master-repos.rb
|
40
44
|
- env.example
|
41
45
|
- lib/github_graph_ql_client.rb
|
42
46
|
- lib/repository_lister.rb
|