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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cea73244ce641f36e0e876f49e029291701ef1a807ac7b15813ee3af2bbfdfdf
4
- data.tar.gz: dd501f909e92abc15998aac96f50f02631841b2125a5a1ee69461de7cd16bce3
3
+ metadata.gz: 3f05e40d9433c30d78cd29862228c8b3da6fa23cc57390595ecc9bd8e389d73d
4
+ data.tar.gz: 567a2f1ff63266369bd6aabca971ff679b1021af6766228e19ab825fe34aa7ad
5
5
  SHA512:
6
- metadata.gz: 6c8f39c52acf21550017c6ef927776c9caebafdcf23fecf6444172c7a2040f1399d088cdb2f7e1f1c61bd90f3e4ea62673a4b80f9bb3a6d29287c00fd59a54bd
7
- data.tar.gz: d73713682bee77353203f16e226d94b333fe503524957d89bd2f280e31c65a601c1a5f071ae4777936e87b664427010a6ebf86ffa4e0f4000bc11492fb91ac88
6
+ metadata.gz: c72bc3a0990b27069e130ff6a7469779449e5893c51d1be1671a0057262a56e2ef45952e174c5787ee4131ee296a8f67e556a693500c411828c9e9bc8c81b9d9
7
+ data.tar.gz: 9af549c15131b5914b0691ebebc0d3eff7c3dbccbb2aa8480717a9d68c6f31f7fcab037ca55764a5d8bc76b6c557cf9c8f1ec96dc964f6dfe03be24e4b7d050e
data/Gemfile CHANGED
@@ -8,4 +8,5 @@ gem "octokit"
8
8
 
9
9
  group :development do
10
10
  gem "pry-byebug"
11
+ gem "rspec"
11
12
  end
@@ -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
@@ -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
@@ -5,7 +5,6 @@
5
5
  # do/don't comply with our team-wide standards for how github repositories
6
6
  # should be configured.
7
7
 
8
- require "bundler/setup"
9
8
  require "json"
10
9
  require "net/http"
11
10
  require "uri"
@@ -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) }
@@ -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
- .filter { |repo| repo["name"] =~ regexp }
15
+ .select { |repo| repo["name"] =~ regexp }
16
16
  .map { |repo| repo["name"] }
17
17
  end
18
18
 
@@ -1,7 +1,7 @@
1
1
  class RepositoryReport < GithubGraphQlClient
2
2
  attr_reader :organization, :repo_name, :team
3
3
 
4
- MASTER = "master"
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
- has_master_branch_protection: has_master_branch_protection?,
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("/")).filter do |team|
105
- team[:name] == team && team[:permission] == ADMIN
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 has_master_branch_protection?
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
- .filter { |edge| edge.dig("node", "pattern") == MASTER }
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.2
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-05-14 00:00:00.000000000 Z
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