fogbugz 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,54 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'fogbugz/common'
2
3
 
3
- require 'rubygems'
4
- require 'net/https'
5
- require 'uri'
6
- require 'rexml/document'
7
- require 'optparse'
8
-
9
- api_url = ENV['FOGBUGZ_API_URL']
10
- unless api_url
11
- puts "Environment variable FOGBUGZ_API_URL must be set."
12
- exit 1
13
- end
14
-
15
- api_token = ENV['FOGBUGZ_API_TOKEN']
16
- unless api_token
17
- puts "Environment variable FOGBUGZ_API_TOKEN must be set."
18
- exit 1
19
- end
20
-
21
- options = {}
22
- optparse = OptionParser.new do |opts|
23
- opts.banner = "usage: #{File::basename(__FILE__)} [options]"
24
-
25
- opts.on_tail('-h', '--help') do
26
- puts optparse.help
27
- exit 1
28
- end
29
- end
30
- optparse.parse!
31
-
32
- uri = URI format("#{api_url}?cmd=listPriorities&token=%s",
33
- URI.escape(api_token))
34
- http = Net::HTTP.new(uri.host, uri.port)
35
- if uri.scheme == 'https'
36
- http.use_ssl = true
37
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
38
- end
39
- response = http.start { |h| h.request Net::HTTP::Get.new(uri.request_uri) }
40
- if response.code != '200'
41
- puts "HTTP request to #{api_url} failed with code #{response.code}."
42
- exit 1
43
- end
44
-
45
- result = REXML::Document.new(response.body)
46
- error = result.elements['/response/error']
47
- if error
48
- puts "Failed with error: #{error.text}."
49
- exit 1
50
- end
51
-
52
- result.elements.each('/response/priorities/priority') do |priority|
53
- puts priority.elements['sPriority'].text
4
+ parse_opts "usage: #{File::basename(__FILE__)} [options]", 0
5
+ do_api('listPriorities').elements.each('/response/priorities/priority') do |p|
6
+ puts p.elements['sPriority'].text
54
7
  end
@@ -1,55 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'fogbugz/common'
2
3
 
3
- require 'rubygems'
4
- require 'net/https'
5
- require 'uri'
6
- require 'rexml/document'
7
- require 'optparse'
8
-
9
- api_url = ENV['FOGBUGZ_API_URL']
10
- unless api_url
11
- puts "Environment variable FOGBUGZ_API_URL must be set."
12
- exit 1
13
- end
14
-
15
- api_token = ENV['FOGBUGZ_API_TOKEN']
16
- unless api_token
17
- puts "Environment variable FOGBUGZ_API_TOKEN must be set."
18
- exit 1
19
- end
20
-
21
- options = {}
22
- optparse = OptionParser.new do |opts|
23
- opts.banner = "usage: #{File::basename(__FILE__)} [options]"
24
-
25
- opts.on_tail('-h', '--help') do
26
- puts optparse.help
27
- exit 1
28
- end
29
- end
30
- optparse.parse!
31
-
32
- uri = URI format("#{api_url}?cmd=listProjects&token=%s", URI.escape(api_token))
33
- http = Net::HTTP.new(uri.host, uri.port)
34
- if uri.scheme == 'https'
35
- http.use_ssl = true
36
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
37
- end
38
- response = http.start { |h| h.request Net::HTTP::Get.new(uri.request_uri) }
39
- if response.code != '200'
40
- puts "HTTP request to #{api_url} failed with code #{response.code}."
41
- exit 1
42
- end
43
-
44
- result = REXML::Document.new(response.body)
45
- error = result.elements['/response/error']
46
- if error
47
- puts "Failed with error: #{error.text}."
48
- exit 1
49
- end
50
-
51
- result.elements.each('/response/projects/project') do |project|
4
+ parse_opts "usage: #{File::basename(__FILE__)} [options]", 0
5
+ do_api('listProjects').elements.each('/response/projects/project') do |p|
52
6
  puts format("%-20.20s %s\n",
53
- project.elements['sPersonOwner'].text,
54
- project.elements['sProject'].text).strip!
7
+ p.elements['sPersonOwner'].text,
8
+ p.elements['sProject'].text).strip!
55
9
  end
@@ -28,7 +28,8 @@ optparse = OptionParser.new do |opts|
28
28
  end
29
29
  end
30
30
  optparse.parse!
31
- unless ARGV[0]
31
+
32
+ unless ARGV.length == 1
32
33
  puts optparse.help
33
34
  exit 1
34
35
  end
@@ -28,7 +28,8 @@ optparse = OptionParser.new do |opts|
28
28
  end
29
29
  end
30
30
  optparse.parse!
31
- unless ARGV[0]
31
+
32
+ unless ARGV.length == 1
32
33
  puts optparse.help
33
34
  exit 1
34
35
  end
@@ -1,58 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'fogbugz/common'
2
3
 
3
- require 'rubygems'
4
- require 'net/https'
5
- require 'uri'
6
- require 'rexml/document'
7
- require 'optparse'
8
-
9
- api_url = ENV['FOGBUGZ_API_URL']
10
- unless api_url
11
- puts "Environment variable FOGBUGZ_API_URL must be set."
12
- exit 1
13
- end
14
-
15
- api_token = ENV['FOGBUGZ_API_TOKEN']
16
- unless api_token
17
- puts "Environment variable FOGBUGZ_API_TOKEN must be set."
18
- exit 1
19
- end
20
-
21
- options = {}
22
- optparse = OptionParser.new do |opts|
23
- opts.banner = "usage: #{File::basename(__FILE__)} [options] <case> <status>"
24
-
25
- opts.on_tail('-h', '--help') do
26
- puts optparse.help
27
- exit 1
28
- end
29
- end
30
- optparse.parse!
31
- unless ARGV.length == 2
32
- puts optparse.help
33
- exit 1
34
- end
35
-
36
- uri = URI format("#{api_url}?cmd=listStatuses&token=%s&fResolved=1",
37
- URI.escape(api_token))
38
- http = Net::HTTP.new(uri.host, uri.port)
39
- if uri.scheme == 'https'
40
- http.use_ssl = true
41
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
42
- end
43
- response = http.start { |h| h.request Net::HTTP::Get.new(uri.request_uri) }
44
- if response.code != '200'
45
- puts "HTTP request to #{api_url} failed with code #{response.code}."
46
- exit 1
47
- end
48
-
49
- result = REXML::Document.new(response.body)
50
- error = result.elements['/response/error']
51
- if error
52
- puts "Failed with error: #{error.text}."
53
- exit 1
54
- end
4
+ parse_opts "usage: #{File::basename(__FILE__)} [options] <case> <status>", 2
55
5
 
6
+ result = do_api 'listStatuses', :fResolved => '1'
56
7
  status = result.elements["/response/statuses/status[sStatus='#{ARGV[1]}']"]
57
8
 
58
9
  unless status
@@ -60,23 +11,5 @@ unless status
60
11
  exit 1
61
12
  end
62
13
 
63
- uri = URI format("#{api_url}?cmd=resolve&token=%s&ixBug=%s&ixStatus=%s",
64
- URI.escape(api_token), URI.escape(ARGV[0]),
65
- URI.escape(status.elements['ixStatus'].text))
66
- http = Net::HTTP.new(uri.host, uri.port)
67
- if uri.scheme == 'https'
68
- http.use_ssl = true
69
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
70
- end
71
- response = http.start { |h| h.request Net::HTTP::Get.new(uri.request_uri) }
72
- if response.code != '200'
73
- puts "HTTP request to #{api_url} failed with code #{response.code}."
74
- exit 1
75
- end
76
-
77
- result = REXML::Document.new(response.body)
78
- error = result.elements['/response/error']
79
- if error
80
- puts "Failed with error: #{error.text}."
81
- exit 1
82
- end
14
+ do_api('resolve', :ixBug => ARGV[0],
15
+ :ixStatus => status.elements['ixStatus'].text)
@@ -1,151 +1,35 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'fogbugz/common'
2
3
 
3
- require 'rubygems'
4
- require 'net/https'
5
- require 'uri'
6
- require 'rexml/document'
7
- require 'optparse'
8
- require 'highline'
9
- require 'time'
4
+ options = parse_opts "usage: #{File::basename(__FILE__)} [options] <case>", 1
10
5
 
11
- HighLine.use_color = STDOUT.isatty
12
- begin
13
- require 'win32console' if RUBY_PLATFORM =~ /mingw/
14
- rescue LoadError
15
- HighLine.use_color = false
16
- end
17
-
18
- api_url = ENV['FOGBUGZ_API_URL']
19
- unless api_url
20
- puts "Environment variable FOGBUGZ_API_URL must be set."
21
- exit 1
22
- end
6
+ result = do_api('search', :max => 1, :q => ARGV[0],
7
+ :cols => 'ixBug,ixBugParent,tags,sTitle,sProject,sArea,sFixFor,sCategory,sPersonAssignedTo,sPriority,hrsCurrEst,dtDue,events')
23
8
 
24
- api_token = ENV['FOGBUGZ_API_TOKEN']
25
- unless api_token
26
- puts "Environment variable FOGBUGZ_API_TOKEN must be set."
27
- exit 1
28
- end
29
-
30
- options = {}
31
- optparse = OptionParser.new do |opts|
32
- opts.banner = "usage: #{File::basename(__FILE__)} [options] <case>"
33
-
34
- opts.on_tail('-h', '--help') do
35
- puts optparse.help
36
- exit 1
37
- end
38
- end
39
- optparse.parse!
40
-
41
- unless ARGV[0]
42
- puts optparse.help
43
- exit 1
44
- end
45
-
46
- uri = URI format("#{api_url}?cmd=search&token=%s&cols=%s&q=%s&max=1",
47
- URI.escape(api_token),
48
- URI.escape('ixBug,ixBugParent,tags,sTitle,sProject,sArea,sFixFor,sCategory,sPersonAssignedTo,sPriority,hrsCurrEst,events'),
49
- URI.escape(ARGV[0]))
50
- http = Net::HTTP.new(uri.host, uri.port)
51
- if uri.scheme == 'https'
52
- http.use_ssl = true
53
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
54
- end
55
- response = http.start { |h| h.request Net::HTTP::Get.new(uri.request_uri) }
56
- if response.code != '200'
57
- puts "HTTP request to #{api_url} failed with code #{response.code}."
58
- exit 1
59
- end
60
-
61
- result = REXML::Document.new(response.body)
62
- error = result.elements['/response/error']
63
- if error
64
- puts "Failed with error: #{error.text}."
65
- exit 1
66
- end
67
-
68
- hl = HighLine.new
69
9
  bug = result.elements["/response/cases/case[@ixBug='#{ARGV[0]}']"]
70
10
  unless bug
71
11
  puts "Case #{ARGV[0]} does not exist."
72
12
  exit 1
73
13
  end
74
14
 
75
- puts "#{hl.color('case:', HighLine::BLUE)} #{ARGV[0]}"
76
-
77
- sTitle = bug.elements['sTitle']
78
- if sTitle and sTitle.text and not sTitle.text.empty?
79
- puts "#{hl.color('title:', HighLine::BLUE)} #{sTitle.text}"
80
- end
81
-
82
- sPersonAssignedTo = bug.elements['sPersonAssignedTo']
83
- if sPersonAssignedTo and sPersonAssignedTo.text and
84
- not sPersonAssignedTo.text.empty?
85
- puts "#{hl.color('assignee:', HighLine::BLUE)} #{sPersonAssignedTo.text}"
86
- end
87
-
88
- ixBugParent = bug.elements['ixBugParent']
89
- if ixBugParent and ixBugParent.text and not ixBugParent.text.empty? and
90
- ixBugParent.text != '0'
91
- puts "#{hl.color('parent:', HighLine::BLUE)} #{ixBugParent.text}"
92
- end
93
-
94
- tags = bug.elements.collect('tags/tag') { |tag| tag.text }
95
- if tags and not tags.empty?
96
- puts "#{hl.color('tags:', HighLine::BLUE)} [#{tags.join(', ')}]"
97
- end
98
-
99
- sProject = bug.elements['sProject']
100
- if sProject and sProject.text and not sProject.text.empty?
101
- puts "#{hl.color('project:', HighLine::BLUE)} #{sProject.text}"
102
- end
103
-
104
- sArea = bug.elements['sArea']
105
- if sArea and sArea.text and not sArea.text.empty?
106
- puts "#{hl.color('area:', HighLine::BLUE)} #{sArea.text}"
107
- end
15
+ print "#{b}case:#{c} #{ARGV[0]}\n"
16
+ print maybe_show('title', bug.elements['sTitle'])
17
+ print maybe_show('assignee', bug.elements['sPersonAssignedTo'])
18
+ print maybe_show('parent', bug.elements['ixBugParent'])
19
+ print maybe_show_array('tags', bug.elements.collect('tags/tag') { |t| t.text })
20
+ print maybe_show('project', bug.elements['sProject'])
21
+ print maybe_show('area', bug.elements['sArea'])
22
+ print maybe_show('milestone', bug.elements['sFixFor'])
23
+ print maybe_show('category', bug.elements['sCategory'])
24
+ print maybe_show('priority', bug.elements['sPriority'])
25
+ print maybe_show_time('due', bug.elements['dtDue'])
26
+ print maybe_show('estimate', bug.elements['hrsCurrEst'])
27
+ print "\n"
108
28
 
109
- sFixFor = bug.elements['sFixFor']
110
- if sFixFor and sFixFor.text and not sFixFor.text.empty?
111
- puts "#{hl.color('milestone:', HighLine::BLUE)} #{sFixFor.text}"
112
- end
113
-
114
- sCategory = bug.elements['sCategory']
115
- if sCategory and sCategory.text and not sCategory.text.empty?
116
- puts "#{hl.color('category:', HighLine::BLUE)} #{sCategory.text}"
117
- end
118
-
119
- sPriority = bug.elements['sPriority']
120
- if sPriority and sPriority.text and not sPriority.text.empty?
121
- puts "#{hl.color('priority:', HighLine::BLUE)} #{sPriority.text}"
122
- end
123
-
124
- hrsCurrEst = bug.elements['hrsCurrEst']
125
- if hrsCurrEst and hrsCurrEst.text and not hrsCurrEst.text.empty? and
126
- hrsCurrEst.text != '0'
127
- puts "#{hl.color('estimate:', HighLine::BLUE)} #{hrsCurrEst.text}"
128
- end
129
-
130
- puts "\n"
131
29
  bug.elements.each('events/event') do |event|
132
- evtDescription = event.elements['evtDescription']
133
- if evtDescription and evtDescription.text and
134
- not evtDescription.text.empty?
135
- time = Time.parse(event.elements['dt'].text).localtime
136
- header = format("%s at %s on %s.", evtDescription.text,
137
- time.strftime('%-l:%M %p'), time.strftime('%A, %B %e %Y'))
138
- puts hl.color(header, HighLine::GREEN)
139
- end
140
-
141
- sChanges = event.elements['sChanges']
142
- if sChanges and sChanges.text and not sChanges.text.empty?
143
- puts hl.color(sChanges.text, HighLine::BLUE)
144
- end
145
-
146
- summary = event.elements['s']
147
- if summary and summary.text and not summary.text.empty?
148
- puts summary.text
149
- end
150
- puts ''
30
+ puts maybe_show_event(g, event.elements['evtDescription'],
31
+ event.elements['dt'])
32
+ print maybe_show_literal(b, event.elements['sChanges'])
33
+ print maybe_show_literal(c, event.elements['s'])
34
+ print "\n"
151
35
  end
@@ -1,54 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ require 'fogbugz/common'
2
3
 
3
- require 'rubygems'
4
- require 'net/https'
5
- require 'uri'
6
- require 'rexml/document'
7
- require 'optparse'
8
-
9
- api_url = ENV['FOGBUGZ_API_URL']
10
- unless api_url
11
- puts "Environment variable FOGBUGZ_API_URL must be set."
12
- exit 1
13
- end
14
-
15
- api_token = ENV['FOGBUGZ_API_TOKEN']
16
- unless api_token
17
- puts "Environment variable FOGBUGZ_API_TOKEN must be set."
18
- exit 1
19
- end
20
-
21
- options = {}
22
- optparse = OptionParser.new do |opts|
23
- opts.banner = "usage: #{File::basename(__FILE__)} [options] <case>"
24
-
25
- opts.on_tail('-h', '--help') do
26
- puts optparse.help
27
- exit 1
28
- end
29
- end
30
- optparse.parse!
31
- unless ARGV[0]
32
- puts optparse.help
33
- exit 1
34
- end
35
-
36
- uri = URI format("#{api_url}?cmd=startWork&token=%s&ixBug=%s",
37
- URI.escape(api_token), URI.escape(ARGV[0]))
38
- http = Net::HTTP.new(uri.host, uri.port)
39
- if uri.scheme == 'https'
40
- http.use_ssl = true
41
- http.verify_mode = OpenSSL::SSL::VERIFY_NONE
42
- end
43
- response = http.start { |h| h.request Net::HTTP::Get.new(uri.request_uri) }
44
- if response.code != '200'
45
- puts "HTTP request to #{api_url} failed with code #{response.code}."
46
- exit 1
47
- end
48
-
49
- result = REXML::Document.new(response.body)
50
- error = result.elements['/response/error']
51
- if error
52
- puts "Failed with error: #{error.text}."
53
- exit 1
54
- end
4
+ parse_opts "usage: #{File::basename(__FILE__)} [options] <case>", 1
5
+ do_api 'startWork', :ixBug => ARGV[0]