Class: Discharger::SetupRunner::Commands::GithubPackagesCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Discharger::SetupRunner::Commands::GithubPackagesCommand
show all
- Defined in:
- lib/discharger/setup_runner/commands/github_packages_command.rb
Overview
Stores bundler credentials for a private GitHub Packages gem source
using the GitHub CLI, so Gemfiles don't need embedded tokens.
Credentials are written to the app's .bundle/config — keep .bundle
gitignored. Run this step before "bundler" in setup.yml.
Instance Attribute Summary
Attributes inherited from BaseCommand
#app_root, #config, #logger
Instance Method Summary
collapse
Methods inherited from BaseCommand
#initialize
Instance Method Details
#can_execute? ⇒ Boolean
40
41
42
|
# File 'lib/discharger/setup_runner/commands/github_packages_command.rb', line 40
def can_execute?
!source.to_s.empty?
end
|
#description ⇒ Object
44
45
46
|
# File 'lib/discharger/setup_runner/commands/github_packages_command.rb', line 44
def description
"Configure GitHub Packages credentials"
end
|
#execute ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/discharger/setup_runner/commands/github_packages_command.rb', line 13
def execute
unless gh_installed?
log "GitHub CLI (gh) not found; skipping. Install gh and rerun setup or `bundle install` may fail for #{source}"
return
end
unless authenticated? || login
log "Not logged in to GitHub; skipping. Run `gh auth login` and rerun setup."
return
end
username = gh("api", "user", "--jq", ".login")
token = gh("auth", "token")
if username.to_s.empty? || token.to_s.empty?
log "Could not read GitHub credentials from gh; skipping."
return
end
store_bundler_credentials(username, token)
if credentials_valid?(username, token)
log "Configured bundler credentials for #{source}"
else
log "#{source} rejected the stored credentials. Your gh token may lack " \
"the read:packages scope — run `gh auth refresh -s read:packages` and rerun setup."
end
end
|