Class: Dri::Commands::Fetch::Runbooks
Instance Method Summary
collapse
#add_color, #api_client, #bold, #command, #cursor, #editor, #pastel, #prompt, #spinner, #verify_config_exists
logger
Constructor Details
#initialize(options) ⇒ Runbooks
Returns a new instance of Runbooks.
11
12
13
|
# File 'lib/dri/commands/fetch/runbooks.rb', line 11
def initialize(options)
@options = options
end
|
Instance Method Details
#execute(folder: nil, _input: $stdin, output: $stdout) ⇒ Object
15
16
17
18
19
|
# File 'lib/dri/commands/fetch/runbooks.rb', line 15
def execute(folder: nil, _input: $stdin, output: $stdout)
return fetch_summary(output: output) unless folder
fetch_runbook("#{folder}/index.md", output: output)
end
|
#fetch_runbook(path, output:) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/dri/commands/fetch/runbooks.rb', line 34
def fetch_runbook(path, output:)
runbook = nil
spinner.run do
runbook = api_client.get_file(
path,
ref: 'main',
project_id: Utils::Constants::ProjectIDs::RUNBOOKS_PROJECT_ID
)
rescue Gitlab::Error::NotFound
logger.error "The runbook #{path} could not be found."
end
return unless runbook
content = Base64.decode64(runbook.content)
markdown(content, output)
end
|
#fetch_summary(output:) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/dri/commands/fetch/runbooks.rb', line 21
def fetch_summary(output:)
logger.info 'Fetching runbooks'
prompt = TTY::Prompt.new
runbooks = api_client.list_runbooks
return output.puts 'No runbooks could be found' if runbooks.empty?
choices = runbooks.map(&:path)
path = prompt.select('Which runbook would you like to look at?', choices)
fetch_runbook("#{path}/index.md", output: output)
end
|