Class: Huborg::Client
- Inherits:
-
Object
- Object
- Huborg::Client
- Defined in:
- lib/huborg.rb
Overview
The class that interacts with organizational repositories.
-
#push_template! - push a file to all repositories
-
#clone_and_rebase! - download all repositories for the org
-
#audit_license - tooling to check the licenses of your org
-
#synchronize_mailmap! - ensure all git .mailmap files are synchronized
Constant Summary collapse
- DEFAULT_REPOSITORY_FILTER =
When listing repositories, this callable will return all repositories.
->(client, repo) { true }
Instance Method Summary collapse
-
#audit_license(skip_private: true, skip_archived: true, allowed_licenses: :all) ⇒ True
Responsible for logging (as an error) repositories that do not have a license.
-
#clone_and_rebase!(directory:, skip_forked: false, skip_archived: false, skip_dirty: true, force: false, shallow: false) ⇒ True
Clone all repositories (that match the #repository_filter for the given organization(s). Then and rebase any existing repositories.
-
#each_pull_request_with_repo(skip_archived: true, query: { state: :open}) {|responds, responds| ... } ⇒ Object
Yield each pull request, and associated repository that matches the given parameters.
-
#initialize(org_names:, logger: default_logger, github_access_token: default_access_token, repository_filter: DEFAULT_REPOSITORY_FILTER) ⇒ Client
constructor
A new instance of Client.
-
#list_repositories {|responds| ... } ⇒ True
List every repository that will be acted upon.
-
#push_template!(template:, filename:, overwrite: false) ⇒ True
Responsible for pushing the given template file to all of the organizations repositories.
-
#synchronize_mailmap!(template:, consolidated_template: template) ⇒ True
Responsible for taking a template that confirms to Git’s .mailmap file format (e.g. github.com/samvera/maintenance/blob/master/templates/MAILMAP) and adding in all .mailmap entries that exist within the organizations repositories.
Constructor Details
#initialize(org_names:, logger: default_logger, github_access_token: default_access_token, repository_filter: DEFAULT_REPOSITORY_FILTER) ⇒ Client
Returns a new instance of Client.
56 57 58 59 60 61 62 63 64 |
# File 'lib/huborg.rb', line 56 def initialize(org_names:, logger: default_logger, github_access_token: default_access_token, repository_filter: DEFAULT_REPOSITORY_FILTER) @org_names = Array(org_names) @logger = logger @client = Octokit::Client.new(access_token: github_access_token) @repository_filter = repository_filter end |
Instance Method Details
#audit_license(skip_private: true, skip_archived: true, allowed_licenses: :all) ⇒ True
Responsible for logging (as an error) repositories that do not have a license.
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/huborg.rb', line 140 def audit_license(skip_private: true, skip_archived: true, allowed_licenses: :all) license_list = Array(allowed_licenses) each_github_repository do |repo| next if skip_private && repo.private? next if skip_archived && repo.archived? if repo.license logger.info(%(#{repo.fullname} has "#{repo.license.key}")) next if allowed_licenses == :all next if license_list.include?(repo.license.key) logger.error(%(#{repo.full_name} has "#{repo.license.key}" which is not in #{license_list.inspect})) else logger.error("#{repo.full_name} is missing a license") end end true end |
#clone_and_rebase!(directory:, skip_forked: false, skip_archived: false, skip_dirty: true, force: false, shallow: false) ⇒ True
The Product Owner decided to set ‘shallow: false` as the default, as other local scripts run by them made use of those directory structures.
Clone all repositories (that match the #repository_filter for the given organization(s). Then and rebase any existing repositories.
Let’s say we have a Github Organization “penguin” which has the repositories “paradigm” and “raft”. In the above example, if we specified the ‘DIRECTORY` as “/Iceflow”, we would end up with the following local directory tree within /Iceflow:
.
└── penguin
├── paradigm
└── raft
In the case of ‘shallow: true`, we would have the following tree within /Iceflow:
.
├── paradigm
└── raft
257 258 259 260 261 262 263 264 |
# File 'lib/huborg.rb', line 257 def clone_and_rebase!(directory:, skip_forked: false, skip_archived: false, skip_dirty: true, force: false, shallow: false) each_github_repository do |repo| next if skip_archived && repo.archived? next if skip_forked && repo.fork? clone_and_rebase_one!(repo: repo, directory: directory, skip_dirty: skip_dirty, force: force, shallow: shallow) end true end |
#each_pull_request_with_repo(skip_archived: true, query: { state: :open}) {|responds, responds| ... } ⇒ Object
Yield each pull request, and associated repository that matches the given parameters
289 290 291 292 293 294 295 296 297 |
# File 'lib/huborg.rb', line 289 def each_pull_request_with_repo(skip_archived: true, query: { state: :open}) each_github_repository do |repo| next if skip_archived && repo.archived? fetch_rel_for(rel: :pulls, from: repo, query: query).each do |pull| yield(pull, repo) end end true end |
#list_repositories {|responds| ... } ⇒ True
List every repository that will be acted upon. This is primarily to provide extra assurance to the user.
325 326 327 328 329 330 331 |
# File 'lib/huborg.rb', line 325 def list_repositories each_github_repository do |repo| yield repo end true end |
#push_template!(template:, filename:, overwrite: false) ⇒ True
Verify that the template exists
This skips archived repositories
Responsible for pushing the given template file to all of the organizations repositories. As we are pushing changes to repositories, this process will skip archived repositories.
115 116 117 118 119 120 |
# File 'lib/huborg.rb', line 115 def push_template!(template:, filename:, overwrite: false) each_github_repository do |repo| push_template_to!(repo: repo, template: template, filename: filename, overwrite: overwrite) end true end |
#synchronize_mailmap!(template:, consolidated_template: template) ⇒ True
Ensure that this doesn’t create a pull request if nothing has changed.
Responsible for taking a template that confirms to Git’s .mailmap file format (e.g. github.com/samvera/maintenance/blob/master/templates/MAILMAP) and adding in all .mailmap entries that exist within the organizations repositories. This merged .mailmap is then pushed out, via a pull request, to all of the non-archived repositories.
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/huborg.rb', line 178 def synchronize_mailmap!(template:, consolidated_template: template) mailmap_lines = Set.new File.read(template).split("\n").each do |line| mailmap_lines << line unless line.empty? end each_github_repository do |repo| begin mailmap = client.contents(repo.full_name, path: '.mailmap') lines = mailmap.rels[:download].get.data lines.split("\n").each do |line| mailmap_lines << line end rescue Octokit::NotFound next end end # Write the contents to a file File.open(consolidated_template, "w+") do |file| mailmap_lines.to_a.sort.each do |line| file.puts line end end each_github_repository do |repo| next if repo.archived? push_template_to!(filename: ".mailmap", template: consolidated_template, repo: repo, overwrite: true) end true end |