jira_command 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6787ad878548e6092d77737601c0c13b79ed400a945fe8dfbe4e55ed6b76f96c
4
- data.tar.gz: bf378610ae5b94587a4cd4bfe45cf26c1bbb2ee3c87acaf7d0a98d5840f38a1d
3
+ metadata.gz: de9b915ed2af20b1590e31703459e748ef701601eeb3dd5ecb0be0ba1eb87675
4
+ data.tar.gz: 58664c3370e6ad144f03decdff7d43ad9c89a3dad494e51b2579a7cf24017d2c
5
5
  SHA512:
6
- metadata.gz: 3044777ddd6bcab9e4b4135521fba746bb07256cd76bfaafcf23a78be2e206297bc9de9ce65af3bda97546c1ef6b80dcab2850fcc4503c282928ccb8ee7f626f
7
- data.tar.gz: a96b1683fec16610cac9f4dc9b2cfe2eb30ed62fd42b6a8efe504ca3985177ce11f892f187c44d9885cc0a2dbae79382d902db105d440467586e8277675cf24d
6
+ metadata.gz: a802d9ee4afaf814ed424f1fe0a23823f7f998cedd96909f8f9ec2f826bd0360be61bde297330f1686e0cf03300a1b4f18f4f71cccdcbafa273e93d95a6910db
7
+ data.tar.gz: c7af75ea99e6a674e0fbc9d9ce24220a35e771ac91f17ade1b20e5042c37f48f1ae75a7185b703822bc417d5d2891154814bfd2dc406e5fc6ea19c7e6d92c224
@@ -1,4 +1,3 @@
1
-
2
1
  Style/FrozenStringLiteralComment:
3
2
  Enabled: false
4
3
 
@@ -45,7 +44,7 @@ Metrics/BlockLength:
45
44
  Max: 60
46
45
 
47
46
  Style/HashEachMethods:
48
- Enabled: true
47
+ Enabled: true
49
48
 
50
49
  Metrics/AbcSize:
51
50
  Max: 50
@@ -56,6 +55,9 @@ Style/AsciiComments:
56
55
  Style/ClassAndModuleChildren:
57
56
  Enabled: false
58
57
 
58
+ Metrics/ParameterLists:
59
+ Enabled: false
60
+
59
61
  Style/HashTransformKeys:
60
62
  Enabled: false
61
63
 
data/README.md CHANGED
@@ -22,6 +22,8 @@ Or install it yourself as:
22
22
 
23
23
  ## Usage
24
24
 
25
+ You need to get token in [JIRA](https://id.atlassian.com/manage-profile/security).
26
+
25
27
  ```bash
26
28
  $ jira_command config create
27
29
  > Please input your site url: https://<your-domain>.atlassian.net/
@@ -39,6 +41,50 @@ Commands:
39
41
  jira_command user # list all users
40
42
  ```
41
43
 
44
+ <b>the most useful commands</b>
45
+
46
+ ```
47
+ $ jira_command list help my
48
+ Usage:
49
+ jira_command list my
50
+
51
+ Options:
52
+ c, [--current=CURRENT]
53
+ u, [--unresolved=UNRESOLVED]
54
+
55
+ list your issues
56
+
57
+
58
+ $ jira_command list help my
59
+ Usage:
60
+ jira_command list my
61
+
62
+ Options:
63
+ c, [--current=CURRENT]
64
+ u, [--unresolved=UNRESOLVED]
65
+
66
+ list your issues
67
+
68
+ $ jira_command transition help issue
69
+ Usage:
70
+ jira_command transition issue
71
+
72
+ Options:
73
+ c, [--current=CURRENT]
74
+ m, [--mine=MINE]
75
+
76
+ transite issue status
77
+
78
+ $ jira_command assign help exec
79
+ Usage:
80
+ jira_command assign exec
81
+
82
+ Options:
83
+ i, [--issue=ISSUE]
84
+
85
+ assign to user
86
+ ```
87
+
42
88
  ## Development
43
89
 
44
90
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -6,6 +6,7 @@ require_relative 'command/user'
6
6
  require_relative 'command/assign'
7
7
  require_relative 'command/status'
8
8
  require_relative 'command/transition'
9
+ require_relative 'command/issue'
9
10
 
10
11
  module JiraCommand
11
12
  class CLI < Thor
@@ -15,5 +16,6 @@ module JiraCommand
15
16
  register(JiraCommand::Command::Assign, 'assign', 'assign', 'set or unset assign in issue')
16
17
  register(JiraCommand::Command::Status, 'status', 'status', 'show all status in project')
17
18
  register(JiraCommand::Command::Transition, 'transition', 'transition', 'transition issues')
19
+ register(JiraCommand::Command::Issue, 'issue', 'issue', 'create a issue')
18
20
  end
19
21
  end
@@ -7,9 +7,9 @@ require_relative '../jira/assign'
7
7
  module JiraCommand
8
8
  module Command
9
9
  class Assign < Thor
10
- desc 'assign', 'assign to user'
10
+ desc 'exec', 'assign to user'
11
11
  option 'issue', aliases: 'i', required: false
12
- def assign
12
+ def exec
13
13
  config = JiraCommand::Config.new.read
14
14
 
15
15
  user_api = JiraCommand::Jira::User.new(config)
@@ -1,7 +1,7 @@
1
1
  require 'jira_command'
2
2
  require 'thor'
3
3
  require 'optparse'
4
- require 'pry'
4
+ require 'tty-prompt'
5
5
  require_relative '../config'
6
6
  require 'base64'
7
7
 
@@ -0,0 +1,64 @@
1
+ require 'jira_command'
2
+ require_relative '../config'
3
+ require_relative '../jira/issuetype'
4
+ require_relative '../jira/project'
5
+ require_relative '../jira/issue'
6
+
7
+ module JiraCommand
8
+ module Command
9
+ class Issue < Thor
10
+ desc 'create', 'create new issue'
11
+ def create
12
+ config = JiraCommand::Config.new.read
13
+ jira_issue_type = JiraCommand::Jira::IssueType.new(config)
14
+ issue_types = jira_issue_type.list
15
+
16
+ prompt = TTY::Prompt.new
17
+
18
+ issue_type = prompt.select('Which issue type do you want to create?') do |menu|
19
+ issue_types.each do |item|
20
+ menu.choice name: item[:name], value: item[:id]
21
+ end
22
+ end
23
+
24
+ jira_project = JiraCommand::Jira::Project.new(config)
25
+ projects = jira_project.list
26
+
27
+ project = prompt.select('Which project does the issue belong to?') do |menu|
28
+ projects.each do |item|
29
+ menu.choice name: item[:name], value: { id: item[:id], key: item[:key] }
30
+ end
31
+ end
32
+
33
+ user_api = JiraCommand::Jira::User.new(config)
34
+ user_list = user_api.all_list(project: project[:key])
35
+
36
+ assignee = prompt.select('Who do you want to assign?') do |menu|
37
+ user_list.each do |user|
38
+ menu.choice name: user[:name], value: user[:account_id]
39
+ end
40
+ end
41
+
42
+ reporter = prompt.select('Who are you?') do |menu|
43
+ user_list.each do |user|
44
+ menu.choice name: user[:name], value: user[:account_id]
45
+ end
46
+ end
47
+
48
+ summary = prompt.ask('Please input issue summary: ')
49
+ description = prompt.ask('Please input issue description: ')
50
+
51
+ jira_issue = JiraCommand::Jira::Issue.new(config)
52
+
53
+ puts 'the created issue url: ' + jira_issue.create(
54
+ summary: summary,
55
+ description: description,
56
+ assignee: assignee,
57
+ reporter: reporter,
58
+ project_id: project[:id],
59
+ issuetype_id: issue_type
60
+ )
61
+ end
62
+ end
63
+ end
64
+ end
@@ -14,7 +14,7 @@ module JiraCommand
14
14
  jira = JiraCommand::Jira::Status.new(config)
15
15
  res = jira.list(project: options['project'])
16
16
 
17
- puts res.map { |item| item[:name] }
17
+ puts res.map(:name)
18
18
  end
19
19
  end
20
20
  end
@@ -46,7 +46,9 @@ module JiraCommand
46
46
 
47
47
  issue_key = prompt.select('Which issue do you want to transite?') do |menu|
48
48
  issues_list['issues'].map do |i|
49
- menu.choice name: "#{i['fields']['assignee'].nil? ? 'not assigned' : i['fields']['assignee']['displayName']}: #{i['fields']['summary']}(#{i['fields']['status']['name']})", value: i['key']
49
+ assignee = i['fields']['assignee']
50
+ menu.choice(name: "#{assignee.nil? ? 'not assigned' : assignee['displayName']}: #{i['fields']['summary']}(#{i['fields']['status']['name']})",
51
+ value: i['key'])
50
52
  end
51
53
  end
52
54
 
@@ -0,0 +1,40 @@
1
+ require 'jira_command'
2
+ require 'faraday'
3
+ require 'json'
4
+ require_relative 'base'
5
+
6
+ module JiraCommand
7
+ module Jira
8
+ class Issue < JiraCommand::Jira::Base
9
+ BASE_PATH = 'rest/api/2/issue'.freeze
10
+
11
+ def create(summary:, description:, assignee:, reporter:, project_id:, issuetype_id:)
12
+ request_body = { fields: {
13
+ project: {
14
+ id: project_id
15
+ },
16
+ summary: summary,
17
+ issuetype: {
18
+ id: issuetype_id
19
+ },
20
+ assignee: {
21
+ id: assignee
22
+ },
23
+ reporter: {
24
+ id: reporter
25
+ },
26
+ description: description
27
+ } }.to_json
28
+
29
+ res = @conn.post do |req|
30
+ req.url BASE_PATH
31
+ req.body = request_body
32
+ end
33
+
34
+ body = JSON.parse(res.body)
35
+
36
+ @config['jira_url'] + 'browse/' + body['key']
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ require 'jira_command'
2
+ require 'faraday'
3
+ require 'json'
4
+ require_relative 'base'
5
+
6
+ module JiraCommand
7
+ module Jira
8
+ class IssueType < JiraCommand::Jira::Base
9
+ BASE_PATH = 'rest/api/2/issuetype'.freeze
10
+
11
+ def list
12
+ res = @conn.get(BASE_PATH)
13
+ body = JSON.parse(res.body)
14
+
15
+ body.map { |item| { name: item['untranslatedName'], id: item['id'] } }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'jira_command'
2
+ require 'faraday'
3
+ require 'json'
4
+ require_relative 'base'
5
+
6
+ module JiraCommand
7
+ module Jira
8
+ class Project < JiraCommand::Jira::Base
9
+ BASE_PATH = 'rest/api/2/project'.freeze
10
+
11
+ def list
12
+ res = @conn.get(BASE_PATH)
13
+ body = JSON.parse(res.body)
14
+
15
+ body.map { |item| { name: item['name'], id: item['id'], key: item['key'] } }
16
+ end
17
+ end
18
+ end
19
+ end
@@ -9,7 +9,7 @@ module JiraCommand
9
9
  class Status < JiraCommand::Jira::Base
10
10
  BASE_PATH = 'rest/api/2/status'.freeze
11
11
 
12
- def list(project:)
12
+ def list
13
13
  res = @conn.get(BASE_PATH)
14
14
 
15
15
  res = JSON.parse(res.body)
@@ -20,7 +20,7 @@ module JiraCommand
20
20
  def transite(issue_key:, target_status_id:)
21
21
  request_url = "rest/api/2/issue/#{issue_key}/transitions"
22
22
 
23
- res = @conn.post do |req|
23
+ @conn.post do |req|
24
24
  req.url request_url
25
25
  req.body = { transition: { id: target_status_id } }.to_json
26
26
  end
@@ -19,7 +19,7 @@ module JiraCommand
19
19
  def transite(issue_key:, target_transition_id:)
20
20
  request_url = "rest/api/2/issue/#{issue_key}/transitions"
21
21
 
22
- res = @conn.post do |req|
22
+ @conn.post do |req|
23
23
  req.url request_url
24
24
  req.body = { transition: { id: target_transition_id } }.to_json
25
25
  end
@@ -24,7 +24,7 @@ module JiraCommand
24
24
  end
25
25
 
26
26
  def show_assignable(project:)
27
- puts all_list(project: project).map { |item| item[:name] }
27
+ puts all_list(project: project).map(:name)
28
28
  end
29
29
  end
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module JiraCommand
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.1.1'.freeze
3
3
  end
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.0
4
+ version: 0.1.1
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-20 00:00:00.000000000 Z
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -50,6 +50,7 @@ files:
50
50
  - lib/jira_command/cli.rb
51
51
  - lib/jira_command/command/assign.rb
52
52
  - lib/jira_command/command/config.rb
53
+ - lib/jira_command/command/issue.rb
53
54
  - lib/jira_command/command/list.rb
54
55
  - lib/jira_command/command/status.rb
55
56
  - lib/jira_command/command/transition.rb
@@ -57,7 +58,10 @@ files:
57
58
  - lib/jira_command/config.rb
58
59
  - lib/jira_command/jira/assign.rb
59
60
  - lib/jira_command/jira/base.rb
61
+ - lib/jira_command/jira/issue.rb
62
+ - lib/jira_command/jira/issuetype.rb
60
63
  - lib/jira_command/jira/list.rb
64
+ - lib/jira_command/jira/project.rb
61
65
  - lib/jira_command/jira/status.rb
62
66
  - lib/jira_command/jira/transition.rb
63
67
  - lib/jira_command/jira/user.rb