Class: JiraCommand::Command::Issue

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

Instance Method Summary collapse

Instance Method Details

#attach_epic(issue_key) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/jira_command/command/issue.rb', line 100

def attach_epic(issue_key)
  config = JiraCommand::Config.new.read

  baord_list = if !config[:boards].nil? && options['refresh-board'].nil?
                 config[:boards]
               else
                 agile_board = JiraCommand::Jira::Board.new(config)
                 agile_board.list
               end

  target_board = baord_list.find { |item| item[:projectKey] == issue_key.split('-').first }

  agile_epic = JiraCommand::Jira::Epic.new(config)
  epics = agile_epic.list(board_id: target_board[:id])

  prompt = TTY::Prompt.new
  epic_id = prompt.select('Which epic does the created issue belong to?') do |menu|
    epics.each do |item|
      menu.choice name: item[:name], value: item[:id]
    end
  end

  agile_epic.move_issue(epic_id: epic_id, issue_key: issue_key)
end

#attach_sprint(issue_key) ⇒ Object



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/jira_command/command/issue.rb', line 127

def attach_sprint(issue_key)
  config = JiraCommand::Config.new.read

  baord_list = if !config[:boards].nil? && options['refresh-board'].nil?
                 config[:boards]
               else
                 agile_board = JiraCommand::Jira::Board.new(config)
                 agile_board.list
               end

  target_board = baord_list.find { |item| item[:projectKey] == issue_key.split('-').first }

  sprint_id = JiraCommand::Prompt::Base.new.select_sprint(board_id: target_board[:id])

  jira_sprint = JiraCommand::Jira::Sprint.new(config)

  jira_sprint.move_issue(issue_key: issue_key, sprint_id: sprint_id)
end

#comment(issue_key) ⇒ Object



91
92
93
94
95
96
# File 'lib/jira_command/command/issue.rb', line 91

def comment(issue_key)
  config = JiraCommand::Config.new.read
  jira_comment = JiraCommand::Jira::Issue.new(config)

  jira_comment.comment(issue_key: issue_key, message: options['message'])
end

#createObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/jira_command/command/issue.rb', line 17

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

  prompt_base = JiraCommand::Prompt::Base.new

  issue_type = prompt_base.select_issue_type(
    message: 'Which issue type do you want to create?',
    refresh: !options['refresh-issue-type'].nil?
  )

  project = prompt_base.select_project(
    message: 'Which project does the issue belong to?',
    refresh: !options['refresh-project'].nil?
  )

  assignee = prompt_base.select_user(
    message: 'Who do you want to assign?',
    refresh: !options['refresh-user'].nil?,
    additional: [{ name: 'unassigned', value: nil }]
  )

  reporter = prompt_base.select_user(
    message: 'Who are you?',
    refresh: !options['refresh-user'].nil?
  )

  prompt = TTY::Prompt.new
  summary = prompt.ask('Please input issue summary: ')
  description = prompt.ask('Please input issue description: ')

  jira_issue = JiraCommand::Jira::Issue.new(config)

  issue_key = jira_issue.create(
    summary: summary,
    description: description,
    assignee: assignee,
    reporter: reporter,
    project_id: project[:id],
    issuetype_id: issue_type[:id]
  )

  puts 'the created issue url: ' + config[:jira_url] + 'browse/' + issue_key

  return if issue_type[:name] == 'Epic'

  baord_list = if !config[:boards].nil? && options['refresh-board'].nil?
                 config[:boards]
               else
                 agile_board = JiraCommand::Jira::Board.new(config)
                 agile_board.list
               end

  target_board = baord_list.find { |item| item[:projectId].to_i == project[:id].to_i }

  agile_epic = JiraCommand::Jira::Epic.new(config)
  epics = agile_epic.list(board_id: target_board[:id])

  epic_id = prompt.select('Which epic does the created issue belong to?') do |menu|
    epics.each do |item|
      menu.choice name: item[:name], value: item[:id]
    end
  end

  agile_epic.move_issue(epic_id: epic_id, issue_key: issue_key)

  exit 0 unless prompt.yes?('Do you want to attach to sprint?')

  sprint_id = prompt_base.select_sprint(board_id: target_board[:id])
  jira_sprint = JiraCommand::Jira::Sprint.new(config)
  jira_sprint.move_issue(issue_key: issue_key, sprint_id: sprint_id)
end