taskmapper-github 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,2 @@
1
+ ---
2
+ BUNDLE_WITHOUT: ""
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
@@ -0,0 +1 @@
1
+ ticketmaster-github
@@ -0,0 +1 @@
1
+ 1.9.2-p290
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.8.7
4
+ - 1.9.2
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source "http://rubygems.org"
2
+ gem "taskmapper", "~> 0.8"
3
+ gem "octokit", "~> 0.6"
4
+ group :development do
5
+ gem "jeweler", "~> 1.6"
6
+ gem "rspec", "~> 2.3"
7
+ gem "fakeweb", "~> 1.3"
8
+ gem "simplecov", "~> 0.5", :platforms => :ruby_19
9
+ gem "rcov", "~> 1.0", :platforms => :ruby_18
10
+ end
@@ -0,0 +1,72 @@
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
+ addressable (2.2.7)
14
+ builder (3.0.0)
15
+ diff-lcs (1.1.3)
16
+ fakeweb (1.3.0)
17
+ faraday (0.7.6)
18
+ addressable (~> 2.2)
19
+ multipart-post (~> 1.1)
20
+ rack (~> 1.1)
21
+ faraday_middleware (0.7.0)
22
+ faraday (~> 0.7.3)
23
+ git (1.2.5)
24
+ hashie (1.2.0)
25
+ i18n (0.6.0)
26
+ jeweler (1.8.3)
27
+ bundler (~> 1.0)
28
+ git (>= 1.2.5)
29
+ rake
30
+ rdoc
31
+ json (1.6.5)
32
+ multi_json (1.0.4)
33
+ multipart-post (1.1.5)
34
+ octokit (0.6.5)
35
+ addressable (~> 2.2.6)
36
+ faraday (~> 0.7.4)
37
+ faraday_middleware (~> 0.7.0)
38
+ hashie (~> 1.2.0)
39
+ multi_json (~> 1.0.2)
40
+ rack (1.4.1)
41
+ rake (0.9.2.2)
42
+ rcov (1.0.0)
43
+ rdoc (3.12)
44
+ json (~> 1.4)
45
+ rspec (2.8.0)
46
+ rspec-core (~> 2.8.0)
47
+ rspec-expectations (~> 2.8.0)
48
+ rspec-mocks (~> 2.8.0)
49
+ rspec-core (2.8.0)
50
+ rspec-expectations (2.8.0)
51
+ diff-lcs (~> 1.1.2)
52
+ rspec-mocks (2.8.0)
53
+ simplecov (0.6.1)
54
+ multi_json (~> 1.0)
55
+ simplecov-html (~> 0.5.3)
56
+ simplecov-html (0.5.3)
57
+ taskmapper (0.8.0)
58
+ activeresource (~> 3.0)
59
+ activesupport (~> 3.0)
60
+ hashie (~> 1.2)
61
+
62
+ PLATFORMS
63
+ ruby
64
+
65
+ DEPENDENCIES
66
+ fakeweb (~> 1.3)
67
+ jeweler (~> 1.6)
68
+ octokit (~> 0.6)
69
+ rcov (~> 1.0)
70
+ rspec (~> 2.3)
71
+ simplecov (~> 0.5)
72
+ taskmapper (~> 0.8)
@@ -0,0 +1,19 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard 'rspec', :version => 2 do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
+ watch('spec/spec_helper.rb') { "spec" }
8
+
9
+ # Rails example
10
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
+ watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
+ watch('config/routes.rb') { "spec/routing" }
15
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
+ # Capybara request specs
17
+ watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
18
+ end
19
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2010 The Hybrid Group
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,86 @@
1
+ # taskmapper-github
2
+
3
+ This is a provider for [taskmapper](http://ticketrb.com). It provides interoperability with [Github](http://www.github.com/) and its issue tracking system through the taskmapper gem.
4
+
5
+ # Usage and Examples
6
+
7
+ First we have to instantiate a new taskmapper instance:
8
+ github = TaskMapper.new(:github, {:login => "coder", :token => "m4st3r!"})
9
+
10
+ If you do not pass in the token and the username, it will only access public information for the account.
11
+
12
+ == Finding Projects(Repositories)
13
+
14
+ You can find your own projects by doing:
15
+
16
+ projects = github.projects # Will return all your repositories
17
+ projects = github.projects(['your_repo1', 'your_repo2'])
18
+ project = github.project('your_repo')
19
+
20
+ Also you can access other users repos
21
+
22
+ project = github.project.find(:first, {:user => 'other_user', :repo => 'his_repo'})
23
+
24
+ Or even make a search with an array
25
+
26
+ projects = github.project.find(:all, ['ruby','git'])
27
+
28
+ == Finding Tickets(Issues)
29
+
30
+ tickets = project.tickets # All open issues
31
+ tickets = project.tickets(:all, {:state => 'closed'}) # All closed tickets
32
+ ticket = project.ticket(<issue_number>)
33
+
34
+ == Open Tickets
35
+
36
+ ticket = project.ticket!({:title => "New ticket", :body => "Body for the very new ticket"})
37
+
38
+ == Close a ticket
39
+
40
+ ticket = ticket.close
41
+
42
+ == Reopen a ticket
43
+
44
+ ticket = ticket.reopen
45
+
46
+ = Update a ticket
47
+
48
+ ticket.title = "New title"
49
+ ticket.body = "New body"
50
+ ticket.save
51
+
52
+ == Finding Comments
53
+ comments = ticket.comments
54
+
55
+ == Create Comment
56
+ comment = ticket.comment!("your comment goes here")
57
+
58
+ ## Requirements
59
+
60
+ * rubygems (obviously)
61
+ * taskmapper gem (latest version preferred)
62
+ * jeweler gem (only if you want to repackage and develop)
63
+ * Octopi gem provdes interface to Github
64
+
65
+ The taskmapper gem should automatically be installed during the installation of this gem if it is not already installed.
66
+
67
+ ## Other Notes
68
+
69
+ Since this and the taskmapper gem is still primarily a work-in-progress, minor changes may be incompatible with previous versions. Please be careful about using and updating this gem in production.
70
+
71
+ If you see or find any issues, feel free to open up an issue report.
72
+
73
+
74
+ ## Note on Patches/Pull Requests
75
+
76
+ * Fork the project.
77
+ * Make your feature addition or bug fix.
78
+ * Add tests for it. This is important so we don't break it in a
79
+ future version unintentionally.
80
+ * Commit, do not mess with rakefile, version, or history.
81
+ (if you want to have your own version, that is fine but bump version in a commit by itself so we can ignore when I pull)
82
+ * Send us a pull request. Bonus points for topic branches.
83
+
84
+ ## Copyright
85
+
86
+ Copyright (c) 2010-2011 The Hybrid Group. See LICENSE for details.
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "taskmapper-github"
8
+ gem.summary = %Q{The github provider for taskmapper}
9
+ gem.description = %Q{This provides an interface with github through the taskmapper gem.}
10
+ gem.email = "hong.quach@abigfisch.com"
11
+ gem.homepage = "http://github.com/kiafaldorius/taskmapper-github"
12
+ gem.authors = ["HybridGroup"]
13
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
14
+ end
15
+ Jeweler::GemcutterTasks.new
16
+ rescue LoadError
17
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
18
+ end
19
+
20
+ require 'rspec/core'
21
+ require 'rspec/core/rake_task'
22
+ RSpec::Core::RakeTask.new(:spec) do |spec|
23
+ spec.pattern = FileList['spec/**/*_spec.rb']
24
+ end
25
+
26
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
27
+ spec.pattern = 'spec/**/*_spec.rb'
28
+ spec.rcov = true
29
+ end
30
+
31
+ task :default => :spec
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.10.0
@@ -0,0 +1,91 @@
1
+ module TaskMapper::Provider
2
+ module Github
3
+ # The comment class for taskmapper-github
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
+ attr_accessor :prefix_options
10
+
11
+ def initialize(*object)
12
+ if object.first
13
+ object = object.first
14
+ unless object.is_a? Hash
15
+ hash = {:id => object.id,
16
+ :body => object.body,
17
+ :created_at => object.created_at,
18
+ :author => object.user.login}
19
+ else
20
+ hash = object
21
+ end
22
+ super hash
23
+ end
24
+ end
25
+
26
+ def author
27
+ self.user.login
28
+ end
29
+
30
+ def created_at
31
+ @created_at ||= begin
32
+ Time.parse(self[:created_at])
33
+ rescue
34
+ self[:created_at]
35
+ end
36
+ end
37
+
38
+ def updated_at
39
+ @updated_at ||= begin
40
+ Time.parse(self[:updated_at])
41
+ rescue
42
+ self[:updated_at]
43
+ end
44
+ end
45
+
46
+ # declare needed overloaded methods here
47
+
48
+ def self.find_by_attributes(project_id, ticket_id, attributes = {})
49
+ search_by_attribute(self.find_all(project_id, ticket_id), attributes)
50
+ end
51
+
52
+ def self.find_all(project_id, ticket_id)
53
+ TaskMapper::Provider::Github.api.issue_comments(project_id, ticket_id).collect do |comment|
54
+ comment.merge!(:project_id => project_id, :ticket_id => ticket_id)
55
+ clean_body! comment
56
+ self.new comment
57
+ end
58
+ end
59
+
60
+ def self.create(project_id, ticket_id, comment)
61
+ github_comment = TaskMapper::Provider::Github.api.add_comment(project_id, ticket_id, comment)
62
+ github_comment.merge!(:project_id => project_id, :ticket_id => ticket_id)
63
+ flat_body github_comment
64
+ self.new github_comment
65
+ end
66
+
67
+ #See https://www.kanbanpad.com/projects/31edb8d134e7967c1f0d#!xt-4f994d17014289000707433f
68
+ def self.flat_body(comment_hashie)
69
+ comment_hashie.body = comment_hashie.body.body
70
+ comment_hashie
71
+ end
72
+
73
+ # See https://www.kanbanpad.com/projects/31edb8d134e7967c1f0d#!xt-4f994f2101428900070759fd
74
+ def self.clean_body!(comment)
75
+ comment.body = comment.body.sub(/\A---\s\sbody:\s/, '').gsub(/\s\z/, '')
76
+ end
77
+
78
+ def save
79
+ update_comment(project_id, id, body)
80
+ end
81
+
82
+ private
83
+ def update_comment(repo, number, comment, options = {})
84
+ TaskMapper::Provider::Github.api.update_comment repo, number, comment, options
85
+ true
86
+ end
87
+
88
+
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,60 @@
1
+ module TaskMapper::Provider
2
+ # This is the Github Provider for taskmapper
3
+ module Github
4
+ include TaskMapper::Provider::Base
5
+
6
+ class << self
7
+ attr_accessor :login, :api, :user_token, :valid_user
8
+ end
9
+
10
+ # This is for cases when you want to instantiate using TaskMapper::Provider::Github.new(auth)
11
+ def self.new(auth = {})
12
+ TaskMapper.new(:github, auth)
13
+ end
14
+
15
+ # declare needed overloaded methods here
16
+ def authorize(auth = {})
17
+ @authentication ||= TaskMapper::Authenticator.new(auth)
18
+ auth = @authentication
19
+ login = auth.login || auth.username
20
+ if auth.login.blank? and auth.username.blank?
21
+ raise TaskMapper::Exception.new('Please provide at least a username')
22
+ elsif auth.token
23
+ TaskMapper::Provider::Github.login = login
24
+ TaskMapper::Provider::Github.user_token = auth.token
25
+ TaskMapper::Provider::Github.api = Octokit::Client.new(:login => login, :token => auth.token)
26
+ elsif auth.password
27
+ TaskMapper::Provider::Github.login = login
28
+ TaskMapper::Provider::Github.user_token = auth.token
29
+ TaskMapper::Provider::Github.api = Octokit::Client.new(:login => login, :password => auth.password)
30
+ else
31
+ TaskMapper::Provider::Github.login = login
32
+ TaskMapper::Provider::Github.user_token = nil
33
+ TaskMapper::Provider::Github.api = Octokit::Client.new(:login => login)
34
+ end
35
+ end
36
+
37
+ def valid?
38
+ begin
39
+ TaskMapper::Provider::Github.valid_user = TaskMapper::Provider::Github.api.user.total_private_repos >= 0
40
+ rescue
41
+ false
42
+ end
43
+ end
44
+
45
+ def projects(*options)
46
+ Project.find(options)
47
+ end
48
+
49
+ def project(*project)
50
+ unless project.empty?
51
+ Project.find_by_id(project.first)
52
+ else
53
+ super
54
+ end
55
+ end
56
+
57
+ end
58
+ end
59
+
60
+
@@ -0,0 +1,110 @@
1
+ module TaskMapper::Provider
2
+ module Github
3
+ # Project class for taskmapper-github
4
+ #
5
+ #
6
+ class Project < TaskMapper::Provider::Base::Project
7
+
8
+ # declare needed overloaded methods here
9
+ def initialize(*object)
10
+ if object.first
11
+ object = object.first
12
+ @system_data = {:client => object}
13
+ unless object.is_a? Hash
14
+ hash = {:description => object.description,
15
+ :created_at => object.created_at,
16
+ :updated_at => object.created_at,
17
+ :name => object.name,
18
+ :id => object.name,
19
+ :owner => object.owner}
20
+ else
21
+ hash = object
22
+ end
23
+ super hash
24
+ end
25
+ end
26
+
27
+ def created_at
28
+ begin
29
+ Time.parse(self[:created_at])
30
+ rescue
31
+ self[:created_at]
32
+ end
33
+ end
34
+
35
+ def updated_at
36
+ begin
37
+ Time.parse(self[:created_at])
38
+ rescue
39
+ self[:created_at]
40
+ end
41
+ end
42
+
43
+ def id
44
+ "#{self.owner.login}/#{self[:name]}"
45
+ end
46
+
47
+ # copy from this.copy(that) copies that into this
48
+ def copy(project)
49
+ project.tickets.each do |ticket|
50
+ copy_ticket = self.ticket!(:title => ticket.title, :description => ticket.description)
51
+ ticket.comments.each do |comment|
52
+ copy_ticket.comment!(:body => comment.body)
53
+ sleep 1
54
+ end
55
+ end
56
+ end
57
+
58
+ def self.find(*options)
59
+ if options[0].empty?
60
+ projects = self.find_all
61
+ elsif options[0].first.is_a? Array
62
+ options[0].first.collect { |name| self.find_by_id(name) }
63
+ elsif options[0].first.is_a? String
64
+ self.find_by_id(options[0].first)
65
+ elsif options[0].first.is_a? Hash
66
+ self.find_by_attributes(options[0].first)
67
+ end
68
+ end
69
+
70
+ def self.find_by_attributes(attributes = {})
71
+ search_by_attribute(self.find_all, attributes)
72
+ end
73
+
74
+ def self.find_by_id(id)
75
+ id = "#{TaskMapper::Provider::Github.login}/#{id}" unless id.include?("/")
76
+ self.new TaskMapper::Provider::Github.api.repository(id)
77
+ end
78
+
79
+ def self.find_all
80
+ repos = []
81
+ user_repos = TaskMapper::Provider::Github.api.repositories(TaskMapper::Provider::Github.login).collect { |repository|
82
+ self.new repository }
83
+ repos = repos + user_repos
84
+ if TaskMapper::Provider::Github.valid_user
85
+ org_repos = TaskMapper::Provider::Github.api.organization_repositories.collect { |repository|
86
+ self.new repository }
87
+ repos = repos + org_repos
88
+ end
89
+ repos
90
+ end
91
+
92
+ def tickets(*options)
93
+ TaskMapper::Provider::Github::Ticket.find(self.id, options)
94
+ end
95
+
96
+ def ticket(*options)
97
+ unless options.empty?
98
+ TaskMapper::Provider::Github::Ticket.find_by_id(self.id, options.first)
99
+ else
100
+ TaskMapper::Provider::Github::Ticket
101
+ end
102
+ end
103
+
104
+ def ticket!(*options)
105
+ TaskMapper::Provider::Github::Ticket.open(self.id, options.first)
106
+ end
107
+ end
108
+
109
+ end
110
+ end