Class: CreateTicket::CLI

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

Instance Method Summary collapse

Instance Method Details

#assigneeObject



32
33
34
# File 'lib/create_ticket/cli.rb', line 32

def assignee
  ENV.fetch('JIRA_ASSIGNEE')
end

#custom_fieldsObject



40
41
42
43
# File 'lib/create_ticket/cli.rb', line 40

def custom_fields
  ENV.select { |k, _| k.start_with? 'JIRA_CUSTOMFIELD' }.to_a
     .map { |k, v| [k.downcase.sub(/^jira_/, ''), v] }.to_h
end

#duedateObject



45
46
47
# File 'lib/create_ticket/cli.rb', line 45

def duedate
  ENV['JIRA_DUEDATE']
end

#issue_typeObject



36
37
38
# File 'lib/create_ticket/cli.rb', line 36

def issue_type
  ENV.fetch('JIRA_ISSUE_TYPE')
end

#jira_tokenObject



24
25
26
# File 'lib/create_ticket/cli.rb', line 24

def jira_token
  ENV.fetch('JIRA_TOKEN') { prompt_for_jira_token }
end

#jira_urlObject



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

def jira_url
  ENV.fetch('JIRA_URL')
end

#projectObject



13
14
15
# File 'lib/create_ticket/cli.rb', line 13

def project
  ENV.fetch('JIRA_PROJECT')
end

#prompt_for_jira_tokenObject



17
18
19
20
21
22
# File 'lib/create_ticket/cli.rb', line 17

def prompt_for_jira_token
  cli = HighLine.new
  username = cli.ask('Username: ')
  password = cli.ask('Password: ') { |q| q.echo = '*' }
  Base64.encode64 "#{username}:#{password}"
end

#run!Object



49
50
51
52
53
54
55
# File 'lib/create_ticket/cli.rb', line 49

def run!
  ticket_url = CreateTicket.new(self).create_ticket!
  puts ticket_url
rescue CouldNotCreateTicketError, KeyError, JSON::ParserError => e
  puts e.message
  exit 1
end

#template_filenameObject



28
29
30
# File 'lib/create_ticket/cli.rb', line 28

def template_filename
  ENV.fetch('TEMPLATE_FILENAME')
end