jira-cli 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +4 -0
- data/bin/jira +5 -0
- data/lib/jira.rb +13 -0
- data/lib/jira/constants.rb +5 -0
- data/lib/jira/install.rb +29 -0
- data/lib/jira/lookup.rb +80 -0
- data/lib/jira/mixins.rb +88 -0
- data/lib/jira/version.rb +10 -0
- metadata +95 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1899da7c2bc62844806201e66ec6efa76ae7aa2a
|
4
|
+
data.tar.gz: 7640f9a343f471738008aa88b4a1ada6b61ece5f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f1bb34acfcca4560898e0632de7d0c4ffc3dfcd096c13cdc2b80e758755d8c23813c4100f801323ed231cbeddef8dc847828eff065a879f7ae1b0ecae9fa47c2
|
7
|
+
data.tar.gz: 6c57048f99459abbac3f8185e4d022345d1ec799e4f544705bfe2a8c798d4d14cd102aea6bba0176cfb10556c9cf7c1c4e76008599327193883c7c47721df19d
|
data/README.md
ADDED
data/bin/jira
ADDED
data/lib/jira.rb
ADDED
data/lib/jira/install.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#
|
2
|
+
# Installation Script
|
3
|
+
#
|
4
|
+
|
5
|
+
module Jira
|
6
|
+
class CLI < Thor
|
7
|
+
|
8
|
+
desc "install", "Guides the user through JIRA installation"
|
9
|
+
def install
|
10
|
+
say self.jira_url_path
|
11
|
+
say self.jira_auth_path
|
12
|
+
|
13
|
+
create_file self.jira_url_path, nil, verbose:false do
|
14
|
+
self.cli.ask("Enter your JIRA URL: ")
|
15
|
+
end
|
16
|
+
|
17
|
+
create_file self.jira_auth_path, nil, verbose:false do
|
18
|
+
username = self.cli.ask("Enter your JIRA username: ")
|
19
|
+
password = self.cli.ask("Enter your JIRA password: ") do |q|
|
20
|
+
q.echo = false
|
21
|
+
end
|
22
|
+
"#{username}:#{password}"
|
23
|
+
end
|
24
|
+
|
25
|
+
self.discard_memoized
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
data/lib/jira/lookup.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
module Jira
|
2
|
+
class CLI < Thor
|
3
|
+
|
4
|
+
desc "summarize", "Outputs the summary of the input ticket"
|
5
|
+
def summarize(ticket=nil)
|
6
|
+
ticket ||= ex('git rev-parse --abbrev-ref HEAD')
|
7
|
+
json = self.query("issue/#{ticket}")
|
8
|
+
summary = json['fields']['summary']
|
9
|
+
status = json['fields']['status']['name']
|
10
|
+
self.mutex.synchronize do
|
11
|
+
say "#{self.colored_ticket(ticket)} "\
|
12
|
+
"#{self.colored_status(status).center(26)} "\
|
13
|
+
"#{self.colored_summary(summary)}"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
desc "all", "Summarizes all tickets that have local branches"
|
18
|
+
def all
|
19
|
+
tickets = []
|
20
|
+
branches = ex("git branch").delete("*").split("\n")
|
21
|
+
branches.each do |branch|
|
22
|
+
stripped = branch.strip
|
23
|
+
if !!stripped[/^[a-zA-Z]+-[0-9]+$/]
|
24
|
+
tickets << stripped
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
threads = []
|
29
|
+
tickets.each do |ticket|
|
30
|
+
threads << Thread.new{ self.summarize(ticket) }
|
31
|
+
end
|
32
|
+
threads.each{ |thread| thread.join }
|
33
|
+
end
|
34
|
+
|
35
|
+
protected
|
36
|
+
|
37
|
+
def colored_ticket(ticket)
|
38
|
+
"("\
|
39
|
+
"#{Thor::Shell::Color::RED}"\
|
40
|
+
"#{ticket}"\
|
41
|
+
"#{Thor::Shell::Color::CLEAR}"\
|
42
|
+
")"
|
43
|
+
end
|
44
|
+
|
45
|
+
def colored_status(status)
|
46
|
+
"["\
|
47
|
+
"#{Thor::Shell::Color::BLUE}"\
|
48
|
+
"#{status}"\
|
49
|
+
"#{Thor::Shell::Color::CLEAR}"\
|
50
|
+
"]"
|
51
|
+
end
|
52
|
+
|
53
|
+
def colored_summary(summary)
|
54
|
+
"#{Thor::Shell::Color::BOLD}"\
|
55
|
+
"#{Thor::Shell::Color::WHITE}"\
|
56
|
+
"#{summary}"\
|
57
|
+
"#{Thor::Shell::Color::CLEAR}"
|
58
|
+
end
|
59
|
+
|
60
|
+
def query(path)
|
61
|
+
response = self.client.get "#{self.jira_url}/rest/api/2/#{path}"
|
62
|
+
return JSON.parse(response.body)
|
63
|
+
end
|
64
|
+
|
65
|
+
def mutex
|
66
|
+
@mutex ||= Mutex.new
|
67
|
+
end
|
68
|
+
|
69
|
+
def client
|
70
|
+
self.mutex.synchronize do
|
71
|
+
return @client if !@client.nil?
|
72
|
+
@client = Faraday.new
|
73
|
+
username, password = self.jira_auth
|
74
|
+
@client.basic_auth(username, password)
|
75
|
+
return @client
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
end
|
data/lib/jira/mixins.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
module Jira
|
2
|
+
class CLI < Thor
|
3
|
+
|
4
|
+
require 'highline/import'
|
5
|
+
require 'json'
|
6
|
+
require 'faraday'
|
7
|
+
include Thor::Actions
|
8
|
+
include Thor::Shell
|
9
|
+
|
10
|
+
protected
|
11
|
+
|
12
|
+
#
|
13
|
+
# @return [String] JIRA endpoint
|
14
|
+
#
|
15
|
+
def jira_url
|
16
|
+
return @jira_url if !@jira_url.nil?
|
17
|
+
path = self.jira_url_path
|
18
|
+
self.validate_path!(path)
|
19
|
+
@jira_url ||= File.read(path).strip
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# @return [String] JIRA authorization
|
24
|
+
#
|
25
|
+
# @return [String] username
|
26
|
+
# @return [String] password
|
27
|
+
#
|
28
|
+
def jira_auth
|
29
|
+
if !@username.nil? && !@password.nil?
|
30
|
+
return @username, @password
|
31
|
+
end
|
32
|
+
path = self.jira_auth_path
|
33
|
+
self.validate_path!(path)
|
34
|
+
@username, @password = File.read(path).strip.split(':')
|
35
|
+
return @username, @password
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# @return [String] path to .jira-url file
|
40
|
+
#
|
41
|
+
def jira_url_path
|
42
|
+
@url_path ||= self.root_path + "/.jira-url"
|
43
|
+
end
|
44
|
+
|
45
|
+
#
|
46
|
+
# @return [String] path to .jira-auth file
|
47
|
+
#
|
48
|
+
def jira_auth_path
|
49
|
+
@auth_path ||= self.root_path + "/.jira-auth"
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# @return [String] path to root git directory
|
54
|
+
#
|
55
|
+
def root_path
|
56
|
+
@root_path ||= ex "git rev-parse --show-toplevel"
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# @return [Highline] HighLine instance for handling input
|
61
|
+
#
|
62
|
+
def cli
|
63
|
+
@highline ||= ::HighLine.new
|
64
|
+
end
|
65
|
+
|
66
|
+
#
|
67
|
+
# Execute shell command
|
68
|
+
#
|
69
|
+
# @param command [String] command to run
|
70
|
+
# @return [String] output of the run command
|
71
|
+
#
|
72
|
+
def ex(command)
|
73
|
+
run(command, verbose:false, capture:true).strip
|
74
|
+
end
|
75
|
+
|
76
|
+
def validate_path!(path)
|
77
|
+
if !File.exists?(path)
|
78
|
+
say "Please run `jira install` before running this action..."
|
79
|
+
abort
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def discard_memozied
|
84
|
+
@jira_url = nil
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
data/lib/jira/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jira-cli
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Darren Lin Cheng
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-05 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.18.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.18.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: highline
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.6.20
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.6.20
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: faraday
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.8.8
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.8.8
|
55
|
+
description: CLI used to manage JIRA workflows leveraging git
|
56
|
+
email: darren@thanx.com
|
57
|
+
executables:
|
58
|
+
- jira
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- bin/jira
|
63
|
+
- lib/jira/constants.rb
|
64
|
+
- lib/jira/install.rb
|
65
|
+
- lib/jira/lookup.rb
|
66
|
+
- lib/jira/mixins.rb
|
67
|
+
- lib/jira/version.rb
|
68
|
+
- lib/jira.rb
|
69
|
+
- README.md
|
70
|
+
homepage: http://rubygems.org/gems/jira-cli
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.1.4
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: JIRA CLI
|
94
|
+
test_files: []
|
95
|
+
has_rdoc:
|