Class: JiraCommand::Prompt::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/jira_command/prompt/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



12
13
14
15
# File 'lib/jira_command/prompt/base.rb', line 12

def initialize
  @prompt = TTY::Prompt.new
  @config = JiraCommand::Config.new.read
end

Instance Attribute Details

#config=(value) ⇒ Object (writeonly)

Sets the attribute config

Parameters:

  • value

    the value to set the attribute config to.



10
11
12
# File 'lib/jira_command/prompt/base.rb', line 10

def config=(value)
  @config = value
end

#prompt=(value) ⇒ Object (writeonly)

Sets the attribute prompt

Parameters:

  • value

    the value to set the attribute prompt to.



10
11
12
# File 'lib/jira_command/prompt/base.rb', line 10

def prompt=(value)
  @prompt = value
end

Instance Method Details

#select_board(message: 'Please select board', refresh: false) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/jira_command/prompt/base.rb', line 17

def select_board(message: 'Please select board', refresh: false)
  baord_list = if @config[:boards].nil? || refresh
                 agile_board = JiraCommand::Jira::Board.new(@config)
                 agile_board.list
               else
                 @config[:boards]
               end

  @prompt.select(message) do |menu|
    baord_list.each do |item|
      menu.choice name: item[:name], value: item[:id]
    end
  end
end

#select_issue_type(message:, refresh: false) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jira_command/prompt/base.rb', line 32

def select_issue_type(message:, refresh: false)
  issue_types = if @config[:issue_types].nil? || refresh
                  jira_issue_type = JiraCommand::Jira::IssueType.new(@config)
                  jira_issue_type.list
                else
                  @config[:issue_types]
                end

  @prompt.select(message) do |menu|
    issue_types.each do |item|
      menu.choice name: item[:name], value: { id: item[:id], name: item[:name] }
    end
  end
end

#select_project(message:, refresh: false) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/jira_command/prompt/base.rb', line 47

def select_project(message:, refresh: false)
  projects = if @config[:projects].nil? || refresh
               jira_project = JiraCommand::Jira::Project.new(@config)
               jira_project.list
             else
               @config[:projects]
             end

  @prompt.select(message) do |menu|
    projects.each do |item|
      menu.choice name: item[:name], value: { id: item[:id], key: item[:key] }
    end
  end
end

#select_sprint(message: 'Please select sprint:', board_id:, state: 'active,future') ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/jira_command/prompt/base.rb', line 83

def select_sprint(message: 'Please select sprint:', board_id:, state: 'active,future')
  jira_sprint = JiraCommand::Jira::Sprint.new(@config)
  res = jira_sprint.list(
    board_id: board_id,
    query: { state: state }
  )

  @prompt.select(message) do |menu|
    res.each do |item|
      menu.choice name: item[:name], value: item[:id]
    end
  end
end

#select_user(message:, project_key: nil, refresh: false, additional: []) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/jira_command/prompt/base.rb', line 62

def select_user(message:,
                project_key: nil,
                refresh: false,
                additional: [])
  user_list = if @config[:users].nil? || refresh
                user_api = JiraCommand::Jira::User.new(@config)
                user_api.all_list(project: project_key)
              else
                @config[:users]
              end

  @prompt.select(message) do |menu|
    additional.each do |item|
      menu.choice name: item[:name], value: item[:account_id]
    end
    user_list.each do |item|
      menu.choice name: item[:name], value: item[:account_id]
    end
  end
end