taskmapper-jira 0.3.0

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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ .bundle
2
+ pkg/*
3
+ *.un~
4
+ *.swp
data/.rbenv-gemsets ADDED
@@ -0,0 +1 @@
1
+ ticketmaster-jira
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm 1.9.2@taskmapper-jira --create
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ source :rubygems
2
+
3
+ gem 'taskmapper', "~> 0.8"
4
+ gem 'jira4r-jh', "~> 0.4"
5
+
6
+ group :test, :development do
7
+ gem "rspec", "~> 2.8"
8
+ gem 'rake', '~> 0.9.2'
9
+ gem "simplecov", "~> 0.5", :platforms => :ruby_19
10
+ gem "rcov", "~> 1.0", :platforms => :ruby_18
11
+ end
12
+
data/Gemfile.lock ADDED
@@ -0,0 +1,52 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.2.3)
5
+ activesupport (= 3.2.3)
6
+ builder (~> 3.0.0)
7
+ activeresource (3.2.3)
8
+ activemodel (= 3.2.3)
9
+ activesupport (= 3.2.3)
10
+ activesupport (3.2.3)
11
+ i18n (~> 0.6)
12
+ multi_json (~> 1.0)
13
+ builder (3.0.0)
14
+ diff-lcs (1.1.3)
15
+ hashie (1.2.0)
16
+ httpclient (2.2.3)
17
+ i18n (0.6.0)
18
+ jira4r-jh (0.4.0)
19
+ soap4r
20
+ soap4r
21
+ multi_json (1.1.0)
22
+ rake (0.9.2.2)
23
+ rcov (1.0.0)
24
+ rspec (2.8.0)
25
+ rspec-core (~> 2.8.0)
26
+ rspec-expectations (~> 2.8.0)
27
+ rspec-mocks (~> 2.8.0)
28
+ rspec-core (2.8.0)
29
+ rspec-expectations (2.8.0)
30
+ diff-lcs (~> 1.1.2)
31
+ rspec-mocks (2.8.0)
32
+ simplecov (0.6.1)
33
+ multi_json (~> 1.0)
34
+ simplecov-html (~> 0.5.3)
35
+ simplecov-html (0.5.3)
36
+ soap4r (1.5.8)
37
+ httpclient (>= 2.1.1)
38
+ taskmapper (0.8.0)
39
+ activeresource (~> 3.0)
40
+ activesupport (~> 3.0)
41
+ hashie (~> 1.2)
42
+
43
+ PLATFORMS
44
+ ruby
45
+
46
+ DEPENDENCIES
47
+ jira4r-jh (~> 0.4)
48
+ rake (~> 0.9.2)
49
+ rcov (~> 1.0)
50
+ rspec (~> 2.8)
51
+ simplecov (~> 0.5)
52
+ taskmapper (~> 0.8)
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ task :default => :spec
5
+
6
+ desc "run specs"
7
+ task :spec do
8
+ sh "bundle exec rspec --color spec/"
9
+ end
10
+
@@ -0,0 +1,5 @@
1
+ class TaskMapper
2
+ module Jira
3
+ VERSION = "0.3.0"
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ module TaskMapper::Provider
2
+ module Jira
3
+ # The comment class for taskmapper-jira
4
+ #
5
+ # Do any mapping between taskmapper and your system's comment model here
6
+ # versions of the ticket.
7
+ #
8
+ class Comment < TaskMapper::Provider::Base::Comment
9
+ #API = Jira::Comment # The class to access the api's comments
10
+ # declare needed overloaded methods here
11
+
12
+ def initialize(*object)
13
+ if object.first
14
+ object = object.first
15
+ unless object.is_a? Hash
16
+ @system_data = {:client => object}
17
+ hash = {:id => object.id,
18
+ :author => object.author,
19
+ :body => object.body,
20
+ :created_at => object.created,
21
+ :updated_at => object.updated,
22
+ :ticket_id => object.ticket_id,
23
+ :project_id => object.project_id}
24
+ else
25
+ hash = object
26
+ end
27
+ super(hash)
28
+ end
29
+ end
30
+
31
+ def self.find(ticket_id, *options)
32
+ if options.first.empty?
33
+ self.find_all(ticket_id)
34
+ end
35
+ end
36
+
37
+ def self.find_all(ticket_id)
38
+ begin
39
+ $jira.getComments("#{ticket_id}").map { |comment| self.new comment }
40
+ rescue
41
+ []
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,50 @@
1
+ module TaskMapper::Provider
2
+ # This is the Jira Provider for taskmapper
3
+ module Jira
4
+ include TaskMapper::Provider::Base
5
+ #TICKET_API = Jira::Ticket # The class to access the api's tickets
6
+ #PROJECT_API = Jira::Project # The class to access the api's projects
7
+
8
+ # This is for cases when you want to instantiate using TaskMapper::Provider::Jira.new(auth)
9
+ def self.new(auth = {})
10
+ TaskMapper.new(:jira, auth)
11
+ end
12
+
13
+ # Providers must define an authorize method. This is used to initialize and set authentication
14
+ # parameters to access the API
15
+ def authorize(auth = {})
16
+ @authentication ||= TaskMapper::Authenticator.new(auth)
17
+ $jira = Jira4R::JiraTool.new(2,@authentication.url)
18
+ begin
19
+ $jira.login(@authentication.username, @authentication.password)
20
+ @valid_auth = true
21
+ rescue
22
+ @valid_auth = false
23
+ end
24
+ # Set authentication parameters for whatever you're using to access the API
25
+ end
26
+
27
+ # declare needed overloaded methods here
28
+
29
+ def project(*options)
30
+ if options.first.is_a? String
31
+ options[0] = options[0].to_i
32
+ end
33
+ if options.first.is_a? Fixnum
34
+ Project.find_by_id(options.first)
35
+ elsif options.first.is_a? Hash
36
+ Project.find_by_attributes(options.first).first
37
+ end
38
+ end
39
+
40
+ def projects(*options)
41
+ Project.find(options)
42
+ end
43
+
44
+ def valid?
45
+ @valid_auth
46
+ end
47
+ end
48
+ end
49
+
50
+
@@ -0,0 +1,71 @@
1
+ module TaskMapper::Provider
2
+ module Jira
3
+ # Project class for taskmapper-jira
4
+ #
5
+ #
6
+ class Project < TaskMapper::Provider::Base::Project
7
+ #API = Jira::Project # The class to access the api's projects
8
+ # declare needed overloaded methods here
9
+ # copy from this.copy(that) copies that into this
10
+ def initialize(*object)
11
+ if object.first
12
+ object = object.first
13
+ unless object.is_a? Hash
14
+ @system_data = {:client => object}
15
+ hash = {:id => object.id.to_i,
16
+ :name => object.name,
17
+ :description => object.description,
18
+ :updated_at => nil,
19
+ :created_at => nil}
20
+ else
21
+ hash = object
22
+ end
23
+ super(hash)
24
+ end
25
+ end
26
+
27
+ def id
28
+ self[:id].to_i
29
+ end
30
+
31
+ def copy(project)
32
+ project.tickets.each do |ticket|
33
+ copy_ticket = self.ticket!(:title => ticket.title, :description => ticket.description)
34
+ ticket.comments.each do |comment|
35
+ copy_ticket.comment!(:body => comment.body)
36
+ sleep 1
37
+ end
38
+ end
39
+ end
40
+
41
+ def self.find(*options)
42
+ if options[0].first.is_a? Array
43
+ self.find_all.select do |project|
44
+ project if options.first.any? { |id| project.id == id }
45
+ end
46
+ elsif options[0].first.is_a? Hash
47
+ find_by_attributes(options[0].first)
48
+ else
49
+ self.find_all
50
+ end
51
+ end
52
+
53
+ def self.find_by_attributes(attributes = {})
54
+ search_by_attribute(self.find_all, attributes)
55
+ end
56
+
57
+ def self.find_all
58
+ $jira.getProjectsNoSchemes().map do |project|
59
+ Project.new project
60
+ end
61
+ end
62
+
63
+ def self.find_by_id(id)
64
+ self.find_all.select { |project| project.id == id }.first
65
+ end
66
+
67
+ end
68
+ end
69
+ end
70
+
71
+
@@ -0,0 +1,73 @@
1
+ module TaskMapper::Provider
2
+ module Jira
3
+ # Ticket class for taskmapper-jira
4
+ #
5
+
6
+ class Ticket < TaskMapper::Provider::Base::Ticket
7
+ #API = Jira::Ticket # The class to access the api's tickets
8
+ # declare needed overloaded methods here
9
+ def initialize(*object)
10
+ if object.first
11
+ object = object.first
12
+ unless object.is_a? Hash
13
+ @system_data = {:client => object}
14
+ hash = {:id => object.id.to_i,
15
+ :status => object.status,
16
+ :priority => object.priority,
17
+ :title => object.summary,
18
+ :resolution => object.resolution,
19
+ :created_at => object.created,
20
+ :updated_at => object.updated,
21
+ :description => object.description,
22
+ :assignee => object.assignee,
23
+ :requestor => object.reporter}
24
+ else
25
+ hash = object
26
+ end
27
+ super(hash)
28
+ end
29
+ end
30
+
31
+ def id
32
+ self[:id].to_i
33
+ end
34
+
35
+ def updated_at
36
+ normalize_datetime(self[:updated_at])
37
+ end
38
+
39
+ def created_at
40
+ normalize_datetime(self[:created_at])
41
+ end
42
+
43
+ def self.find_by_attributes(project_id, attributes = {})
44
+ search_by_attribute(self.find_all(project_id), attributes)
45
+ end
46
+
47
+ def self.find_by_id(project_id, id)
48
+ self.find_all(project_id).select { |ticket| ticket.id == id }.first
49
+ end
50
+
51
+ def self.find_all(project_id)
52
+ $jira.getIssuesFromJqlSearch("project = #{project_id}", 200).map do |ticket|
53
+ self.new ticket
54
+ end
55
+ end
56
+
57
+ def comments(*options)
58
+ Comment.find(self.id, options)
59
+ end
60
+
61
+ def comment(*options)
62
+ nil
63
+ end
64
+
65
+ private
66
+ def normalize_datetime(datetime)
67
+ Time.mktime(datetime.year, datetime.month, datetime.day, datetime.hour, datetime.min, datetime.sec)
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+ end
@@ -0,0 +1,5 @@
1
+ require 'jira4r/jira_tool'
2
+
3
+ %w{ jira ticket project comment }.each do |f|
4
+ require File.dirname(__FILE__) + '/provider/' + f + '.rb';
5
+ end
@@ -0,0 +1,39 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe TaskMapper::Provider::Jira::Comment do
4
+ before(:each) do
5
+ @url = "some_url"
6
+ @fj = FakeJiraTool.new
7
+ @project_jira = Struct.new(:id, :name, :description).new(1, 'project', 'project description')
8
+ @ticket = Struct.new(:id,
9
+ :status,
10
+ :priority,
11
+ :summary,
12
+ :resolution,
13
+ :created,
14
+ :updated,
15
+ :description, :assignee, :reporter).new(1,'open','high', 'ticket 1', 'none', Time.now, Time.now, 'description', 'myself', 'yourself')
16
+ @comment = Struct.new(:id, :author, :body, :created, :updated, :ticket_id, :project_id).new(1,
17
+ 'myself',
18
+ 'body',
19
+ Time.now,
20
+ Time.now,
21
+ 1,
22
+ 1)
23
+ Jira4R::JiraTool.stub!(:new).with(2, @url).and_return(@fj)
24
+ @fj.stub!(:getProjectsNoSchemes).and_return([@project_jira, @project_jira])
25
+ @fj.stub!(:getProjectById).and_return(@project_jira)
26
+ @fj.stub!(:getIssuesFromJqlSearch).and_return([@ticket])
27
+ @fj.stub!(:getComments).and_return([@comment])
28
+ @tm = TaskMapper.new(:jira, :username => 'testuser', :password => 'testuser', :url => @url)
29
+ @ticket = @tm.projects.first.tickets.first
30
+ @klass = TaskMapper::Provider::Jira::Comment
31
+ end
32
+
33
+ it "should be able to load all comments" do
34
+ @ticket.comments.should be_an_instance_of(Array)
35
+ @ticket.comments.first.should be_an_instance_of(@klass)
36
+ end
37
+
38
+ it "should be able to create a comment"
39
+ end
@@ -0,0 +1,46 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe TaskMapper::Provider::Jira::Project do
4
+ before(:each) do
5
+ @url = "some_url"
6
+ @fj = FakeJiraTool.new
7
+ @project = Struct.new(:id, :name, :description).new(1,
8
+ 'project',
9
+ 'project description')
10
+ Jira4R::JiraTool.stub!(:new).with(2, @url).and_return(@fj)
11
+ @fj.stub!(:getProjectsNoSchemes).and_return([@project, @project])
12
+ @fj.stub!(:getProjectByKey).and_return(@project)
13
+ @tm = TaskMapper.new(:jira, :username => 'testuser', :password => 'testuser', :url => @url)
14
+ @klass = TaskMapper::Provider::Jira::Project
15
+ end
16
+
17
+ it "should be able to load all projects" do
18
+ @tm.projects.should be_an_instance_of(Array)
19
+ @tm.projects.first.should be_an_instance_of(@klass)
20
+ end
21
+
22
+ it "should be able to load all projects based on an array of id's" do
23
+ @tm.projects([1]).should be_an_instance_of(Array)
24
+ @tm.projects.first.should be_an_instance_of(@klass)
25
+ @tm.projects.first.id.should == 1
26
+ end
27
+
28
+ it "should be load all projects based on attributes" do
29
+ projects = @tm.projects(:id => 1)
30
+ projects.should be_an_instance_of(Array)
31
+ projects.first.should be_an_instance_of(@klass)
32
+ projects.first.id.should == 1
33
+ end
34
+
35
+ it "should be able to load a single project based on id" do
36
+ project = @tm.project(1)
37
+ project.should be_an_instance_of(@klass)
38
+ project.name.should == 'project'
39
+ end
40
+
41
+ it "should be able to load a single project by attributes" do
42
+ project = @tm.project(:id => 1)
43
+ project.should be_an_instance_of(@klass)
44
+ project.name.should == 'project'
45
+ end
46
+ end
@@ -0,0 +1,23 @@
1
+ $:.unshift(File.expand_path(File.dirname(__FILE__) + '/../lib'))
2
+ require 'taskmapper'
3
+ require 'taskmapper-jira'
4
+ require 'rspec/expectations'
5
+
6
+ class FakeJiraTool
7
+ attr_accessor :call_stack, :returns
8
+
9
+ def initialize
10
+ @call_stack = []
11
+ @returns = {}
12
+ end
13
+
14
+ def method_missing *args
15
+ @call_stack << args
16
+ @returns.delete(args.first) if @returns.key?(args.first)
17
+ end
18
+ end
19
+
20
+ RSpec.configure do |config|
21
+ config.mock_framework = :rspec
22
+ end
23
+
@@ -0,0 +1,19 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "TaskMapper::Provider::Jira" do
4
+ before(:each) do
5
+ @url = "some_url"
6
+ @fj = FakeJiraTool.new
7
+ Jira4R::JiraTool.stub!(:new).with(2, @url).and_return(@fj)
8
+ @tm = TaskMapper.new(:jira, :username => 'testing', :password => 'testing', :url => @url)
9
+ end
10
+
11
+ it "should be able to instantiate a new taskmapper instance" do
12
+ @tm.should be_an_instance_of(TaskMapper)
13
+ @tm.should be_a_kind_of(TaskMapper::Provider::Jira)
14
+ end
15
+
16
+ it "should validate authentication with the valid method" do
17
+ @tm.valid?.should be_true
18
+ end
19
+ end
@@ -0,0 +1,49 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe TaskMapper::Provider::Jira::Ticket do
4
+ before(:each) do
5
+ @url = "some_url"
6
+ @fj = FakeJiraTool.new
7
+ @project_jira = Struct.new(:id, :name, :description).new(1, 'project', 'project description')
8
+ @ticket = Struct.new(:id,
9
+ :status,
10
+ :priority,
11
+ :summary,
12
+ :resolution,
13
+ :created,
14
+ :updated,
15
+ :description, :assignee, :reporter).new(1,'open','high', 'ticket 1', 'none', Time.now, Time.now, 'description', 'myself', 'yourself')
16
+ Jira4R::JiraTool.stub!(:new).with(2, @url).and_return(@fj)
17
+ @fj.stub!(:getProjectsNoSchemes).and_return([@project_jira, @project_jira])
18
+ @fj.stub!(:getProjectById).and_return(@project_jira)
19
+ @fj.stub!(:getIssuesFromJqlSearch).and_return([@ticket])
20
+ @tm = TaskMapper.new(:jira, :username => 'testuser', :password => 'testuser', :url => @url)
21
+ @project_tm = @tm.projects.first
22
+ @klass = TaskMapper::Provider::Jira::Ticket
23
+ end
24
+
25
+ it "should be able to load all tickets" do
26
+ @project_tm.tickets.should be_an_instance_of(Array)
27
+ @project_tm.tickets.first.should be_an_instance_of(@klass)
28
+ end
29
+
30
+ it "should be able to load all tickets based on array of id's" do
31
+ tickets = @project_tm.tickets([1])
32
+ tickets.should be_an_instance_of(Array)
33
+ tickets.first.should be_an_instance_of(@klass)
34
+ tickets.first.id.should == 1
35
+ end
36
+
37
+ it "should be able to load a single ticket based on id" do
38
+ ticket = @project_tm.ticket(1)
39
+ ticket.should be_an_instance_of(@klass)
40
+ ticket.id.should == 1
41
+ end
42
+
43
+ it "should be able to load a single ticket based on attributes" do
44
+ ticket = @project_tm.ticket(:id => 1)
45
+ ticket.should be_an_instance_of(@klass)
46
+ ticket.id.should == 1
47
+ end
48
+
49
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+ require './lib/jira/version'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = 'taskmapper-jira'
8
+ s.version = TaskMapper::Jira::VERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Charles Lowell", "Rafael George"]
11
+ s.email = ["cowboyd@thefrontside.net", "rafael@hybridgroup.com"]
12
+ s.homepage = 'http://github.com/hybridgroup/taskmapper-jira'
13
+ s.summary = %q{taskmapper binding for JIRA}
14
+ s.description = %q{Interact with Atlassian JIRA ticketing system from Ruby}
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: taskmapper-jira
3
+ version: !ruby/object:Gem::Version
4
+ hash: 19
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 3
9
+ - 0
10
+ version: 0.3.0
11
+ platform: ruby
12
+ authors:
13
+ - Charles Lowell
14
+ - Rafael George
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2012-05-11 00:00:00 Z
20
+ dependencies: []
21
+
22
+ description: Interact with Atlassian JIRA ticketing system from Ruby
23
+ email:
24
+ - cowboyd@thefrontside.net
25
+ - rafael@hybridgroup.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files: []
31
+
32
+ files:
33
+ - .gitignore
34
+ - .rbenv-gemsets
35
+ - .rvmrc
36
+ - .travis.yml
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - Rakefile
40
+ - lib/jira/version.rb
41
+ - lib/provider/comment.rb
42
+ - lib/provider/jira.rb
43
+ - lib/provider/project.rb
44
+ - lib/provider/ticket.rb
45
+ - lib/taskmapper-jira.rb
46
+ - spec/comment_spec.rb
47
+ - spec/project_spec.rb
48
+ - spec/spec_helper.rb
49
+ - spec/taskmapper-jira_spec.rb
50
+ - spec/ticket_spec.rb
51
+ - taskmapper-jira.gemspec
52
+ homepage: http://github.com/hybridgroup/taskmapper-jira
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.15
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: taskmapper binding for JIRA
85
+ test_files:
86
+ - spec/comment_spec.rb
87
+ - spec/project_spec.rb
88
+ - spec/spec_helper.rb
89
+ - spec/taskmapper-jira_spec.rb
90
+ - spec/ticket_spec.rb