trellohub 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7d99116570f13e82e28ce68a35b5f1e6fd7a9b4e
4
+ data.tar.gz: 04a5fdea4cf49b3cf28abc353a2f0a982752eae0
5
+ SHA512:
6
+ metadata.gz: 9e9cddc0aa24c8e5c17217d94c879e4ef84fc7282b100d72020ccdd06af4bbbf9596e6f4623288c61c382cec4f677fac1145c2ece5c0684788a96f4e824323a8
7
+ data.tar.gz: 329245e579d8c0927b8f6c2520be973f69ed23662e0166e9f4518bbd5a8a434dc329e611b57c934b24353b0f052fc7853297b96ef6814ed51002482fbb584b43
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ boards
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in trellohub.gemspec
4
+ gemspec
5
+
6
+ gem 'pry'
7
+ gem 'awesome_print', require: 'ap'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 linyows
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,79 @@
1
+ Trellohub
2
+ =========
3
+
4
+ Trellohub is uniform task management by synchronizing the github issues and trello cards.
5
+
6
+ [![Gem Version](https://badge.fury.io/rb/trellohub.png)][gem]
7
+ [![Build Status](https://secure.travis-ci.org/linyows/trellohub.png?branch=master)][travis]
8
+ [![Dependency Status](https://gemnasium.com/linyows/trellohub.png?travis)][gemnasium]
9
+ [![Code Climate](https://codeclimate.com/github/linyows/trellohub.png)][codeclimate]
10
+ [![Coverage Status](https://coveralls.io/repos/linyows/trellohub/badge.png?branch=master)][coveralls]
11
+
12
+ [gem]: https://rubygems.org/gems/trellohub
13
+ [travis]: http://travis-ci.org/linyows/trellohub
14
+ [gemnasium]: https://gemnasium.com/linyows/trellohub
15
+ [codeclimate]: https://codeclimate.com/github/linyows/trellohub
16
+ [coveralls]: https://coveralls.io/r/linyows/trellohub
17
+
18
+ Installation
19
+ ------------
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'trellohub'
25
+ ```
26
+
27
+ And then execute:
28
+
29
+ ```sh
30
+ $ bundle
31
+ ```
32
+
33
+ Or install it yourself as:
34
+
35
+ ```sh
36
+ $ gem install trellohub
37
+ ```
38
+
39
+ Usage
40
+ -----
41
+
42
+ ```sh
43
+ $ cp boards/example.yml boards/your_board_name.yml
44
+ ```
45
+
46
+ edit `boards/your_board_name.yml`:
47
+
48
+ ```yml
49
+ ```
50
+
51
+ Synchronizing
52
+ -------------
53
+
54
+ GitHub Issues | Trello Cards | Description
55
+ ------------- | ------------ | -----------
56
+ status changes | status changes | open, closed : create, delete
57
+ milestone changes | status changes | when setted milestones
58
+ labels change | list changes | label: todo => list: To Do
59
+ title changes | title changes | card title: 'repo_name#issue_number title'
60
+ asignee changes | member changes | first member is issue assignee
61
+
62
+ Contributing
63
+ ------------
64
+
65
+ 1. Fork it ( http://github.com/linyows/trellohub/fork )
66
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
67
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
68
+ 4. Push to the branch (`git push origin my-new-feature`)
69
+ 5. Create new Pull Request
70
+
71
+ Authors
72
+ -------
73
+
74
+ - [linyows](https://github.com/linyows)
75
+
76
+ License
77
+ -------
78
+
79
+ The MIT License (MIT)
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/trellohub.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'octokit'
2
+ require 'trell'
3
+ require 'trellohub/version'
4
+ require 'trellohub/configurable'
5
+ require 'trellohub/board'
6
+ require 'trellohub/list'
7
+ require 'trellohub/lists'
8
+ require 'trellohub/card'
9
+ require 'trellohub/cards'
10
+ require 'trellohub/member'
11
+ require 'trellohub/synchronal'
12
+
13
+ module Trellohub
14
+ class << self
15
+ include Trellohub::Configurable
16
+ include Trellohub::Synchronal
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module Trellohub
2
+ module Board
3
+ class << self
4
+ def id
5
+ Trellohub.board_id
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,90 @@
1
+ require 'trellohub/board'
2
+ require 'trellohub/cards'
3
+
4
+ module Trellohub
5
+ class Card
6
+ class << self
7
+ include Trellohub::Cards
8
+ end
9
+
10
+ attr_accessor(*self.all_attributes)
11
+ alias_method :repo, :repository
12
+
13
+ def repository_name
14
+ repo.split('/').last
15
+ end
16
+
17
+ def import(card)
18
+ card.attrs.keys.each do |attr|
19
+ instance_variable_set(:"@#{attr}", card.send(attr))
20
+ end
21
+ end
22
+
23
+ def import_from_issue(repository, issue)
24
+ @idBoard = Trellohub::Board.id
25
+ @repository = repository
26
+ @issue = issue.dup
27
+
28
+ build_key
29
+ build_name
30
+ build_desc
31
+ build_milestone
32
+
33
+ assign_members
34
+ assign_list
35
+ end
36
+
37
+ def build_key
38
+ @key = "#{repository_name}##{@issue.number}"
39
+ end
40
+
41
+ def build_name
42
+ @name = "#{repository_name}##{@issue.number} #{@issue.title}"
43
+ end
44
+
45
+ def build_desc
46
+ @desc = "#{Octokit.web_endpoint}#{repo}/issues/#{@issue.number}"
47
+ end
48
+
49
+ def build_milestone
50
+ return unless @issue.milestone
51
+ @milestone = @issue.milestone.title
52
+ end
53
+
54
+ def assign_members
55
+ return unless @issue.assignee
56
+
57
+ member = Trellohub::Member.find_by_github_user(@issue.assignee.login)
58
+ unless member.nil?
59
+ @idMembers = [member.id]
60
+ @members = [member.username]
61
+ end
62
+ end
63
+
64
+ def assign_list
65
+ labels = @issue.labels.map(&:name).uniq
66
+ list = Trellohub.list_by(labels: labels)
67
+ return unless list
68
+ @idList = list.id
69
+ @list_name = list.name
70
+ end
71
+
72
+ def save_to_trello
73
+ end
74
+
75
+ def save_to_github
76
+ end
77
+
78
+ def export
79
+ Hash[self.class.valid_attributes.map { |key|
80
+ [key, instance_variable_get(:"@#{key}")]
81
+ }]
82
+ end
83
+
84
+ def to_hash
85
+ Hash[self.class.all_attributes.map { |key|
86
+ [key, instance_variable_get(:"@#{key}")]
87
+ }]
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,58 @@
1
+ require 'trellohub/board'
2
+
3
+ module Trellohub
4
+ module Cards
5
+ def valid_attributes
6
+ %i(
7
+ id
8
+ checkItemStates
9
+ closed
10
+ dateLastActivity
11
+ desc
12
+ descData
13
+ idBoard
14
+ idList
15
+ idMembersVoted
16
+ idShort
17
+ idAttachmentCover
18
+ name
19
+ pos
20
+ shortLink
21
+ badges
22
+ due
23
+ idChecklists
24
+ idMembers
25
+ labels
26
+ shortUrl
27
+ subscribed
28
+ )
29
+ end
30
+
31
+ def other_attributes
32
+ %i(
33
+ key
34
+ repository
35
+ list_name
36
+ members
37
+ milestore
38
+ issue
39
+ )
40
+ end
41
+
42
+ def all_attributes
43
+ self.valid_attributes + self.other_attributes
44
+ end
45
+
46
+ def all
47
+ @all || self.all!
48
+ end
49
+
50
+ def all!
51
+ @all = Trell.cards(Trellohub::Board.id)
52
+ end
53
+
54
+ def all_clear
55
+ self.all.each { |card| Trell.delete_card(card.id) }
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,128 @@
1
+ require 'yaml'
2
+ require 'trellohub/core_ext/hash'
3
+
4
+ module Trellohub
5
+ module Configurable
6
+ CONFIGURATIONS_KEYS = %i(
7
+ config_file
8
+ board_id
9
+ repositories
10
+ milestones
11
+ lists
12
+ trello_application_key
13
+ trello_application_token
14
+ github_access_token
15
+ github_api_endpoint
16
+ github_web_endpoint
17
+ )
18
+
19
+ attr_accessor(*CONFIGURATIONS_KEYS)
20
+ alias_method :repos, :repositories
21
+
22
+ def configure
23
+ yield self
24
+ end
25
+
26
+ def reset
27
+ @config_file = ENV['CONFIG_FILE']
28
+ @board_id = ENV['BOARD_ID']
29
+ @repositories = []
30
+ @milestones = []
31
+ @lists = []
32
+ @trello_application_key = ENV['TRELLO_APPLICATION_KEY']
33
+ @trello_application_token = ENV['TRELLO_APPLICATION_TOKEN']
34
+ @github_access_token = ENV['GITHUB_ACCESS_TOKEN']
35
+ @github_api_endpoint = Octokit.api_endpoint
36
+ @github_web_endpoint = Octokit.web_endpoint
37
+ end
38
+
39
+ def load!(config_file = nil)
40
+ config_file ||= @config_file
41
+
42
+ YAML.load_file(config_file).
43
+ symbolize_keys.
44
+ slice(*Trellohub::Configurable.keys).
45
+ each do |key, value|
46
+ if value.is_a?(Array)
47
+ value = value.map { |v| v.is_a?(Hash) ? Trellohub::List.new(v) : v }
48
+ end
49
+ instance_variable_set(:"@#{key}", value)
50
+ end
51
+ end
52
+
53
+ def init_trell
54
+ Trell.configure do |c|
55
+ c.application_key = @trello_application_key
56
+ c.application_token = @trello_application_token
57
+ end
58
+ end
59
+
60
+ def init_octokit
61
+ Octokit.configure do |c|
62
+ c.access_token = @github_access_token
63
+ c.api_endpoint = @github_api_endpoint
64
+ c.web_endpoint = @github_web_endpoint
65
+ c.auto_paginate = true
66
+ end
67
+ end
68
+
69
+ def setup(config_file = nil)
70
+ reset
71
+ load!(config_file)
72
+ init_trell
73
+ init_octokit
74
+ self
75
+ end
76
+
77
+ def configurations
78
+ Hash[Trellohub::Configurable.keys.map { |key|
79
+ [key, instance_variable_get(:"@#{key}")]
80
+ }]
81
+ end
82
+ alias_method :conf, :configurations
83
+
84
+ def list_by(name: nil, default: nil, label: nil, labels: [])
85
+ case
86
+ when name
87
+ @lists.find { |list| list.name == name }
88
+ when default
89
+ @lists.find { |list| list.default == true }
90
+ when label
91
+ @lists.find { |list| list.issue_label == label }
92
+ else
93
+ labels.each { |label_name|
94
+ list = Trellohub.list_by(label: label_name)
95
+ return list if list
96
+ } unless labels.empty?
97
+
98
+ Trellohub.default_list
99
+ end
100
+ end
101
+
102
+ def default_list
103
+ Trellohub.list_by(default: true)
104
+ end
105
+
106
+ def list_names
107
+ @lists.map(&:name).compact
108
+ end
109
+
110
+ def issue_labels
111
+ @lists.map(&:issue_label).compact
112
+ end
113
+
114
+ def github_api_endpoint
115
+ File.join(@github_api_endpoint, '')
116
+ end
117
+
118
+ def github_web_endpoint
119
+ File.join(@github_web_endpoint, '')
120
+ end
121
+
122
+ class << self
123
+ def keys
124
+ @keys ||= CONFIGURATIONS_KEYS
125
+ end
126
+ end
127
+ end
128
+ end
@@ -0,0 +1,19 @@
1
+ class Hash
2
+ def slice(*keys)
3
+ keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) }
4
+ end
5
+
6
+ def symbolize_keys
7
+ self.each_with_object(self.class.new) { |(k, v), hash|
8
+ v = v.symbolize_keys if v.class.name == self.class.name
9
+ hash[:"#{k}"] = v
10
+ }
11
+ end
12
+
13
+ def stringify_keys
14
+ self.each_with_object(self.class.new) { |(k, v), hash|
15
+ v = v.stringify_keys if v.is_a?(self.class)
16
+ hash["#{k}"] = v
17
+ }
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ require 'ostruct'
2
+ require 'trellohub/board'
3
+ require 'trellohub/lists'
4
+
5
+ module Trellohub
6
+ class List < OpenStruct
7
+ def id
8
+ @id ||= find_id
9
+ end
10
+
11
+ def find_id
12
+ current_list = self.class.find_by(name: name)
13
+
14
+ list = case
15
+ when current_list && current_list.closed
16
+ Trell.update_list(current_list.id, closed: false)
17
+ when current_list.nil?
18
+ Trell.create_list(name: name, idBoard: board_id)
19
+ else
20
+ current_list
21
+ end
22
+
23
+ list.id
24
+ end
25
+
26
+ def board_id
27
+ Trellohub::Board.id
28
+ end
29
+
30
+ class << self
31
+ include Lists
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,17 @@
1
+ require 'trellohub/board'
2
+
3
+ module Trellohub
4
+ module Lists
5
+ def all
6
+ @all || self.all!
7
+ end
8
+
9
+ def all!
10
+ @all = Trell.lists(Trellohub::Board.id)
11
+ end
12
+
13
+ def find_by(name: nil)
14
+ self.all.find { |list| list.name == name }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ module Trellohub
2
+ module Member
3
+ class << self
4
+ def find_by_github_user(username)
5
+ @members = {} if @members.nil?
6
+ @members[:"#{username}"] ||= Trell.member(username)
7
+ rescue Trell::NotFound
8
+ nil
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,56 @@
1
+ module Trellohub
2
+ module Synchronal
3
+ SYNCHRONAL_KEYS = %i(
4
+ temporary_cards_by_issues
5
+ temporary_cards
6
+ )
7
+
8
+ attr_reader(*SYNCHRONAL_KEYS)
9
+
10
+ def synchronize
11
+ end
12
+ alias_method :sync, :synchronize
13
+
14
+ def issues(repo)
15
+ return Octokit.issues(repo) if Trellohub.milestones.empty?
16
+
17
+ milestones = Octokit.milestones(repo)
18
+ return [] if milestones.empty?
19
+
20
+ milestones.each.with_object([]) do |milestone, milestoned_issues|
21
+ temp_issues = Octokit.issues(repo, milestone: milestone.number)
22
+ milestoned_issues.concat(temp_issues) unless temp_issues.empty?
23
+ end
24
+ end
25
+
26
+ def issues_cards
27
+ @issue_cards ||= Trellohub.repos.each.with_object([]) do |repo, cards|
28
+ cards.concat issues_cards_on(repo)
29
+ end
30
+ end
31
+
32
+ def issues_cards_on(repo)
33
+ issues(repo).each.with_object([]) do |issue, cards|
34
+ temp_card = Trellohub::Card.new
35
+ temp_card.import_from_issue repo, issue
36
+ cards << temp_card
37
+ end
38
+ end
39
+
40
+ def trello_cards
41
+ @trello_cards ||= Trellohub::Card.all.
42
+ each.with_object([]) do |card, cards|
43
+ temp_card = Trellohub::Card.new
44
+ temp_card.import card
45
+ cards << temp_card
46
+ end
47
+ end
48
+
49
+ # def import_from_github_issues
50
+ # issued_cards(repo, 'open').each do |card|
51
+ # Trell.create_card card.slice(*valid_card_attributes)
52
+ # end
53
+ # end
54
+ # alias_method :import, :import_from_github_issues
55
+ end
56
+ end
@@ -0,0 +1,3 @@
1
+ module Trellohub
2
+ VERSION = "0.0.1"
3
+ end
data/trellohub.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'trellohub/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'trellohub'
8
+ spec.version = Trellohub::VERSION
9
+ spec.authors = ['linyows']
10
+ spec.email = ['linyows@gmail.com']
11
+ spec.summary = %q{Trellohub is uniform task management by synchronizing the github issues and trello cards.}
12
+ spec.description = %q{Trellohub is uniform task management by synchronizing the github issues and trello cards.}
13
+ spec.homepage = 'https://github.com/linyows/trellohub'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'octokit'
22
+ spec.add_dependency 'trell'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.5'
25
+ spec.add_development_dependency 'rake'
26
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trellohub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - linyows
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: trell
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Trellohub is uniform task management by synchronizing the github issues
70
+ and trello cards.
71
+ email:
72
+ - linyows@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - boards/example.yml
83
+ - lib/trellohub.rb
84
+ - lib/trellohub/board.rb
85
+ - lib/trellohub/card.rb
86
+ - lib/trellohub/cards.rb
87
+ - lib/trellohub/configurable.rb
88
+ - lib/trellohub/core_ext/hash.rb
89
+ - lib/trellohub/list.rb
90
+ - lib/trellohub/lists.rb
91
+ - lib/trellohub/member.rb
92
+ - lib/trellohub/synchronal.rb
93
+ - lib/trellohub/version.rb
94
+ - trellohub.gemspec
95
+ homepage: https://github.com/linyows/trellohub
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.0
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Trellohub is uniform task management by synchronizing the github issues and
119
+ trello cards.
120
+ test_files: []