trellohub 0.0.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7d99116570f13e82e28ce68a35b5f1e6fd7a9b4e
4
- data.tar.gz: 04a5fdea4cf49b3cf28abc353a2f0a982752eae0
3
+ metadata.gz: c3e0c1cd2aeef9e9fed641f72a69f7af0c079322
4
+ data.tar.gz: cc7b3945d5f13f745d7667d41416d7cf975dec7a
5
5
  SHA512:
6
- metadata.gz: 9e9cddc0aa24c8e5c17217d94c879e4ef84fc7282b100d72020ccdd06af4bbbf9596e6f4623288c61c382cec4f677fac1145c2ece5c0684788a96f4e824323a8
7
- data.tar.gz: 329245e579d8c0927b8f6c2520be973f69ed23662e0166e9f4518bbd5a8a434dc329e611b57c934b24353b0f052fc7853297b96ef6814ed51002482fbb584b43
6
+ metadata.gz: 9bcd7fa80eef654f76073370b126dfd410560529bfea907c84c65d039e0b7b62f6343b373f1f495e994726eaf3db849070d29991f7a94e7fd84b7b8e5fc7ccc5
7
+ data.tar.gz: c32fecbcb9e4648e6afb75a1825374fe95329617ad7792fa27d44f7baa06b53bd02d30b55ea25a167e957153a8c68a0bf1a7f5681eb336340ff75286160b36d3
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.1
5
+ before_install:
6
+ - gem update bundler
7
+ script:
8
+ - bundle exec rspec
9
+ notifications:
10
+ irc:
11
+ on_success: change
12
+ on_failure: always
13
+ channels:
14
+ - "irc.freenode.org#linyows"
data/Gemfile CHANGED
@@ -5,3 +5,12 @@ gemspec
5
5
 
6
6
  gem 'pry'
7
7
  gem 'awesome_print', require: 'ap'
8
+ gem 'rainbow'
9
+
10
+ group :test do
11
+ gem 'coveralls', require: false
12
+ gem 'rspec', '~> 3.0.0.beta2'
13
+ gem 'simplecov', require: false
14
+ gem 'vcr', '~> 2.4'
15
+ gem 'webmock', '>= 1.9'
16
+ end
data/README.md CHANGED
@@ -46,18 +46,44 @@ $ cp boards/example.yml boards/your_board_name.yml
46
46
  edit `boards/your_board_name.yml`:
47
47
 
48
48
  ```yml
49
+ board_id: 531c1a3524127e**********
50
+ repositories:
51
+ - full_name: organization/project_one
52
+ milestone: Stable Version
53
+ - full_name: organization/project_two
54
+ milestone: Ver2
55
+ - full_name: organization/project_three
56
+ milestone: New Feature
57
+ lists:
58
+ - name: Backlog
59
+ default: true
60
+ - name: To Do
61
+ issue_label: to do
62
+ - name: Doing
63
+ issue_label: doing
64
+ - name: Done
65
+ issue_label: done
66
+ - name: Recent Closed
67
+ issue_closed_at: '>= Time.now.utc -60*60*24*7'
68
+ trello_application_key: 429452e37b7e********************
69
+ trello_application_token: dc71944d87340616f03a7647****************************************
70
+ github_access_token: e17e1c6caa******************************
71
+ ```
72
+
73
+ ```sh
74
+ $ env DEBUG=true env CONFIG_PATH=~/trellohub/boards/your_board_name.yml trellohub
49
75
  ```
50
76
 
51
77
  Synchronizing
52
78
  -------------
53
79
 
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
80
+ GitHub Issues | Trello Cards | Description
81
+ ------------- | ------------ | -----------
82
+ Status(open, closed) changes | Closed(true false) changes | All created by a token user When trellohub creates the issue.
83
+ Milestone changes | Status changes | If setted milestones
84
+ Labels change | List changes | e.g. The "todo" label => The "To Do" list
85
+ Title changes | Title changes | Card title format is 'repo_name#issue_number title'
86
+ Asignee changes | Member changes | First member is issue assignee.
61
87
 
62
88
  Contributing
63
89
  ------------
data/bin/trellohub ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lib = File.expand_path('../../lib', __FILE__)
4
+ require "#{lib}/trellohub"
5
+
6
+ Trellohub.setup
7
+ Trellohub.sync
data/lib/trellohub.rb CHANGED
@@ -1,15 +1,22 @@
1
1
  require 'octokit'
2
2
  require 'trell'
3
+ require 'yaml'
4
+
3
5
  require 'trellohub/version'
4
- require 'trellohub/configurable'
6
+ require 'trellohub/repository'
5
7
  require 'trellohub/board'
6
8
  require 'trellohub/list'
7
- require 'trellohub/lists'
8
9
  require 'trellohub/card'
9
- require 'trellohub/cards'
10
10
  require 'trellohub/member'
11
+ require 'trellohub/form'
12
+ require 'trellohub/configurable'
13
+ require 'trellohub/mocking'
11
14
  require 'trellohub/synchronal'
12
15
 
16
+ require 'trellohub/core_ext/string'
17
+ require 'trellohub/core_ext/array'
18
+ require 'trellohub/core_ext/hash'
19
+
13
20
  module Trellohub
14
21
  class << self
15
22
  include Trellohub::Configurable
@@ -1,90 +1,19 @@
1
1
  require 'trellohub/board'
2
- require 'trellohub/cards'
3
2
 
4
3
  module Trellohub
5
- class Card
4
+ module Card
6
5
  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))
6
+ def all
7
+ @all || self.all!
20
8
  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
9
 
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]
10
+ def all!
11
+ @all = Trell.cards(Trellohub::Board.id, filter: 'all')
61
12
  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
13
 
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
- }]
14
+ def all_clear
15
+ self.all.each { |card| Trell.delete_card(card.id) }
16
+ end
88
17
  end
89
18
  end
90
19
  end
@@ -1,39 +1,52 @@
1
- require 'yaml'
2
- require 'trellohub/core_ext/hash'
3
-
4
1
  module Trellohub
5
2
  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
3
+ class << self
4
+ def keys
5
+ %i(
6
+ config_file
7
+ board_id
8
+ repositories
9
+ lists
10
+ options
11
+ trello_application_key
12
+ trello_application_token
13
+ github_access_token
14
+ github_api_endpoint
15
+ github_web_endpoint
16
+ dry_run
17
+ debug
18
+ )
19
+ end
20
+
21
+ def overrideable_keys
22
+ %i(
23
+ board_id
24
+ trello_application_key
25
+ trello_application_token
26
+ github_access_token
27
+ github_api_endpoint
28
+ github_web_endpoint
29
+ dry_run
30
+ debug
31
+ )
32
+ end
33
+ end
34
+
35
+ attr_accessor(*self.keys)
21
36
 
22
37
  def configure
23
38
  yield self
24
39
  end
25
40
 
26
- def reset
41
+ def default!
27
42
  @config_file = ENV['CONFIG_FILE']
28
- @board_id = ENV['BOARD_ID']
29
43
  @repositories = []
30
- @milestones = []
31
44
  @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']
45
+ @options = { default_assignee: true, default_member: true }
35
46
  @github_api_endpoint = Octokit.api_endpoint
36
47
  @github_web_endpoint = Octokit.web_endpoint
48
+ @dry_run = false
49
+ @debug = true
37
50
  end
38
51
 
39
52
  def load!(config_file = nil)
@@ -43,34 +56,44 @@ module Trellohub
43
56
  symbolize_keys.
44
57
  slice(*Trellohub::Configurable.keys).
45
58
  each do |key, value|
46
- if value.is_a?(Array)
47
- value = value.map { |v| v.is_a?(Hash) ? Trellohub::List.new(v) : v }
59
+ case key
60
+ when :repositories
61
+ value = value.map { |v| Trellohub::Repository.new(v) }
62
+ when :lists
63
+ value = value.map { |v| Trellohub::List.new(v) }
48
64
  end
49
65
  instance_variable_set(:"@#{key}", value)
50
66
  end
51
67
  end
52
68
 
53
- def init_trell
69
+ def override!
70
+ Trellohub::Configurable.overrideable_keys.each do |key|
71
+ env_name = key.to_s.upcase
72
+ instance_variable_set(:"@#{key}", ENV[env_name]) if ENV[env_name]
73
+ end
74
+ end
75
+
76
+ def init!
54
77
  Trell.configure do |c|
55
78
  c.application_key = @trello_application_key
56
79
  c.application_token = @trello_application_token
57
80
  end
58
- end
59
81
 
60
- def init_octokit
61
82
  Octokit.configure do |c|
62
83
  c.access_token = @github_access_token
63
84
  c.api_endpoint = @github_api_endpoint
64
85
  c.web_endpoint = @github_web_endpoint
65
86
  c.auto_paginate = true
66
87
  end
88
+
89
+ self.dry_run = true if @dry_run
67
90
  end
68
91
 
69
92
  def setup(config_file = nil)
70
- reset
93
+ default!
71
94
  load!(config_file)
72
- init_trell
73
- init_octokit
95
+ override!
96
+ init!
74
97
  self
75
98
  end
76
99
 
@@ -111,6 +134,23 @@ module Trellohub
111
134
  @lists.map(&:issue_label).compact
112
135
  end
113
136
 
137
+ def repository_by(full_name: nil, milestone: nil)
138
+ case
139
+ when full_name
140
+ @repositories.find { |repo| repo.full_name == full_name }
141
+ when milestone
142
+ @repositories.find { |repo| repo.milestone == milestone }
143
+ end
144
+ end
145
+
146
+ def repository_full_names
147
+ @repositories.map(&:full_names).compact
148
+ end
149
+
150
+ def repository_milestones
151
+ @repositories.map(&:milestone).uniq
152
+ end
153
+
114
154
  def github_api_endpoint
115
155
  File.join(@github_api_endpoint, '')
116
156
  end
@@ -119,10 +159,9 @@ module Trellohub
119
159
  File.join(@github_web_endpoint, '')
120
160
  end
121
161
 
122
- class << self
123
- def keys
124
- @keys ||= CONFIGURATIONS_KEYS
125
- end
162
+ def dry_run=(bool)
163
+ @dry_run = bool
164
+ Mocking.send(@dry_run ? :start : :stop)
126
165
  end
127
166
  end
128
167
  end
@@ -0,0 +1,10 @@
1
+ class Array
2
+ def max_lengths
3
+ self.each_with_object([]) do |line, obj|
4
+ line.each.with_index do |v, i|
5
+ length = v.to_s.width
6
+ obj[i] = length if obj[i].nil? || obj[i] < length
7
+ end
8
+ end
9
+ end
10
+ end
@@ -1,6 +1,14 @@
1
1
  class Hash
2
2
  def slice(*keys)
3
- keys.each_with_object(self.class.new) { |k, hash| hash[k] = self[k] if has_key?(k) }
3
+ keys.each_with_object(self.class.new) { |k, hash|
4
+ hash[k] = self[k] if has_key?(k)
5
+ }
6
+ end
7
+
8
+ def extract(*keys)
9
+ self.each_with_object(self.class.new) { |(k, v), hash|
10
+ hash[k] = v unless keys.include?(k)
11
+ }
4
12
  end
5
13
 
6
14
  def symbolize_keys
@@ -0,0 +1,22 @@
1
+ require 'rainbow/ext/string'
2
+
3
+ class String
4
+ def width
5
+ self.no_coloring.each_char.map { |one_letter|
6
+ one_letter.ascii_only? ? 1 : 2
7
+ }.inject(:+) || 0
8
+ end
9
+
10
+ def no_coloring
11
+ self.gsub(/\e\[\d?\d?;?\d\d?m/, '').gsub(/\e\[0m/, '')
12
+ end
13
+
14
+ def constantize
15
+ Object.const_get(self)
16
+ end
17
+
18
+ def ljust_with_multibyte(length, padstr = ' ')
19
+ length > self.width ? "#{self}#{padstr * (length - self.width)}" : self
20
+ end
21
+ alias_method :ljust, :ljust_with_multibyte
22
+ end