cloud-platform-repository-checker 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e8cf546dab8f2551ca91e723bb23195baa4de9ca433c0b01f5cbd8d62405781
4
- data.tar.gz: 36787f13af08b887b4289964411164f0a8a636346f25002ea7d84170e644c257
3
+ metadata.gz: 3f05e40d9433c30d78cd29862228c8b3da6fa23cc57390595ecc9bd8e389d73d
4
+ data.tar.gz: 567a2f1ff63266369bd6aabca971ff679b1021af6766228e19ab825fe34aa7ad
5
5
  SHA512:
6
- metadata.gz: 2b04b7f8e2b4d75b273e19d65006a47fd65f5d8ef1c9e3d817c713fb716944686cd596b574deb54970dbda32cfe4387cad0097c525c9005ecaed8e8e12b80adb
7
- data.tar.gz: 01a1858cacaba240aa9a1193b39072518a70c7108b148ab0e9de04dd673e0dfa447a0d353f571307235b64083aead7740afad030dafeccf8b044370825c7bf92
6
+ metadata.gz: c72bc3a0990b27069e130ff6a7469779449e5893c51d1be1671a0057262a56e2ef45952e174c5787ee4131ee296a8f67e556a693500c411828c9e9bc8c81b9d9
7
+ data.tar.gz: 9af549c15131b5914b0691ebebc0d3eff7c3dbccbb2aa8480717a9d68c6f31f7fcab037ca55764a5d8bc76b6c557cf9c8f1ec96dc964f6dfe03be24e4b7d050e
@@ -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) }
@@ -1,7 +1,7 @@
1
1
  class RepositoryReport < GithubGraphQlClient
2
2
  attr_reader :organization, :repo_name, :team
3
3
 
4
- MAIN_BRANCHES = ["main", "master"] # We are changing to use "main" but many repos still use "master" as default branch
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,6 +46,7 @@ class RepositoryReport < GithubGraphQlClient
45
46
 
46
47
  def all_checks_result
47
48
  @all_checks_result ||= {
49
+ default_branch_main: default_branch_main?,
48
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"),
@@ -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,6 +103,10 @@ 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
 
@@ -113,11 +122,15 @@ class RepositoryReport < GithubGraphQlClient
113
122
  @rules ||= repo_data.dig("data", "repository", "branchProtectionRules", "edges")
114
123
  end
115
124
 
125
+ def default_branch_main?
126
+ default_branch == MAIN_BRANCH
127
+ end
128
+
116
129
  def has_main_branch_protection?
117
130
  requiring_branch_protection_rules do |rules|
118
131
 
119
132
  rules
120
- .select { |edge| MAIN_BRANCHES.include?(edge.dig("node", "pattern")) }
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.2.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-06-15 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
@@ -29,6 +29,7 @@ email: platforms@digital.justice.gov.uk
29
29
  executables:
30
30
  - check.rb
31
31
  - cloud-platform-repository-checker
32
+ - list-master-repos.rb
32
33
  extensions: []
33
34
  extra_rdoc_files:
34
35
  - README.md
@@ -39,6 +40,7 @@ files:
39
40
  - README.md
40
41
  - bin/check.rb
41
42
  - bin/cloud-platform-repository-checker
43
+ - bin/list-master-repos.rb
42
44
  - env.example
43
45
  - lib/github_graph_ql_client.rb
44
46
  - lib/repository_lister.rb