Class: Speedflow::Plugin::Jira::Prompt

Inherits:
Object
  • Object
show all
Defined in:
lib/speedflow/plugin/jira/prompt.rb

Overview

Plugin prompt

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

Delegate

method - Method. args - Arguments. block - Block.

Returns wathever.



97
98
99
# File 'lib/speedflow/plugin/jira/prompt.rb', line 97

def method_missing(method, *args, &block)
  prompt.send(method, *args, &block)
end

Instance Attribute Details

#promptObject

Public: Prompt.

Returns <::Speedflow::Plugin::Prompt> instance.



104
105
106
# File 'lib/speedflow/plugin/jira/prompt.rb', line 104

def prompt
  @prompt ||= ::Speedflow::Plugin::Prompt.new
end

Instance Method Details

#errors(exception) ⇒ Object

Public: Errors from JIRA exception.

exception - JIRA::HTTPError.

Returns nothing.



82
83
84
85
86
87
88
# File 'lib/speedflow/plugin/jira/prompt.rb', line 82

def errors(exception)
  if exception.response.respond_to?('body')
    response = ::JSON.parse(exception.response.body)
    response['errors'].each { |k, v| prompt.warn "- #{k}: #{v}" }
    response['errorMessages'].each { |v| prompt.warn "- #{v}" }
  end
end

#issue(&issues) ⇒ Object

Public: Prompt issue.

issues - Hash of issues from block.

Returns String key of issue.



64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/speedflow/plugin/jira/prompt.rb', line 64

def issue(&issues)
  sel_issue = prompt.select('Choose the issue:') do |menu|
    menu.choice 'Retry search!', :retry
    yield(title).each do |v|
      menu.choice "#{v.summary} (#{v.key})", v.key
    end
  end

  sel_issue = issue(&issues) if sel_issue == :retry

  sel_issue
end

#issue_type(issue_types) ⇒ Object

Public: Prompt issue type.

issue_types - List of issue types.

Returns ID of issue type.



37
38
39
40
41
42
43
# File 'lib/speedflow/plugin/jira/prompt.rb', line 37

def issue_type(issue_types)
  prompt.select('Choose the issue type:') do |menu|
    issue_types.each do |issue_type|
      menu.choice "#{issue_type.name} (#{issue_type.id})", issue_type.id
    end
  end
end

#project(projects) ⇒ Object

Public: Prompt project.

projects - List of projects.

Returns String of project key.



24
25
26
27
28
29
30
# File 'lib/speedflow/plugin/jira/prompt.rb', line 24

def project(projects)
  prompt.select('Choose the project:') do |menu|
    projects.each do |project|
      menu.choice "#{project.name} (#{project.key})", project.key
    end
  end
end

#titleObject

Public: Prompt title.

Returns String of title.



15
16
17
# File 'lib/speedflow/plugin/jira/prompt.rb', line 15

def title
  ask('What is the title of issue?', required: true)
end

#transition(transitions) ⇒ Object

Public: Prompt transition.

projects - List of transitions.

Returns String of status key.



50
51
52
53
54
55
56
57
# File 'lib/speedflow/plugin/jira/prompt.rb', line 50

def transition(transitions)
  prompt.select('Choose the transition:') do |menu|
    transitions.each do |transition|
      menu.choice(
        "#{transition.name} (#{transition.id})", transition.id)
    end
  end
end