forked from ursooperduper/ruby-findjiras
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfindjiras.rb
72 lines (57 loc) · 1.84 KB
/
findjiras.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
#!/usr/bin/env ruby
=begin
findjiras.rb
A stripped down Ruby port of the original Python-based findjiras script
authored by Kent Quirk. (https://bitbucket.org/kentquirk/findjiras)
Created by Sarah Kuehnle <[email protected]> on October 27, 2012
=end
require 'json'
require 'curb'
require 'yaml'
options = {
username: nil,
password: nil,
jira_url: nil,
projects: nil
}
CONFIG_FILE = File.join(ENV['HOME'], '.findjiras.yaml')
if File.exists? CONFIG_FILE
config_options = YAML.load_file(CONFIG_FILE)
options.merge!(config_options)
if options[:username] == nil || options[:password] == nil
puts "\nPlease edit your config file to include your Jira username and password."
else
jiras = Array.new
ARGF.each_line do |l|
jkeys = /(#{options[:projects]})-\d{1,6}/i.match(l)
if jkeys
jkeys = jkeys.to_s.upcase
if jiras.include?(jkeys) == false
jiras.push(jkeys)
end
end
end
def getkey(s)
p, v = s.split('-')
return [p, v.to_i]
end
jiras.sort! { |x, y| getkey(x) <=> getkey(y) }
jiras.each do |j|
jira_api_url_issues = "#{options[:jira_url]}/rest/api/latest/issue/#{j}?fields=summary"
c = Curl::Easy.http_get(jira_api_url_issues) do |curl|
curl.headers['Accept'] = 'application/json'
curl.headers['Content-Type'] = 'application/json'
curl.http_auth_types = :basic
curl.username = options[:username]
curl.password = options[:password]
end
c.perform
result = JSON.parse c.body_str
puts "[#{result['key']}] #{result['fields']['summary']}"
end
end
else
File.open(CONFIG_FILE, 'w') { |file| YAML::dump(options, file) }
puts "\nCreated configuration file in #{CONFIG_FILE}."
puts "Open that file and add your Jira username and password, then rerun this script.\n\n"
end