jira_command 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/jira_command/cli.rb +7 -0
- data/lib/jira_command/command/assign.rb +12 -24
- data/lib/jira_command/command/config.rb +12 -1
- data/lib/jira_command/command/issue.rb +116 -49
- data/lib/jira_command/command/list.rb +25 -13
- data/lib/jira_command/command/sprint.rb +48 -0
- data/lib/jira_command/command/status.rb +2 -3
- data/lib/jira_command/command/transition.rb +0 -2
- data/lib/jira_command/command/user.rb +2 -3
- data/lib/jira_command/config.rb +1 -1
- data/lib/jira_command/jira/base.rb +2 -2
- data/lib/jira_command/jira/board.rb +27 -0
- data/lib/jira_command/jira/epic.rb +37 -0
- data/lib/jira_command/jira/issue.rb +18 -6
- data/lib/jira_command/jira/{issuetype.rb → issue_type.rb} +0 -0
- data/lib/jira_command/jira/list.rb +1 -0
- data/lib/jira_command/jira/sprint.rb +54 -0
- data/lib/jira_command/jira/status.rb +2 -2
- data/lib/jira_command/jira/transition.rb +2 -2
- data/lib/jira_command/jira/user.rb +1 -3
- data/lib/jira_command/prompt/base.rb +98 -0
- data/lib/jira_command/version.rb +1 -1
- metadata +8 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c1558b0814cb78718eb90f8b6959a76e0730baaf3e95fa40bac1cd8f30fdbb73
|
4
|
+
data.tar.gz: 68788d7679149d09614eb832b798ecc86fdac9ad1576edbe3d06690413864820
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b62c905b65fd122b12e4e0d538714d5cff372c011afc8e67cd3871f62c33358e7a172957cadce6b96f7edb85c50328a68fdf4a4f0847eb909814fbab2cee3757
|
7
|
+
data.tar.gz: ff91926ba9e2ec69ccd279f43e07485a6c1aa8f03ab02cab8cc1e6d56aa836465e07a274096f6e2df9d0cc6e89bf44df69644c5dd358b461f037a8653b8f5dff
|
data/Gemfile.lock
CHANGED
data/lib/jira_command/cli.rb
CHANGED
@@ -7,6 +7,7 @@ require_relative 'command/assign'
|
|
7
7
|
require_relative 'command/status'
|
8
8
|
require_relative 'command/transition'
|
9
9
|
require_relative 'command/issue'
|
10
|
+
require_relative 'command/sprint'
|
10
11
|
|
11
12
|
module JiraCommand
|
12
13
|
class CLI < Thor
|
@@ -17,5 +18,11 @@ module JiraCommand
|
|
17
18
|
register(JiraCommand::Command::Status, 'status', 'status', 'show all status in project')
|
18
19
|
register(JiraCommand::Command::Transition, 'transition', 'transition', 'transition issues')
|
19
20
|
register(JiraCommand::Command::Issue, 'issue', 'issue', 'create a issue')
|
21
|
+
register(JiraCommand::Command::Sprint, 'sprint', 'sprint', 'sprint related features')
|
22
|
+
|
23
|
+
desc 'version', 'show version'
|
24
|
+
def version
|
25
|
+
puts 'You are using: ' + JiraCommand::VERSION
|
26
|
+
end
|
20
27
|
end
|
21
28
|
end
|
@@ -3,45 +3,33 @@ require 'optparse'
|
|
3
3
|
require 'tty-prompt'
|
4
4
|
require_relative '../config'
|
5
5
|
require_relative '../jira/assign'
|
6
|
+
require_relative '../prompt/base'
|
6
7
|
|
7
8
|
module JiraCommand
|
8
9
|
module Command
|
9
10
|
class Assign < Thor
|
10
11
|
desc 'exec', 'assign to user'
|
11
|
-
option '
|
12
|
-
|
13
|
-
def exec
|
12
|
+
option 'refresh-user', aliases: 'u', required: false
|
13
|
+
def exec(issue_key)
|
14
14
|
config = JiraCommand::Config.new.read
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
user_api = JiraCommand::Jira::User.new(config)
|
23
|
-
user_api.all_list(project: project[:key])
|
24
|
-
end
|
25
|
-
|
26
|
-
prompt = TTY::Prompt.new
|
27
|
-
|
28
|
-
assignee = prompt.select('Who do you want to assign?') do |menu|
|
29
|
-
user_list.each do |user|
|
30
|
-
menu.choice name: user[:name], value: user[:account_id]
|
31
|
-
end
|
32
|
-
end
|
16
|
+
prompt_base = JiraCommand::Prompt::Base.new
|
17
|
+
assignee = prompt_base.select_user(
|
18
|
+
message: 'Who do you want to assign?',
|
19
|
+
project_key: issue_key.split('-').first,
|
20
|
+
refresh: !options['refresh-user'].nil?
|
21
|
+
)
|
33
22
|
|
34
23
|
assign = JiraCommand::Jira::Assign.new(config)
|
35
|
-
|
24
|
+
assign.execute(issue_key: issue_key, assignee: assignee)
|
36
25
|
end
|
37
26
|
|
38
27
|
desc 'clear', 'set to unassigned'
|
39
|
-
|
40
|
-
def clear
|
28
|
+
def clear(issue_key)
|
41
29
|
config = JiraCommand::Config.new.read
|
42
30
|
|
43
31
|
assign = JiraCommand::Jira::Assign.new(config)
|
44
|
-
assign.unassigne(issue_key:
|
32
|
+
assign.unassigne(issue_key: issue_key)
|
45
33
|
end
|
46
34
|
end
|
47
35
|
end
|
@@ -3,9 +3,10 @@ require 'thor'
|
|
3
3
|
require 'optparse'
|
4
4
|
require 'tty-prompt'
|
5
5
|
require_relative '../config'
|
6
|
-
require_relative '../jira/
|
6
|
+
require_relative '../jira/issue_type'
|
7
7
|
require_relative '../jira/project'
|
8
8
|
require_relative '../jira/user'
|
9
|
+
require_relative '../jira/board'
|
9
10
|
require 'base64'
|
10
11
|
|
11
12
|
module JiraCommand
|
@@ -62,6 +63,16 @@ module JiraCommand
|
|
62
63
|
JiraCommand::Config.new.write(config)
|
63
64
|
end
|
64
65
|
|
66
|
+
desc 'update_board', 'update default board in config file'
|
67
|
+
def update_board
|
68
|
+
config = JiraCommand::Config.new.read
|
69
|
+
agile_board = JiraCommand::Jira::Board.new(config)
|
70
|
+
config.merge!({
|
71
|
+
boards: agile_board.list
|
72
|
+
})
|
73
|
+
JiraCommand::Config.new.write(config)
|
74
|
+
end
|
75
|
+
|
65
76
|
desc 'clear', 'clear config file'
|
66
77
|
def clear
|
67
78
|
prompt = TTY::Prompt.new
|
@@ -1,79 +1,146 @@
|
|
1
1
|
require 'jira_command'
|
2
2
|
require_relative '../config'
|
3
|
-
require_relative '../
|
4
|
-
require_relative '../jira/
|
3
|
+
require_relative '../prompt/base'
|
4
|
+
require_relative '../jira/epic'
|
5
|
+
require_relative '../jira/board'
|
5
6
|
require_relative '../jira/issue'
|
7
|
+
require_relative '../jira/sprint'
|
6
8
|
|
7
9
|
module JiraCommand
|
8
10
|
module Command
|
9
11
|
class Issue < Thor
|
10
12
|
desc 'create', 'create new issue'
|
11
|
-
option 'refresh-project', aliases: '
|
12
|
-
option 'refresh-issue-type', aliases: '
|
13
|
-
option 'refresh-user', aliases: '
|
13
|
+
option 'refresh-project', aliases: 'p', required: false
|
14
|
+
option 'refresh-issue-type', aliases: 'i', required: false
|
15
|
+
option 'refresh-user', aliases: 'u', required: false
|
16
|
+
option 'refresh-board', aliases: 'b', required: false
|
14
17
|
def create
|
15
18
|
config = JiraCommand::Config.new.read
|
16
19
|
|
17
|
-
|
18
|
-
config['issue_types']
|
19
|
-
else
|
20
|
-
jira_issue_type = JiraCommand::Jira::IssueType.new(config)
|
21
|
-
jira_issue_type.list
|
22
|
-
end
|
20
|
+
prompt_base = JiraCommand::Prompt::Base.new
|
23
21
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
menu.choice name: item['name'], value: item['id']
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
projects = if options['refresh-project'].nil?
|
33
|
-
config['projects']
|
34
|
-
else
|
35
|
-
jira_project = JiraCommand::Jira::Project.new(config)
|
36
|
-
jira_project.list
|
37
|
-
end
|
38
|
-
|
39
|
-
project = prompt.select('Which project does the issue belong to?') do |menu|
|
40
|
-
projects.each do |item|
|
41
|
-
menu.choice name: item['name'], value: { id: item['id'], key: item['key'] }
|
42
|
-
end
|
43
|
-
end
|
22
|
+
issue_type = prompt_base.select_issue_type(
|
23
|
+
message: 'Which issue type do you want to create?',
|
24
|
+
refresh: !options['refresh-issue-type'].nil?
|
25
|
+
)
|
44
26
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
user_api.all_list(project: project[:key])
|
50
|
-
end
|
27
|
+
project = prompt_base.select_project(
|
28
|
+
message: 'Which project does the issue belong to?',
|
29
|
+
refresh: !options['refresh-project'].nil?
|
30
|
+
)
|
51
31
|
|
52
|
-
assignee =
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
32
|
+
assignee = prompt_base.select_user(
|
33
|
+
message: 'Who do you want to assign?',
|
34
|
+
refresh: !options['refresh-user'].nil?,
|
35
|
+
additional: [{ name: 'unassigned', value: nil }]
|
36
|
+
)
|
57
37
|
|
58
|
-
reporter =
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
38
|
+
reporter = prompt_base.select_user(
|
39
|
+
message: 'Who are you?',
|
40
|
+
refresh: !options['refresh-user'].nil?
|
41
|
+
)
|
63
42
|
|
43
|
+
prompt = TTY::Prompt.new
|
64
44
|
summary = prompt.ask('Please input issue summary: ')
|
65
45
|
description = prompt.ask('Please input issue description: ')
|
66
46
|
|
67
47
|
jira_issue = JiraCommand::Jira::Issue.new(config)
|
68
48
|
|
69
|
-
|
49
|
+
issue_key = jira_issue.create(
|
70
50
|
summary: summary,
|
71
51
|
description: description,
|
72
52
|
assignee: assignee,
|
73
53
|
reporter: reporter,
|
74
54
|
project_id: project[:id],
|
75
|
-
issuetype_id: issue_type
|
55
|
+
issuetype_id: issue_type[:id]
|
76
56
|
)
|
57
|
+
|
58
|
+
puts 'the created issue url: ' + config[:jira_url] + 'browse/' + issue_key
|
59
|
+
|
60
|
+
return if issue_type[:name] == 'Epic'
|
61
|
+
|
62
|
+
baord_list = if options['refresh-board'].nil?
|
63
|
+
config[:boards]
|
64
|
+
else
|
65
|
+
agile_board = JiraCommand::Jira::Board.new(config)
|
66
|
+
agile_board.list
|
67
|
+
end
|
68
|
+
|
69
|
+
target_board = baord_list.find { |item| item[:projectId].to_i == project[:id].to_i }
|
70
|
+
|
71
|
+
agile_epic = JiraCommand::Jira::Epic.new(config)
|
72
|
+
epics = agile_epic.list(board_id: target_board[:id])
|
73
|
+
|
74
|
+
epic_id = prompt.select('Which epic does the created issue belong to?') do |menu|
|
75
|
+
epics.each do |item|
|
76
|
+
menu.choice name: item[:name], value: item[:id]
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
agile_epic.move_issue(epic_id: epic_id, issue_key: issue_key)
|
81
|
+
|
82
|
+
exit 0 unless prompt.yes?('Do you want to attach to sprint?')
|
83
|
+
|
84
|
+
sprint_id = prompt_base.select_sprint(board_id: target_board[:id])
|
85
|
+
jira_sprint = JiraCommand::Jira::Sprint.new(config)
|
86
|
+
jira_sprint.move_issue(issue_key: issue_key, sprint_id: sprint_id)
|
87
|
+
end
|
88
|
+
|
89
|
+
desc 'comment', 'comment to issue'
|
90
|
+
option 'message', aliases: 'm', required: false
|
91
|
+
def comment(issue_key)
|
92
|
+
config = JiraCommand::Config.new.read
|
93
|
+
jira_comment = JiraCommand::Jira::Issue.new(config)
|
94
|
+
|
95
|
+
jira_comment.comment(issue_key: issue_key, message: options['message'])
|
96
|
+
end
|
97
|
+
|
98
|
+
desc 'attach_epic', 'attach epic to issue'
|
99
|
+
option 'refresh-board', aliases: 'b', required: false
|
100
|
+
def attach_epic(issue_key)
|
101
|
+
config = JiraCommand::Config.new.read
|
102
|
+
|
103
|
+
baord_list = if options['refresh-board'].nil?
|
104
|
+
config[:boards]
|
105
|
+
else
|
106
|
+
agile_board = JiraCommand::Jira::Board.new(config)
|
107
|
+
agile_board.list
|
108
|
+
end
|
109
|
+
|
110
|
+
target_board = baord_list.find { |item| item[:projectKey] == issue_key.split('-').first }
|
111
|
+
|
112
|
+
agile_epic = JiraCommand::Jira::Epic.new(config)
|
113
|
+
epics = agile_epic.list(board_id: target_board[:id])
|
114
|
+
|
115
|
+
prompt = TTY::Prompt.new
|
116
|
+
epic_id = prompt.select('Which epic does the created issue belong to?') do |menu|
|
117
|
+
epics.each do |item|
|
118
|
+
menu.choice name: item[:name], value: item[:id]
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
agile_epic.move_issue(epic_id: epic_id, issue_key: issue_key)
|
123
|
+
end
|
124
|
+
|
125
|
+
desc 'attach_sprint', 'attach epic to issue'
|
126
|
+
option 'refresh-board', aliases: 'b', required: false
|
127
|
+
def attach_sprint(issue_key)
|
128
|
+
config = JiraCommand::Config.new.read
|
129
|
+
|
130
|
+
baord_list = if options['refresh-board'].nil?
|
131
|
+
config[:boards]
|
132
|
+
else
|
133
|
+
agile_board = JiraCommand::Jira::Board.new(config)
|
134
|
+
agile_board.list
|
135
|
+
end
|
136
|
+
|
137
|
+
target_board = baord_list.find { |item| item[:projectKey] == issue_key.split('-').first }
|
138
|
+
|
139
|
+
sprint_id = JiraCommand::Prompt::Base.new.select_sprint(board_id: target_board[:id])
|
140
|
+
|
141
|
+
jira_sprint = JiraCommand::Jira::Sprint.new(config)
|
142
|
+
|
143
|
+
jira_sprint.move_issue(issue_key: issue_key, sprint_id: sprint_id)
|
77
144
|
end
|
78
145
|
end
|
79
146
|
end
|
@@ -4,6 +4,7 @@ require 'optparse'
|
|
4
4
|
require 'pry'
|
5
5
|
require_relative '../config'
|
6
6
|
require_relative '../jira/list'
|
7
|
+
require_relative '../jira/epic'
|
7
8
|
require 'tty-prompt'
|
8
9
|
require 'base64'
|
9
10
|
require 'terminal-table'
|
@@ -11,24 +12,20 @@ require 'terminal-table'
|
|
11
12
|
module JiraCommand
|
12
13
|
module Command
|
13
14
|
class List < Thor
|
14
|
-
default_command :
|
15
|
+
default_command :all
|
15
16
|
|
16
17
|
desc 'all', 'list issues'
|
18
|
+
option 'current', aliases: 'c', required: false
|
19
|
+
option 'unresolved', aliases: 'u', required: false
|
17
20
|
def all
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
show_in_console(config['jira_url'], issues_list['issues'])
|
22
|
-
end
|
21
|
+
jql = []
|
22
|
+
jql << 'sprint in openSprints()' unless options['current'].nil?
|
23
|
+
jql << 'status not in (resolved)' unless options['unresolved'].nil?
|
23
24
|
|
24
|
-
desc 'unresolved', 'list issues'
|
25
|
-
def unresolved
|
26
25
|
config = JiraCommand::Config.new.read
|
27
26
|
list = JiraCommand::Jira::List.new(config)
|
28
|
-
issues_list = list.list({
|
29
|
-
|
30
|
-
|
31
|
-
show_in_console(config['jira_url'], issues_list['issues'])
|
27
|
+
issues_list = list.list({ jql: jql.join('&') })
|
28
|
+
show_in_console(config[:jira_url], issues_list['issues'])
|
32
29
|
end
|
33
30
|
|
34
31
|
desc 'my', 'list your issues'
|
@@ -44,7 +41,22 @@ module JiraCommand
|
|
44
41
|
issues_list = list.list({ fields: 'id,key,status,issuetype,assignee,summary',
|
45
42
|
jql: jql.join('&') })
|
46
43
|
|
47
|
-
show_in_console(config[
|
44
|
+
show_in_console(config[:jira_url], issues_list['issues'])
|
45
|
+
end
|
46
|
+
|
47
|
+
desc 'without_epic', 'list your issues which has not epic'
|
48
|
+
def without_epic
|
49
|
+
config = JiraCommand::Config.new.read
|
50
|
+
agile_epic = JiraCommand::Jira::Epic.new(config)
|
51
|
+
|
52
|
+
jql = ["key in (#{agile_epic.issue_key_without_epic.join(', ')})"]
|
53
|
+
|
54
|
+
list = JiraCommand::Jira::List.new(config)
|
55
|
+
|
56
|
+
issues_list = list.list({ fields: 'id,key,status,issuetype,assignee,summary',
|
57
|
+
jql: jql.join('&') })
|
58
|
+
|
59
|
+
show_in_console(config[:jira_url], issues_list['issues'])
|
48
60
|
end
|
49
61
|
|
50
62
|
private
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'optparse'
|
3
|
+
require 'date'
|
4
|
+
require_relative '../config'
|
5
|
+
require_relative '../jira/sprint'
|
6
|
+
require_relative '../prompt/base'
|
7
|
+
|
8
|
+
module JiraCommand
|
9
|
+
module Command
|
10
|
+
class Sprint < Thor
|
11
|
+
desc 'list', 'list all sprints'
|
12
|
+
option 'future', aliases: 'f', required: false
|
13
|
+
option 'active', aliases: 'a', required: false
|
14
|
+
option 'closed', aliases: 'c', required: false
|
15
|
+
def list
|
16
|
+
config = JiraCommand::Config.new.read
|
17
|
+
|
18
|
+
board_id = JiraCommand::Prompt::Base.new.select_board
|
19
|
+
jira_sprint = JiraCommand::Jira::Sprint.new(config)
|
20
|
+
state = []
|
21
|
+
state << 'future' unless options['future'].nil?
|
22
|
+
state << 'active' unless options['active'].nil?
|
23
|
+
state << 'closed' unless options['closed'].nil?
|
24
|
+
res = jira_sprint.list(board_id: board_id, query: { state: state })
|
25
|
+
|
26
|
+
puts(res.map { |item| item[:name] })
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'create', 'create sprint'
|
30
|
+
option 'start_datetime', aliases: 's', required: true
|
31
|
+
option 'end_datetime', aliases: 'e', required: true
|
32
|
+
def create(name)
|
33
|
+
config = JiraCommand::Config.new.read
|
34
|
+
|
35
|
+
board_id = JiraCommand::Prompt::Base.new.select_board
|
36
|
+
|
37
|
+
jira_sprint = JiraCommand::Jira::Sprint.new(config)
|
38
|
+
|
39
|
+
jira_sprint.create(
|
40
|
+
name: name,
|
41
|
+
board_id: board_id,
|
42
|
+
start_date: DateTime.parse(options['start_datetime']).strftime('%Y-%m-%dT%H:%M:%S.%L+09:00'),
|
43
|
+
end_date: DateTime.parse(options['end_datetime']).strftime('%Y-%m-%dT%H:%M:%S.%L+09:00')
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -7,14 +7,13 @@ module JiraCommand
|
|
7
7
|
module Command
|
8
8
|
class Status < Thor
|
9
9
|
desc 'project', 'list status in specified project'
|
10
|
-
option 'project', aliases: 'p', required: true
|
11
10
|
def project
|
12
11
|
config = JiraCommand::Config.new.read
|
13
12
|
|
14
13
|
jira = JiraCommand::Jira::Status.new(config)
|
15
|
-
res = jira.list
|
14
|
+
res = jira.list
|
16
15
|
|
17
|
-
puts
|
16
|
+
puts(res.map { |item| item[:name] })
|
18
17
|
end
|
19
18
|
end
|
20
19
|
end
|
@@ -10,12 +10,11 @@ module JiraCommand
|
|
10
10
|
default_command :project
|
11
11
|
|
12
12
|
desc 'project', 'list issues in specified project'
|
13
|
-
|
14
|
-
def project
|
13
|
+
def project(pro)
|
15
14
|
config = JiraCommand::Config.new.read
|
16
15
|
|
17
16
|
user_api = JiraCommand::Jira::User.new(config)
|
18
|
-
user_api.show_assignable(project:
|
17
|
+
user_api.show_assignable(project: pro)
|
19
18
|
end
|
20
19
|
end
|
21
20
|
end
|
data/lib/jira_command/config.rb
CHANGED
@@ -13,11 +13,11 @@ module JiraCommand
|
|
13
13
|
|
14
14
|
def initialize(config)
|
15
15
|
@config = config
|
16
|
-
@conn = Faraday.new(url: config[
|
16
|
+
@conn = Faraday.new(url: config[:jira_url]) do |faraday|
|
17
17
|
faraday.request :url_encoded
|
18
18
|
faraday.headers['Accept'] = 'application/json'
|
19
19
|
faraday.headers['Content-Type'] = 'application/json'
|
20
|
-
faraday.headers['Authorization'] = 'Basic ' + @config[
|
20
|
+
faraday.headers['Authorization'] = 'Basic ' + @config[:header_token]
|
21
21
|
faraday.adapter Faraday.default_adapter
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'jira_command'
|
2
|
+
require 'json'
|
3
|
+
require 'faraday'
|
4
|
+
require_relative 'base'
|
5
|
+
|
6
|
+
module JiraCommand
|
7
|
+
module Jira
|
8
|
+
class Board < JiraCommand::Jira::Base
|
9
|
+
BASE_PATH = 'rest/agile/1.0/board'.freeze
|
10
|
+
|
11
|
+
def list
|
12
|
+
res = @conn.get(BASE_PATH)
|
13
|
+
|
14
|
+
body = JSON.parse(res.body)
|
15
|
+
|
16
|
+
body['values'].map do |item|
|
17
|
+
location = item['location']
|
18
|
+
{ name: item['name'],
|
19
|
+
id: item['id'],
|
20
|
+
projectId: location['projectId'],
|
21
|
+
projectName: location['projectName'],
|
22
|
+
projectKey: location['projectKey'] }
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'jira_command'
|
2
|
+
require 'json'
|
3
|
+
require 'faraday'
|
4
|
+
require 'pry'
|
5
|
+
require_relative 'base'
|
6
|
+
|
7
|
+
module JiraCommand
|
8
|
+
module Jira
|
9
|
+
class Epic < JiraCommand::Jira::Base
|
10
|
+
def list(board_id:)
|
11
|
+
res = @conn.get("rest/agile/1.0/board/#{board_id}/epic")
|
12
|
+
|
13
|
+
body = JSON.parse(res.body)
|
14
|
+
|
15
|
+
body['values'].map { |item| { name: item['name'], id: item['id'] } }
|
16
|
+
end
|
17
|
+
|
18
|
+
def move_issue(issue_key:, epic_id:)
|
19
|
+
@conn.post do |req|
|
20
|
+
req.url "rest/agile/1.0/epic/#{epic_id}/issue"
|
21
|
+
req.body = {
|
22
|
+
issues: [
|
23
|
+
issue_key
|
24
|
+
]
|
25
|
+
}.to_json
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def issue_key_without_epic
|
30
|
+
res = @conn.get('rest/agile/1.0/epic/none/issue')
|
31
|
+
body = JSON.parse(res.body)
|
32
|
+
|
33
|
+
body['issues'].map { |item| item['key'] }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -8,6 +8,15 @@ module JiraCommand
|
|
8
8
|
class Issue < JiraCommand::Jira::Base
|
9
9
|
BASE_PATH = 'rest/api/2/issue'.freeze
|
10
10
|
|
11
|
+
def comment(issue_key:, message:)
|
12
|
+
@conn.post do |req|
|
13
|
+
req.url "rest/api/2/issue/#{issue_key}/comment"
|
14
|
+
req.body = {
|
15
|
+
body: message
|
16
|
+
}.to_json
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
11
20
|
def create(summary:, description:, assignee:, reporter:, project_id:, issuetype_id:)
|
12
21
|
request_body = { fields: {
|
13
22
|
project: {
|
@@ -17,23 +26,26 @@ module JiraCommand
|
|
17
26
|
issuetype: {
|
18
27
|
id: issuetype_id
|
19
28
|
},
|
20
|
-
assignee: {
|
21
|
-
id: assignee
|
22
|
-
},
|
23
29
|
reporter: {
|
24
30
|
id: reporter
|
25
31
|
},
|
26
32
|
description: description
|
27
|
-
} }
|
33
|
+
} }
|
34
|
+
|
35
|
+
unless assignee.nil?
|
36
|
+
request_body.merge!(assignee: {
|
37
|
+
id: assignee
|
38
|
+
})
|
39
|
+
end
|
28
40
|
|
29
41
|
res = @conn.post do |req|
|
30
42
|
req.url BASE_PATH
|
31
|
-
req.body = request_body
|
43
|
+
req.body = request_body.to_json
|
32
44
|
end
|
33
45
|
|
34
46
|
body = JSON.parse(res.body)
|
35
47
|
|
36
|
-
|
48
|
+
body['key']
|
37
49
|
end
|
38
50
|
end
|
39
51
|
end
|
File without changes
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'jira_command'
|
2
|
+
require 'faraday'
|
3
|
+
require 'json'
|
4
|
+
require_relative 'base'
|
5
|
+
|
6
|
+
module JiraCommand
|
7
|
+
module Jira
|
8
|
+
class Sprint < JiraCommand::Jira::Base
|
9
|
+
# https://docs.atlassian.com/jira-software/REST/7.3.1/#agile/1.0/board/{boardId}/sprint-getAllSprints
|
10
|
+
def list(board_id:, query: {})
|
11
|
+
res = @conn.get("rest/agile/1.0/board/#{board_id}/sprint?" + URI.encode_www_form(query))
|
12
|
+
|
13
|
+
body = JSON.parse(res.body)
|
14
|
+
|
15
|
+
body['values'].map do |item|
|
16
|
+
{
|
17
|
+
name: item['name'],
|
18
|
+
id: item['id'],
|
19
|
+
state: item['state'],
|
20
|
+
start_date: item['startDate'],
|
21
|
+
end_date: item['endDate']
|
22
|
+
}
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def move_issue(issue_key:, sprint_id:)
|
27
|
+
@conn.post do |req|
|
28
|
+
req.url "rest/agile/1.0/sprint/#{sprint_id}/issue"
|
29
|
+
req.body = {
|
30
|
+
issues: [
|
31
|
+
issue_key
|
32
|
+
]
|
33
|
+
}.to_json
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# https://docs.atlassian.com/jira-software/REST/7.3.1/#agile/1.0/sprint-createSprint
|
38
|
+
def create(name:, board_id:, start_date:, end_date:)
|
39
|
+
request_body = {
|
40
|
+
name: name,
|
41
|
+
originBoardId: board_id
|
42
|
+
}
|
43
|
+
|
44
|
+
request_body.merge!({ startDate: start_date }) unless start_date.nil?
|
45
|
+
request_body.merge!({ endDate: end_date }) unless end_date.nil?
|
46
|
+
|
47
|
+
@conn.post do |req|
|
48
|
+
req.url 'rest/agile/1.0/sprint'
|
49
|
+
req.body = request_body.to_json
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -12,9 +12,9 @@ module JiraCommand
|
|
12
12
|
def list
|
13
13
|
res = @conn.get(BASE_PATH)
|
14
14
|
|
15
|
-
|
15
|
+
body = JSON.parse(res.body)
|
16
16
|
|
17
|
-
|
17
|
+
body.map { |item| { id: item['id'], name: item['untranslatedName'] } }
|
18
18
|
end
|
19
19
|
|
20
20
|
def transite(issue_key:, target_status_id:)
|
@@ -11,9 +11,9 @@ module JiraCommand
|
|
11
11
|
request_url = "rest/api/2/issue/#{issue_key}/transitions"
|
12
12
|
res = @conn.get(request_url)
|
13
13
|
|
14
|
-
|
14
|
+
body = JSON.parse(res.body)
|
15
15
|
|
16
|
-
|
16
|
+
body['transitions'].map { |item| { id: item['id'].to_i, name: item['name'] } }
|
17
17
|
end
|
18
18
|
|
19
19
|
def transite(issue_key:, target_transition_id:)
|
@@ -15,16 +15,14 @@ module JiraCommand
|
|
15
15
|
|
16
16
|
def all_list(project:)
|
17
17
|
request_url = BASE_PATH + project
|
18
|
-
|
19
18
|
res = @conn.get(request_url)
|
20
|
-
|
21
19
|
body = JSON.parse(res.body)
|
22
20
|
|
23
21
|
body.map { |item| { name: item['displayName'], account_id: item['accountId'] } }
|
24
22
|
end
|
25
23
|
|
26
24
|
def show_assignable(project:)
|
27
|
-
puts
|
25
|
+
puts(all_list(project: project).map { |item| item[:name] })
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require_relative '../config'
|
2
|
+
require_relative '../jira/sprint'
|
3
|
+
require_relative '../jira/user'
|
4
|
+
require_relative '../jira/issue_type'
|
5
|
+
require 'tty-prompt'
|
6
|
+
|
7
|
+
module JiraCommand
|
8
|
+
module Prompt
|
9
|
+
class Base
|
10
|
+
attr_writer :prompt, :config
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@prompt = TTY::Prompt.new
|
14
|
+
@config = JiraCommand::Config.new.read
|
15
|
+
end
|
16
|
+
|
17
|
+
def select_board(message: 'Please select board', refresh: false)
|
18
|
+
baord_list = if refresh
|
19
|
+
agile_board = JiraCommand::Jira::Board.new(@config)
|
20
|
+
agile_board.list
|
21
|
+
else
|
22
|
+
@config[:boards]
|
23
|
+
end
|
24
|
+
|
25
|
+
@prompt.select(message) do |menu|
|
26
|
+
baord_list.each do |item|
|
27
|
+
menu.choice name: item[:name], value: item[:id]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def select_issue_type(message:, refresh: false)
|
33
|
+
issue_types = if refresh
|
34
|
+
jira_issue_type = JiraCommand::Jira::IssueType.new(@config)
|
35
|
+
jira_issue_type.list
|
36
|
+
else
|
37
|
+
@config[:issue_types]
|
38
|
+
end
|
39
|
+
|
40
|
+
@prompt.select(message) do |menu|
|
41
|
+
issue_types.each do |item|
|
42
|
+
menu.choice name: item[:name], value: { id: item[:id], name: item[:name] }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def select_project(message:, refresh: false)
|
48
|
+
projects = if refresh
|
49
|
+
jira_project = JiraCommand::Jira::Project.new(@config)
|
50
|
+
jira_project.list
|
51
|
+
else
|
52
|
+
@config[:projects]
|
53
|
+
end
|
54
|
+
|
55
|
+
@prompt.select(message) do |menu|
|
56
|
+
projects.each do |item|
|
57
|
+
menu.choice name: item[:name], value: { id: item[:id], key: item[:key] }
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def select_user(message:,
|
63
|
+
project_key: nil,
|
64
|
+
refresh: false,
|
65
|
+
additional: [])
|
66
|
+
user_list = if refresh
|
67
|
+
user_api = JiraCommand::Jira::User.new(@config)
|
68
|
+
user_api.all_list(project: project_key)
|
69
|
+
else
|
70
|
+
@config[:users]
|
71
|
+
end
|
72
|
+
|
73
|
+
@prompt.select(message) do |menu|
|
74
|
+
additional.each do |item|
|
75
|
+
menu.choice name: item[:name], value: item[:account_id]
|
76
|
+
end
|
77
|
+
user_list.each do |item|
|
78
|
+
menu.choice name: item[:name], value: item[:account_id]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def select_sprint(message: 'Please select sprint:', board_id:, state: 'active,future')
|
84
|
+
jira_sprint = JiraCommand::Jira::Sprint.new(@config)
|
85
|
+
res = jira_sprint.list(
|
86
|
+
board_id: board_id,
|
87
|
+
query: { state: state }
|
88
|
+
)
|
89
|
+
|
90
|
+
@prompt.select(message) do |menu|
|
91
|
+
res.each do |item|
|
92
|
+
menu.choice name: item[:name], value: item[:id]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
data/lib/jira_command/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jira_command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- shengbo.xu
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -52,19 +52,24 @@ files:
|
|
52
52
|
- lib/jira_command/command/config.rb
|
53
53
|
- lib/jira_command/command/issue.rb
|
54
54
|
- lib/jira_command/command/list.rb
|
55
|
+
- lib/jira_command/command/sprint.rb
|
55
56
|
- lib/jira_command/command/status.rb
|
56
57
|
- lib/jira_command/command/transition.rb
|
57
58
|
- lib/jira_command/command/user.rb
|
58
59
|
- lib/jira_command/config.rb
|
59
60
|
- lib/jira_command/jira/assign.rb
|
60
61
|
- lib/jira_command/jira/base.rb
|
62
|
+
- lib/jira_command/jira/board.rb
|
63
|
+
- lib/jira_command/jira/epic.rb
|
61
64
|
- lib/jira_command/jira/issue.rb
|
62
|
-
- lib/jira_command/jira/
|
65
|
+
- lib/jira_command/jira/issue_type.rb
|
63
66
|
- lib/jira_command/jira/list.rb
|
64
67
|
- lib/jira_command/jira/project.rb
|
68
|
+
- lib/jira_command/jira/sprint.rb
|
65
69
|
- lib/jira_command/jira/status.rb
|
66
70
|
- lib/jira_command/jira/transition.rb
|
67
71
|
- lib/jira_command/jira/user.rb
|
72
|
+
- lib/jira_command/prompt/base.rb
|
68
73
|
- lib/jira_command/version.rb
|
69
74
|
homepage: https://github.com/xincere-inc/jira_command
|
70
75
|
licenses:
|