jira_command 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ require 'thor'
2
+ require 'optparse'
3
+ require 'pry'
4
+ require_relative '../config'
5
+ require_relative '../jira/user'
6
+
7
+ module JiraCommand
8
+ module Command
9
+ class User < Thor
10
+ default_command :project
11
+
12
+ desc 'project', 'list issues in specified project'
13
+ option 'project', aliases: 'p', required: true
14
+ def project
15
+ config = JiraCommand::Config.new.read
16
+
17
+ user_api = JiraCommand::Jira::User.new(config)
18
+ user_api.show_assignable(project: options['project'])
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ require 'jira_command'
2
+ require 'thor'
3
+ require 'optparse'
4
+ require 'pathname'
5
+ require 'fileutils'
6
+ require 'json'
7
+
8
+ module JiraCommand
9
+ class Config
10
+ CONFIG_PATH_CLASS = Pathname(ENV['HOME'] + '/.jira_command/config.json')
11
+
12
+ def read
13
+ unless FileTest.exists?(CONFIG_PATH_CLASS)
14
+ puts 'please create config file first'
15
+ exit 1
16
+ end
17
+
18
+ file = File.read(CONFIG_PATH_CLASS)
19
+ JSON.parse(file)
20
+ end
21
+
22
+ def self.check_exist
23
+ FileTest.exists?(CONFIG_PATH_CLASS)
24
+ end
25
+
26
+ def write(hash_params)
27
+ FileUtils.mkdir_p(CONFIG_PATH_CLASS.dirname) unless Dir.exist?(CONFIG_PATH_CLASS.dirname)
28
+
29
+ File.open(CONFIG_PATH_CLASS, 'w') do |f|
30
+ f.puts hash_params.to_json
31
+ end
32
+ end
33
+
34
+ def clear
35
+ FileUtils.rm(CONFIG_PATH_CLASS)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ require 'jira_command'
2
+ require 'thor'
3
+ require 'optparse'
4
+ require 'pry'
5
+ require 'pathname'
6
+ require 'fileutils'
7
+ require 'json'
8
+ require 'faraday'
9
+ require 'json'
10
+ require_relative 'base'
11
+
12
+ module JiraCommand
13
+ module Jira
14
+ class Assign < JiraCommand::Jira::Base
15
+ def execute(issue_key:, assignee:)
16
+ request_url = "rest/api/3/issue/#{issue_key}/assignee"
17
+ @conn.put do |req|
18
+ req.url request_url
19
+ req.body = { accountId: assignee }.to_json
20
+ end
21
+ end
22
+
23
+ def unassigne(issue_key:)
24
+ request_url = "rest/api/3/issue/#{issue_key}/assignee"
25
+ @conn.put do |req|
26
+ req.url request_url
27
+ req.body = { accountId: -1 }.to_json
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,26 @@
1
+ require 'jira_command'
2
+ require 'optparse'
3
+ require 'pry'
4
+ require 'pathname'
5
+ require 'fileutils'
6
+ require 'json'
7
+ require 'faraday'
8
+
9
+ module JiraCommand
10
+ module Jira
11
+ class Base
12
+ attr_writer :config, :conn
13
+
14
+ def initialize(config)
15
+ @config = config
16
+ @conn = Faraday.new(url: config['jira_url']) do |faraday|
17
+ faraday.request :url_encoded
18
+ faraday.headers['Accept'] = 'application/json'
19
+ faraday.headers['Content-Type'] = 'application/json'
20
+ faraday.headers['Authorization'] = 'Basic ' + @config['header_token']
21
+ faraday.adapter Faraday.default_adapter
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -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,23 @@
1
+ require 'jira_command'
2
+ require 'thor'
3
+ require 'optparse'
4
+ require 'pry'
5
+ require 'pathname'
6
+ require 'fileutils'
7
+ require 'json'
8
+ require 'faraday'
9
+ require_relative 'base'
10
+
11
+ module JiraCommand
12
+ module Jira
13
+ class List < JiraCommand::Jira::Base
14
+ BASE_PATH = 'rest/api/2/search?'.freeze
15
+
16
+ def list(query = {})
17
+ request_url = BASE_PATH + URI.encode_www_form(query)
18
+ res = @conn.get(request_url)
19
+ JSON.parse(res.body)
20
+ end
21
+ end
22
+ end
23
+ 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
@@ -0,0 +1,30 @@
1
+ require 'jira_command'
2
+ require 'pry'
3
+ require 'json'
4
+ require 'faraday'
5
+ require_relative 'base'
6
+
7
+ module JiraCommand
8
+ module Jira
9
+ class Status < JiraCommand::Jira::Base
10
+ BASE_PATH = 'rest/api/2/status'.freeze
11
+
12
+ def list
13
+ res = @conn.get(BASE_PATH)
14
+
15
+ res = JSON.parse(res.body)
16
+
17
+ res.map { |item| { id: item['id'], name: item['untranslatedName'] } }
18
+ end
19
+
20
+ def transite(issue_key:, target_status_id:)
21
+ request_url = "rest/api/2/issue/#{issue_key}/transitions"
22
+
23
+ @conn.post do |req|
24
+ req.url request_url
25
+ req.body = { transition: { id: target_status_id } }.to_json
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ require 'jira_command'
2
+ require 'pry'
3
+ require 'json'
4
+ require 'faraday'
5
+ require_relative 'base'
6
+
7
+ module JiraCommand
8
+ module Jira
9
+ class Transition < JiraCommand::Jira::Base
10
+ def list(issue_key:)
11
+ request_url = "rest/api/2/issue/#{issue_key}/transitions"
12
+ res = @conn.get(request_url)
13
+
14
+ res = JSON.parse(res.body)
15
+
16
+ res['transitions'].map { |item| { id: item['id'].to_i, name: item['name'] } }
17
+ end
18
+
19
+ def transite(issue_key:, target_transition_id:)
20
+ request_url = "rest/api/2/issue/#{issue_key}/transitions"
21
+
22
+ @conn.post do |req|
23
+ req.url request_url
24
+ req.body = { transition: { id: target_transition_id } }.to_json
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,31 @@
1
+ require 'jira_command'
2
+ require 'thor'
3
+ require 'optparse'
4
+ require 'pry'
5
+ require 'pathname'
6
+ require 'fileutils'
7
+ require 'json'
8
+ require 'faraday'
9
+ require_relative 'base'
10
+
11
+ module JiraCommand
12
+ module Jira
13
+ class User < JiraCommand::Jira::Base
14
+ BASE_PATH = 'rest/api/2/user/assignable/search?project='.freeze
15
+
16
+ def all_list(project:)
17
+ request_url = BASE_PATH + project
18
+
19
+ res = @conn.get(request_url)
20
+
21
+ body = JSON.parse(res.body)
22
+
23
+ body.map { |item| { name: item['displayName'], account_id: item['accountId'] } }
24
+ end
25
+
26
+ def show_assignable(project:)
27
+ puts all_list(project: project).map(:name)
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module JiraCommand
2
+ VERSION = '0.1.3'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jira_command
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - shengbo.xu
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: jira cli tool
28
+ email:
29
+ - shengbo.xu@xincere.jp
30
+ executables:
31
+ - jira_command
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - ".gitignore"
36
+ - ".rspec"
37
+ - ".rubocop.yml"
38
+ - ".travis.yml"
39
+ - CODE_OF_CONDUCT.md
40
+ - Gemfile
41
+ - Gemfile.lock
42
+ - LICENSE.txt
43
+ - README.md
44
+ - Rakefile
45
+ - bin/console
46
+ - bin/setup
47
+ - exe/jira_command
48
+ - jira_command.gemspec
49
+ - lib/jira_command.rb
50
+ - lib/jira_command/cli.rb
51
+ - lib/jira_command/command/assign.rb
52
+ - lib/jira_command/command/config.rb
53
+ - lib/jira_command/command/issue.rb
54
+ - lib/jira_command/command/list.rb
55
+ - lib/jira_command/command/status.rb
56
+ - lib/jira_command/command/transition.rb
57
+ - lib/jira_command/command/user.rb
58
+ - lib/jira_command/config.rb
59
+ - lib/jira_command/jira/assign.rb
60
+ - lib/jira_command/jira/base.rb
61
+ - lib/jira_command/jira/issue.rb
62
+ - lib/jira_command/jira/issuetype.rb
63
+ - lib/jira_command/jira/list.rb
64
+ - lib/jira_command/jira/project.rb
65
+ - lib/jira_command/jira/status.rb
66
+ - lib/jira_command/jira/transition.rb
67
+ - lib/jira_command/jira/user.rb
68
+ - lib/jira_command/version.rb
69
+ homepage: https://github.com/xincere-inc/jira_command
70
+ licenses:
71
+ - MIT
72
+ metadata:
73
+ homepage_uri: https://github.com/xincere-inc/jira_command
74
+ source_code_uri: https://github.com/xincere-inc/jira_command
75
+ changelog_uri: https://github.com/xincere-inc/jira_command
76
+ post_install_message:
77
+ rdoc_options: []
78
+ require_paths:
79
+ - lib
80
+ required_ruby_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: 2.3.0
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ requirements: []
91
+ rubygems_version: 3.0.3
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: jira cli
95
+ test_files: []