Class: Cimas::GitHub
- Inherits:
-
Object
- Object
- Cimas::GitHub
- Defined in:
- lib/cimas/github.rb
Overview
Octokit boundary: client construction, remote-to-slug mapping, and
the visibility-lookup fallback policy live here; the orchestrator
speaks in slugs. Pass client: to inject a stand-in for offline
specs (production code always omits it).
Instance Method Summary collapse
- #client ⇒ Object
-
#fetch_visibility(slug) ⇒ Object
True when the repo is GitHub-private.
-
#initialize(token: nil, client: nil) ⇒ GitHub
constructor
A new instance of GitHub.
-
#slug_for(remote) ⇒ Object
Maps any GitHub remote form (ssh://git@github.com/org/repo, git@github.com:org/repo.git, https://github.com/org/repo.git) to the
org/reposlug Octokit expects.
Constructor Details
#initialize(token: nil, client: nil) ⇒ GitHub
Returns a new instance of GitHub.
9 10 11 12 |
# File 'lib/cimas/github.rb', line 9 def initialize(token: nil, client: nil) @token = token @client = client end |
Instance Method Details
#client ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/cimas/github.rb', line 14 def client return @client if @client if @token.nil? raise "[ERROR] Please set GITHUB_TOKEN environment variable to use GitHub functions." end @client = Octokit::Client.new(access_token: @token) end |
#fetch_visibility(slug) ⇒ Object
True when the repo is GitHub-private. Falls back to true (no
accidental public template picks) when the API is unreachable.
37 38 39 40 41 42 43 44 45 |
# File 'lib/cimas/github.rb', line 37 def fetch_visibility(slug) client.repo(slug).private rescue Octokit::NotFound puts "[WARNING] Cannot fetch visibility for #{slug} (404); defaulting to `private` (safer)." true rescue StandardError => e puts "[WARNING] Visibility fetch failed for #{slug}: #{e.}; defaulting to `private` (safer)." true end |
#slug_for(remote) ⇒ Object
Maps any GitHub remote form (ssh://git@github.com/org/repo,
git@github.com:org/repo.git, https://github.com/org/repo.git) to
the org/repo slug Octokit expects.
26 27 28 29 30 31 32 33 |
# File 'lib/cimas/github.rb', line 26 def slug_for(remote) match = remote.to_s.match(%r{github\.com[/:](.+?)(?:\.git)?\z}) unless match raise "[ERROR] not a GitHub remote: #{remote.inspect} — cimas only operates on GitHub repositories." end match[1] end |