Class: JiraCommand::Command::Transition

Inherits:
Thor
  • Object
show all
Defined in:
lib/jira_command/command/transition.rb

Instance Method Summary collapse

Instance Method Details

#execObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/jira_command/command/transition.rb', line 12

def exec
  config = JiraCommand::Config.new.read

  jira = JiraCommand::Jira::Transition.new(config)
  res = jira.list(issue_key: options['issue'])

  prompt = TTY::Prompt.new

  target_transition_id = prompt.select('Which status do you want to transite?') do |menu|
    res.each do |transition|
      menu.choice name: transition[:name], value: transition[:id]
    end
  end

  jira.transite(issue_key: options['issue'], target_transition_id: target_transition_id)
end

#issueObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/jira_command/command/transition.rb', line 32

def issue
  jql = []
  jql << 'sprint in openSprints()' unless options['current'].nil?
  jql << 'assignee=currentUser()' unless options['mine'].nil?

  config = JiraCommand::Config.new.read

  list = JiraCommand::Jira::List.new(config)
  issues_list = list.list({ fields: 'key,status,assignee,summary',
                            jql: jql.join('&') })

  prompt = TTY::Prompt.new

  issue_key = prompt.select('Which issue do you want to transite?') do |menu|
    issues_list['issues'].map do |i|
      assignee = i['fields']['assignee']
      menu.choice(name: "#{assignee.nil? ? 'not assigned' : assignee['displayName']}: #{i['fields']['summary']}(#{i['fields']['status']['name']})",
                  value: i['key'])
    end
  end

  jira = JiraCommand::Jira::Transition.new(config)
  res = jira.list(issue_key: issue_key)

  target_transition_id = prompt.select('Which status do you want to transite?') do |menu|
    res.each do |transition|
      menu.choice name: transition[:name], value: transition[:id]
    end
  end

  jira.transite(issue_key: issue_key, target_transition_id: target_transition_id)
end