Class: Marlens::GithubToJiraComment::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/marlens/github_to_jira_comment/cli.rb

Defined Under Namespace

Classes: ResolvedMarkdown

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env: ENV, out: $stdout, err: $stderr, github_client_factory: nil, jira_client_factory: nil, markdown_resolver_factory: nil, comment_poster_factory: nil) ⇒ CLI

Returns a new instance of CLI.



13
14
15
16
17
18
19
20
21
# File 'lib/marlens/github_to_jira_comment/cli.rb', line 13

def initialize(env: ENV, out: $stdout, err: $stderr, github_client_factory: nil, jira_client_factory: nil, markdown_resolver_factory: nil, comment_poster_factory: nil)
  @env = env
  @out = out
  @err = err
  @github_client_factory = github_client_factory
  @jira_client_factory = jira_client_factory
  @markdown_resolver_factory = markdown_resolver_factory
  @comment_poster_factory = comment_poster_factory
end

Class Method Details

.run(argv = ARGV, env: ENV, out: $stdout, err: $stderr, github_client_factory: nil, jira_client_factory: nil) ⇒ Object



9
10
11
# File 'lib/marlens/github_to_jira_comment/cli.rb', line 9

def self.run(argv = ARGV, env: ENV, out: $stdout, err: $stderr, github_client_factory: nil, jira_client_factory: nil)
  new(env:, out:, err:, github_client_factory:, jira_client_factory:).call(argv)
end

Instance Method Details

#call(argv) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/marlens/github_to_jira_comment/cli.rb', line 23

def call(argv)
  options = parse_options(argv.dup)
  missing = %i[github_url jira_url].select { |key| options[key].to_s.empty? }
  return fail_with("Missing required option(s): #{option_names(missing)}") unless missing.empty?

  source = github_client.fetch(options.fetch(:github_url))
  resolved = resolve_markdown(source.body, github_url: options.fetch(:github_url))
  result = post_comment(options.fetch(:jira_url), resolved)

  @out.puts(result.fetch("id") { result.fetch(:id) })
  0
rescue ArgumentError, KeyError, OptionParser::ParseError, RuntimeError => error
  fail_with(error.message)
end