jira-ruby 0.1.17 → 1.0.0

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
  SHA1:
3
- metadata.gz: 2ff744bcd9ad2d2787f07ecf627888484805cadf
4
- data.tar.gz: ae9c78df7d9b0de9fb35bdfb0671119240211a91
3
+ metadata.gz: bb639c7a6da1d81ae6bb693c5891ee23ce1b1e9c
4
+ data.tar.gz: 331cd7e819faa9cc056045413d968793a238baa9
5
5
  SHA512:
6
- metadata.gz: d118f8da88f23970bb406d4cfabec43eb19fc4178fddc4c9ec9e9c893933dff4b0aa6c3aa56fdcfc92a1ee43817f8ba39d1b03d2a1645c950528bf104eebcbcd
7
- data.tar.gz: 4a9a20b2c3ecb34c7ff79c87cbf0546ec5bbb89700a3655066fd4060d5b9fa4e8dbaf68e66d40f7a8ec02b36c96712be8af4889d6618f50a603ed85f91611c6f
6
+ metadata.gz: e8e856bf2af0be3d9b40b300167117c263c6ffda85fb70001c7fd3c2c59b05eab6561ac2f684786175dcf707d6b5ab9a606b92a17a3278cde73f119fb047d4ff
7
+ data.tar.gz: cc19f33cb2c9455045ff0f1d8368a639963dee01c3c313a39e6e49b026d354dd8f0ef2586773b8153b78c51868466bafbd452aac77ba2641c4f697fd22e6d9d0
data/.travis.yml CHANGED
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.0.0
3
+ - 2.3.1
4
+ - ruby-head
4
5
  before_script:
5
6
  - rake jira:generate_public_cert
6
7
  script: bundle exec rake spec
data/Gemfile CHANGED
@@ -1,6 +1,8 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem 'pry'
3
+ group :development do
4
+ gem 'wdm', '>= 0.1.0' if Gem.win_platform?
5
+ end
4
6
 
5
7
  # Specify your gem's dependencies in jira_api.gemspec
6
8
  gemspec
data/Guardfile ADDED
@@ -0,0 +1,14 @@
1
+ gem 'wdm', '>= 0.1.0' if Gem.win_platform?
2
+ gem 'rspec', '~> 3.0.0'
3
+
4
+ guard 'rspec', cmd: 'bundle exec rspec --color --format doc' do
5
+ # watch /lib/ files
6
+ watch(%r{^lib/(.+).rb$}) do |m|
7
+ "spec/#{m[1]}_spec.rb"
8
+ end
9
+
10
+ # watch /spec/ files
11
+ watch(%r{^spec/(.+).rb$}) do |m|
12
+ "spec/#{m[1]}.rb"
13
+ end
14
+ end
data/README.rdoc CHANGED
@@ -6,7 +6,18 @@ This gem provides access to the Atlassian JIRA REST API.
6
6
 
7
7
  == Example usage
8
8
 
9
- client = JIRA::Client.new({:consumer_key => CONSUMER_KEY, :consumer_secret => CONSUMER_SECRET})
9
+ require 'rubygems'
10
+ require 'jira-ruby'
11
+
12
+ options = {
13
+ :username => 'username',
14
+ :password => 'pass1234',
15
+ :site => 'http://mydomain.atlassian.net:443/',
16
+ :context_path => '',
17
+ :auth_type => :basic
18
+ }
19
+
20
+ client = JIRA::Client.new(options)
10
21
 
11
22
  project = client.Project.find('SAMPLEPROJECT')
12
23
 
@@ -14,17 +25,18 @@ This gem provides access to the Atlassian JIRA REST API.
14
25
  puts "#{issue.id} - #{issue.summary}"
15
26
  end
16
27
 
17
- issue.comments.each {|comment| ... }
18
-
19
- comment = issue.comments.build
20
- comment.save({'body':'My new comment'})
21
- comment.delete
22
-
23
28
  == Links to JIRA REST API documentation
24
29
 
25
30
  * {Overview}[https://developer.atlassian.com/display/JIRADEV/JIRA+REST+APIs]
26
31
  * {Reference}[http://docs.atlassian.com/jira/REST/latest/]
27
32
 
33
+ == Running tests
34
+
35
+ Before running tests, you will need a public certificate generated.
36
+
37
+ ```
38
+ rake jira:generate_public_cert
39
+ ```
28
40
 
29
41
  == Setting up the JIRA SDK
30
42
 
@@ -76,9 +88,13 @@ defaults to HTTP Basic Auth.
76
88
  Using HTTP Basic Authentication, configure and connect a client to your instance
77
89
  of JIRA.
78
90
 
91
+ Note: If your Jira install is hosted on {atlassian.net}[atlassian.net], it will have no context
92
+ path by default. If you're having issues connecting, try setting context_path
93
+ to an empty string in the options hash.
94
+
79
95
  require 'rubygems'
80
96
  require 'pp'
81
- require 'jira'
97
+ require 'jira-ruby'
82
98
 
83
99
  # Consider the use of :use_ssl and :ssl_verify_mode options if running locally
84
100
  # for tests.
@@ -119,7 +135,7 @@ Ensure the JIRA gem is loaded correctly
119
135
 
120
136
  # Gemfile
121
137
  ...
122
- gem 'jira-ruby', :require => 'jira'
138
+ gem 'jira-ruby', :require => 'jira-ruby'
123
139
  ...
124
140
 
125
141
  Add common methods to your application controller and ensure access token
@@ -214,7 +230,7 @@ Create your own controllers for the JIRA resources you wish to access.
214
230
 
215
231
  Here's the same example as a Sinatra application:
216
232
 
217
- require 'jira'
233
+ require 'jira-ruby'
218
234
  class App < Sinatra::Base
219
235
  enable :sessions
220
236
 
@@ -273,7 +289,8 @@ Here's the same example as a Sinatra application:
273
289
  # Initiates the OAuth dance by first requesting a token then redirecting to
274
290
  # http://<yourserver>/auth to get the @access_token
275
291
  get '/signin' do
276
- request_token = @jira_client.request_token
292
+ callback_url = "#{request.base_url}/callback"
293
+ request_token = @jira_client.request_token(oauth_callback: callback_url)
277
294
  session[:request_token] = request_token.token
278
295
  session[:request_secret] = request_token.secret
279
296
 
@@ -283,7 +300,7 @@ Here's the same example as a Sinatra application:
283
300
  # http://<yourserver>/callback
284
301
  # Retrieves the @access_token then stores it inside a session cookie. In a real app,
285
302
  # you'll want to persist the token in a datastore associated with the user.
286
- get "/callback/" do
303
+ get "/callback" do
287
304
  request_token = @jira_client.set_request_token(
288
305
  session[:request_token], session[:request_secret]
289
306
  )
data/Rakefile CHANGED
@@ -19,7 +19,11 @@ task :prepare do
19
19
  end
20
20
 
21
21
  desc 'Run RSpec tests'
22
- RSpec::Core::RakeTask.new(:spec)
22
+ #RSpec::Core::RakeTask.new(:spec)
23
+ RSpec::Core::RakeTask.new(:spec) do |task|
24
+ task.rspec_opts = ['--color', '--format', 'doc']
25
+ end
26
+
23
27
 
24
28
  Rake::RDocTask.new(:doc) do |rd|
25
29
  rd.main = 'README.rdoc'
data/example.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'pp'
2
- require './lib/jira'
2
+ require './lib/jira-ruby'
3
3
 
4
4
  CONSUMER_KEY = 'test'
5
5
  SITE = 'https://test.jira.com'
@@ -42,6 +42,28 @@ end
42
42
  issue = client.Issue.find('SAMPLEPROJECT-1')
43
43
  pp issue
44
44
 
45
+ # # Handling fields by name, rather than by id
46
+ # # ------------------------------------------
47
+ # Cache the Field list from the server
48
+ client.Field.map_fields
49
+ # This allows use of friendlier names for custom fields
50
+ # Say that 'Special Field' is customfield_12345
51
+ # It becomes mapped to Special_Field which is usable as a method call
52
+ #
53
+ # Say that there is a second 'Special Field' is customfield_54321
54
+ # Names are deduplicated so the second 'Special Field' becomes Special_Field_54321
55
+ #
56
+ # Names are massaged to get rid of special characters, and spaces
57
+ # So 'Special & @ Field' becomes Special_____Field - not perfect, but usable
58
+ old_way = issue.customfield_12345
59
+ new_way = issue.Special_Field
60
+ (old_way == new_way) && puts 'much easier'
61
+ #
62
+ # Can also use this to specify fields to be returned in the response
63
+ client.Issue.jql(a_normal_jql_search, fields:[:Special_Field])
64
+ # Or you could always do it the old way - if you can remember the numbers...
65
+ client.Issue.jql(a_normal_jql_search, fields:['customfield_12345'])
66
+
45
67
  # # Find a specific project by key
46
68
  # # ------------------------------
47
69
  # project = client.Project.find('SAMPLEPROJECT')
@@ -173,4 +195,4 @@ remote_link.save(
173
195
  :title => issue_1.key,
174
196
  }
175
197
  }
176
- )
198
+ )
@@ -1,6 +1,6 @@
1
1
  require 'rubygems'
2
2
  require 'pp'
3
- require 'jira'
3
+ require 'jira-ruby'
4
4
 
5
5
  if ARGV.length == 0
6
6
  # If not passed any command line arguments, prompt the
data/jira-ruby.gemspec CHANGED
@@ -1,27 +1,33 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "jira/version"
2
+ $:.push File.expand_path('../lib', __FILE__)
3
+ require 'jira/version'
4
4
 
5
5
  Gem::Specification.new do |s|
6
- s.name = "jira-ruby"
6
+ s.name = 'jira-ruby'
7
7
  s.version = JIRA::VERSION
8
- s.authors = ["SUMO Heavy Industries"]
9
- s.homepage = "http://www.sumoheavy.com"
8
+ s.authors = ['SUMO Heavy Industries']
9
+ s.homepage = 'http://www.sumoheavy.com'
10
10
  s.summary = %q{Ruby Gem for use with the Atlassian JIRA REST API}
11
11
  s.description = %q{API for JIRA}
12
- s.licenses = ["OSL-3.0"]
12
+ s.licenses = ['OSL-3.0']
13
13
 
14
- s.rubyforge_project = "jira-ruby"
14
+ s.rubyforge_project = 'jira-ruby'
15
15
 
16
16
  s.files = `git ls-files`.split("\n")
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
- s.require_paths = ["lib"]
19
+ s.require_paths = ['lib']
20
20
 
21
- s.add_development_dependency "railties"
22
- s.add_runtime_dependency "oauth", '~> 0.4.7'
23
- s.add_runtime_dependency "activesupport"
24
- s.add_development_dependency "webmock", '~> 1.18.0'
25
- s.add_development_dependency "rspec", '~> 3.0.0'
26
- s.add_development_dependency "rake", '~> 10.3.2'
21
+ # Rubtime Dependencies
22
+ s.add_runtime_dependency 'oauth', '~> 0.5', '>= 0.5.0'
23
+ s.add_runtime_dependency 'activesupport', '~> 4.2', '>= 4.2.0'
24
+
25
+ # Development Dependencies
26
+ s.add_development_dependency 'railties', '~> 4.2', '>= 4.2.0'
27
+ s.add_development_dependency 'webmock', '~> 1.18', '>= 1.18.0'
28
+ s.add_development_dependency 'rspec', '~> 3.0', '>= 3.0.0'
29
+ s.add_development_dependency 'rake', '~> 10.3', '>= 10.3.2'
30
+ s.add_development_dependency 'guard', '~> 2.13', '>= 2.13.0'
31
+ s.add_development_dependency 'guard-rspec', '~> 4.6', '>= 4.6.5'
32
+ s.add_development_dependency 'pry', '~> 0.10', '>= 0.10.3'
27
33
  end
@@ -2,7 +2,7 @@ $: << File.expand_path(File.dirname(__FILE__))
2
2
 
3
3
  require 'active_support/inflector'
4
4
  ActiveSupport::Inflector.inflections do |inflector|
5
- inflector.singular 'status', 'status'
5
+ inflector.singular /status$/, 'status'
6
6
  end
7
7
 
8
8
  require 'jira/base'
@@ -29,8 +29,12 @@ require 'jira/resource/issue'
29
29
  require 'jira/resource/filter'
30
30
  require 'jira/resource/field'
31
31
  require 'jira/resource/rapidview'
32
+ require 'jira/resource/resolution'
32
33
  require 'jira/resource/serverinfo'
33
-
34
+ require 'jira/resource/createmeta'
35
+ require 'jira/resource/webhook'
36
+ require 'jira/resource/agile'
37
+ require 'jira/resource/sprint'
34
38
  require 'jira/request_client'
35
39
  require 'jira/oauth_client'
36
40
  require 'jira/http_client'
data/lib/jira/base.rb CHANGED
@@ -348,7 +348,7 @@ module JIRA
348
348
  # JIRA::HTTPError if the request fails (response is not HTTP 2xx).
349
349
  def save!(attrs)
350
350
  http_method = new_record? ? :post : :put
351
- response = client.send(http_method, url, attrs.to_json)
351
+ response = client.send(http_method, new_record? ? url : patched_url, attrs.to_json)
352
352
  set_attrs(attrs, false)
353
353
  set_attrs_from_response(response)
354
354
  @expanded = false
@@ -439,6 +439,7 @@ module JIRA
439
439
  end
440
440
 
441
441
  # This method fixes issue that there is no / prefix in url. It is happened when we call for instance
442
+ # Looks like this issue is actual only in case if you use atlassian sdk your app path is not root (like /jira in example below)
442
443
  # issue.save() for existing resource.
443
444
  # As a result we got error 400 from JIRA API:
444
445
  # [07/Jun/2015:15:32:19 +0400] "PUT jira/rest/api/2/issue/10111 HTTP/1.1" 400 -
@@ -446,7 +447,7 @@ module JIRA
446
447
  # [07/Jun/2015:15:17:18 +0400] "PUT /jira/rest/api/2/issue/10111 HTTP/1.1" 204 -
447
448
  def patched_url
448
449
  result = url
449
- result if result.start_with?('/')
450
+ return result if result.start_with?('/')
450
451
  "/#{result}"
451
452
  end
452
453
 
@@ -455,8 +456,8 @@ module JIRA
455
456
  end
456
457
 
457
458
  # Returns a JSON representation of the current attributes hash.
458
- def to_json
459
- attrs.to_json
459
+ def to_json(options = {})
460
+ attrs.to_json(options)
460
461
  end
461
462
 
462
463
  # Determines if the resource is newly created by checking whether its
@@ -15,7 +15,7 @@ module JIRA
15
15
  # Need to do a little bit of work here as Module.const_get doesn't work
16
16
  # with nested class names, i.e. JIRA::Resource::Foo.
17
17
  #
18
- # So create a method chain from the class componenets. This code will
18
+ # So create a method chain from the class components. This code will
19
19
  # unroll to:
20
20
  # Module.const_get('JIRA').const_get('Resource').const_get('Foo')
21
21
  #
@@ -35,10 +35,10 @@ module JIRA
35
35
  end
36
36
  end
37
37
 
38
- # The priciple purpose of this class is to delegate methods to the corresponding
38
+ # The principle purpose of this class is to delegate methods to the corresponding
39
39
  # non-factory class and automatically prepend the client argument to the argument
40
40
  # list.
41
- delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql
41
+ delegate_to_target_class :all, :find, :collection_path, :singular_path, :jql, :get_backlog_issues, :get_sprints, :get_sprint_issues
42
42
 
43
43
  # This method needs special handling as it has a default argument value
44
44
  def build(attrs={})
data/lib/jira/client.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'json'
2
2
  require 'forwardable'
3
+ require 'ostruct'
3
4
 
4
5
  module JIRA
5
6
 
@@ -37,7 +38,7 @@ module JIRA
37
38
  #
38
39
  # The authenticated client instance returned by the respective client type
39
40
  # (Oauth, Basic)
40
- attr_accessor :consumer, :request_client
41
+ attr_accessor :consumer, :request_client, :http_debug, :cache
41
42
 
42
43
  # The configuration options for this client instance
43
44
  attr_reader :options
@@ -50,7 +51,8 @@ module JIRA
50
51
  :rest_base_path => "/rest/api/2",
51
52
  :ssl_verify_mode => OpenSSL::SSL::VERIFY_PEER,
52
53
  :use_ssl => true,
53
- :auth_type => :oauth
54
+ :auth_type => :oauth,
55
+ :http_debug => false
54
56
  }
55
57
 
56
58
  def initialize(options={})
@@ -64,9 +66,15 @@ module JIRA
64
66
  @consumer = @request_client.consumer
65
67
  when :basic
66
68
  @request_client = HttpClient.new(@options)
69
+ else
70
+ raise ArgumentError, 'Options: ":auth_type" must be ":oauth" or ":basic"'
67
71
  end
68
72
 
73
+ @http_debug = @options[:http_debug]
74
+
69
75
  @options.freeze
76
+
77
+ @cache = OpenStruct.new
70
78
  end
71
79
 
72
80
  def Project # :nodoc:
@@ -101,6 +109,10 @@ module JIRA
101
109
  JIRA::Resource::StatusFactory.new(self)
102
110
  end
103
111
 
112
+ def Resolution # :nodoc:
113
+ JIRA::Resource::ResolutionFactory.new(self)
114
+ end
115
+
104
116
  def Comment # :nodoc:
105
117
  JIRA::Resource::CommentFactory.new(self)
106
118
  end
@@ -133,10 +145,18 @@ module JIRA
133
145
  JIRA::Resource::ServerInfoFactory.new(self)
134
146
  end
135
147
 
148
+ def Createmeta
149
+ JIRA::Resource::CreatemetaFactory.new(self)
150
+ end
151
+
136
152
  def ApplicationLink
137
153
  JIRA::Resource::ApplicationLinkFactory.new(self)
138
154
  end
139
155
 
156
+ def Webhook
157
+ JIRA::Resource::WebhookFactory.new(self)
158
+ end
159
+
140
160
  def Issuelink
141
161
  JIRA::Resource::IssuelinkFactory.new(self)
142
162
  end
@@ -149,6 +169,14 @@ module JIRA
149
169
  JIRA::Resource::RemotelinkFactory.new(self)
150
170
  end
151
171
 
172
+ def Sprint
173
+ JIRA::Resource::SprintFactory.new(self)
174
+ end
175
+
176
+ def Agile
177
+ JIRA::Resource::AgileFactory.new(self)
178
+ end
179
+
152
180
  # HTTP methods without a body
153
181
  def delete(path, headers = {})
154
182
  request(:delete, path, nil, merge_default_headers(headers))
@@ -176,6 +204,7 @@ module JIRA
176
204
  # Sends the specified HTTP request to the REST API through the
177
205
  # appropriate method (oauth, basic).
178
206
  def request(http_method, path, body = '', headers={})
207
+ puts "#{http_method}: #{path} - [#{body}]" if @http_debug
179
208
  @request_client.request(http_method, path, body, headers)
180
209
  end
181
210
 
@@ -0,0 +1,54 @@
1
+ require 'cgi'
2
+
3
+ module JIRA
4
+ module Resource
5
+
6
+ class AgileFactory < JIRA::BaseFactory # :nodoc:
7
+ end
8
+
9
+ class Agile < JIRA::Base
10
+
11
+ def self.all(client)
12
+ response = client.get(path_base(client) + '/board')
13
+ parse_json(response.body)
14
+ end
15
+
16
+ def self.get_backlog_issues(client, board_id, options = {})
17
+ options[:maxResults] ||= 100
18
+ response = client.get("/rest/agile/1.0/board/#{board_id}/backlog?maxResults=#{options[:maxResults]}")
19
+ parse_json(response.body)
20
+ end
21
+
22
+ def self.get_sprints(client, board_id, options = {})
23
+ options[:maxResults] ||= 100
24
+ response = client.get("/rest/agile/1.0/board/#{board_id}/sprint?maxResults=#{options[:maxResults]}")
25
+ parse_json(response.body)
26
+ end
27
+
28
+ def self.get_sprint_issues(client, sprint_id, options = {})
29
+ options[:maxResults] ||= 100
30
+ response = client.get("/rest/agile/1.0/sprint/#{sprint_id}/issue?maxResults=#{options[:maxResults]}")
31
+ parse_json(response.body)
32
+ end
33
+
34
+ # def self.find(client, key, options = {})
35
+ # options[:maxResults] ||= 100
36
+ # fields = options[:fields].join(',') unless options[:fields].nil?
37
+ # response = client.get("/rest/api/latest/search?jql=sprint=#{key}&fields=#{fields}&maxResults=#{options[:maxResults]}")
38
+ # parse_json(response.body)
39
+ # end
40
+
41
+ private
42
+
43
+ def self.path_base(client)
44
+ client.options[:context_path] + '/rest/agile/1.0'
45
+ end
46
+
47
+ def path_base(client)
48
+ self.class.path_base(client)
49
+ end
50
+
51
+ end
52
+
53
+ end
54
+ end