github_to_trello 0.1.7 → 1.0.1

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: b464b0a427c1163e851727141f3613ed8a6f8f21
4
- data.tar.gz: e8a7ed8820e4fb3a3126c473911142e39ac11e00
3
+ metadata.gz: cd3e8b6451343b1932c592870f3be9f61380093c
4
+ data.tar.gz: 1ed2be860f48fd7fd8a3d2648b3b95323b7d9770
5
5
  SHA512:
6
- metadata.gz: d1aa2cdb541a725e72a1c7ac65ed3219e2c75c9b079144ad509c9f346908bcef3fc52c3da8066aa984016a63102b24cbdc3e0e8773d03f2e1e6237a70d3071cf
7
- data.tar.gz: dabab364b1bd6b317bdcf687d13d4556876a388fe6daed9f87425a1ec1f257bd28d27d60bd21d5987d40141a94795b72126e7dddacec22697c7adba33b42afe1
6
+ metadata.gz: e782588a8543a84222810c9ab564471e5a5ff2d3f81a6eba262cbafee3e450246c63466f329a2d6c6df321b1705adbe39c87d9c79a677ccc655fed490c055ea2
7
+ data.tar.gz: 54e6581dfe3bef43f741c374a963d6ab3bc87c790b82b364339e43af5de1c91b0aa55772e419eceedcefd149e94ec1b2e9f32016fb6a980d91622bb9c87c76b0
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  ## Overview
2
- Generates trello cards on a specified board for all open issues in specified github repo(s).
2
+ Generates trello cards on a specified board for all open issues in specified github repo(s).
3
3
 
4
4
  ## Usage
5
5
 
@@ -9,12 +9,12 @@ After completing [prerequisites](#prerequisites):
9
9
  ```
10
10
  require 'github_to_trello'
11
11
 
12
- public_key = "your_public_key"
13
- token = "your_token"
14
- board_id "your_trello_board_id"
15
- repo_name = "your_name/your_repo"
16
-
17
- GithubToTrello.new(public_key, token, board_id, repo_name).update
12
+ GithubToTrello.new(
13
+ :public_key => "your_public_key",
14
+ :token => "your_token",
15
+ :board_id => "your_trello_board_id",
16
+ :inbox_name => "your_name/your_repo",
17
+ ).update
18
18
  ```
19
19
 
20
20
  ## Prerequisites
@@ -23,15 +23,14 @@ GithubToTrello.new(public_key, token, board_id, repo_name).update
23
23
  2. A public key and token giving access to that trello account
24
24
  - `PUBLIC_KEY` - Log into trello and visit https://trello.com/app-key
25
25
  - `TOKEN` - Go to
26
- https://trello.com/1/connect?key=...&name=MyApp&response_type=token&scope=read,write
27
- (substituting the public key for ... a unique name for MyApp)
26
+ https://trello.com/1/connect?key=<...>&name=MyApp&response_type=token&scope=read,write
27
+ (substituting your public key for <...> and replacing 'MyApp' with a unique name)
28
28
 
29
29
  ## Features
30
- - Creates a list for specified repo (if a list for that repo is not already present)
31
- - Creates a list for "Claimed" cards that are being worked on, and a
32
- "Done" list for recently completed issues
33
- - Adds or updates cards for all open issues or PRs in that repo
30
+ - Creates a list for specified repo
31
+ - Adds cards for all open issues or PRs in that repo
34
32
 
35
33
  Sites used for reference
36
34
  - http://www.sitepoint.com/customizing-trello-ruby/
37
35
  - https://github.com/jeremytregunna/ruby-trello/blob/master/lib/trello/card.rb
36
+
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ task :default => "spec:integration"
5
+
6
+ desc "Run tests"
7
+ RSpec::Core::RakeTask.new("spec:integration") do |t|
8
+ t.pattern = "spec/*.rb"
9
+ end
@@ -5,12 +5,17 @@ require 'trello'
5
5
 
6
6
 
7
7
  class GithubToTrello
8
- def initialize(public_key, token, board_id, repo_name)
9
- @github_gateway = GithubGateway.new(repo_name)
10
- @trello_gateway = TrelloGateway.new(public_key,
11
- token,
12
- board_id,
13
- repo_name)
8
+ def initialize(options)
9
+ [:public_key, :token, :board_id, :repo_name].each do |required_field|
10
+ _raise_argument_error(required_field) unless options[required_field]
11
+ end
12
+
13
+ @github_gateway = GithubGateway.new(options[:repo_name])
14
+ @trello_gateway = TrelloGateway.new(
15
+ {
16
+ :inbox_name => options[:repo_name],
17
+ }.merge(options)
18
+ )
14
19
  end
15
20
 
16
21
  def update
@@ -18,19 +23,24 @@ class GithubToTrello
18
23
  @trello_gateway.create_or_update_card(issue)
19
24
  end
20
25
  end
26
+
27
+ def _raise_argument_error(field)
28
+ raise ArgumentError, "Argument '#{field}' is required yet missing"
29
+ end
21
30
  end
22
31
 
23
32
  # Example usage with dotenv gem and .env file
24
33
  #
25
34
  # if __FILE__ == $PROGRAM_NAME
26
- # public_key = ENV["PUBLIC_KEY"]
27
- # token = ENV["TOKEN"]
28
- # board_id = ENV["BOARD_ID"]
29
- # repos = ENV["REPOS"].split(",")
30
- #
31
- # repos.each do |repo|
35
+ # ENV["REPOS"].split(",").each do |repo|
32
36
  # puts "Updating repo: #{repo}"
33
- # GithubToTrello.new(public_key, token, board_id, repo).update
37
+ #
38
+ # GithubToTrello.new(
39
+ # :public_key => ENV["PUBLIC_KEY"],
40
+ # :token => ENV["TOKEN"],
41
+ # :board_id => ENV["BOARD_ID"],
42
+ # :repo_name => repo,
43
+ # ).update
34
44
  # end
35
45
  # end
36
46
 
@@ -5,37 +5,48 @@ DAYS_TIL_OLD = 14
5
5
  DAYS_TIL_REALLY_OLD = 28
6
6
 
7
7
  class TrelloGateway
8
- attr_reader :list, :board, :claimed_list, :done_list
8
+ attr_reader :board, :inbox
9
+
10
+ def initialize(options)
11
+ [:public_key, :token, :board_id, :inbox_name].each do |required_field|
12
+ _raise_argument_error(required_field) unless options[required_field]
13
+ end
9
14
 
10
- def initialize(public_key, token, board_id, repo_name)
11
15
  Trello.configure do |c|
12
- c.developer_public_key = public_key
13
- c.member_token = token
16
+ c.developer_public_key = options[:public_key]
17
+ c.member_token = options[:token]
14
18
  end
15
19
 
16
- @board = _board(board_id)
17
- @list = _list(repo_name)
18
- @claimed_list = _list("Claimed")
19
- @done_list = _list("Done")
20
+ @board = _board(options[:board_id])
21
+ @inbox = _list(options[:inbox_name])
20
22
  end
21
23
 
22
24
  def create_or_update_card(issue)
23
- existing_card = _existing_card?(issue)
25
+ existing_card = _existing_card(issue)
24
26
  existing_card.nil? ? _create_card(issue) : existing_card
25
27
  end
26
28
 
27
- def _existing_card?(issue)
28
- unclaimed_card = _list_contains_issue?(@list, issue)
29
- claimed_card = _list_contains_issue?(@claimed_list, issue)
30
- done_card = _list_contains_issue?(@done_list, issue)
29
+ def lists
30
+ board.lists
31
+ end
31
32
 
32
- unclaimed_card || claimed_card || done_card
33
+ def _raise_argument_error(field)
34
+ raise "Argument '#{field}' is required yet missing"
35
+ end
36
+
37
+ def _existing_card(issue)
38
+ lists.each do |list|
39
+ list.cards.each do |card|
40
+ return card if card.name == issue.title
41
+ end
42
+ end
43
+ nil
33
44
  end
34
45
 
35
46
  def _create_card(issue)
36
47
  card = Trello::Card.create(
37
48
  :name => issue.title,
38
- :list_id => @list.id,
49
+ :list_id => inbox.id,
39
50
  :desc => issue.body + "\n" + issue.html_url + "\n" + issue.updated_at.to_s,
40
51
  )
41
52
  _add_checklist_to(card)
@@ -43,25 +54,19 @@ class TrelloGateway
43
54
  end
44
55
 
45
56
  def _add_checklist_to(card)
46
- checklist = Trello::Checklist.create(:name => "Todo", :board_id => @board.id)
57
+ checklist = Trello::Checklist.create(:name => "Todo", :board_id => board.id)
47
58
  checklist.add_item("Initial Response")
48
59
  card.add_checklist(checklist)
49
60
  end
50
61
 
51
- def _list_contains_issue?(list, issue)
52
- list.cards.detect do |card|
53
- card.name == issue.title
54
- end
55
- end
56
-
57
62
  def _board(id)
58
63
  Trello::Board.find(id)
59
64
  end
60
65
 
61
66
  def _list(name)
62
- found_list = @board.lists.detect do |list|
67
+ found_list = board.lists.detect do |list|
63
68
  list.name =~ /#{name}/
64
69
  end
65
- found_list || Trello::List.create(:name => name, :board_id => @board.id)
70
+ found_list || Trello::List.create(:name => name, :board_id => board.id)
66
71
  end
67
72
  end
@@ -1,3 +1,3 @@
1
1
  module GithubToTrello
2
- VERSION = "0.1.7"
2
+ VERSION = "1.0.1"
3
3
  end
@@ -0,0 +1,72 @@
1
+ require 'rspec'
2
+ require_relative '../lib/github_to_trello'
3
+
4
+ describe GithubToTrello do
5
+ before(:all) do
6
+ @options = {
7
+ :public_key => "abcdef",
8
+ :token => "ghilmnopqrstuvwxyz",
9
+ :board_id => "123456",
10
+ :repo_name => "chrissiedeist/django_blog",
11
+ :inbox_name => "django_blog",
12
+ }
13
+ end
14
+
15
+ describe "new" do
16
+ it "sets up github and trello gateways" do
17
+ expect(GithubGateway).to receive(:new).with(@options[:repo_name])
18
+ expect(TrelloGateway).to receive(:new).with(@options)
19
+
20
+ gateway = GithubToTrello.new(@options)
21
+ end
22
+
23
+ it "defaults to repository name when inbox isn't provided" do
24
+ allow(GithubGateway).to receive(:new).with(@options[:repo_name])
25
+
26
+ @options.delete(:inbox_name)
27
+ expected_options = {
28
+ :inbox_name => @options[:repo_name],
29
+ }.merge(@options)
30
+
31
+ expect(TrelloGateway).to receive(:new).with(expected_options)
32
+
33
+ gateway = GithubToTrello.new(@options)
34
+ end
35
+
36
+ it "raises an error if any mandatory fields aren't passed" do
37
+ required_fields = [:public_key, :token, :board_id, :repo_name]
38
+
39
+ (1..3).each do |field_count|
40
+ required_fields.combination(field_count).to_a.each do |field_combo|
41
+ bad_options = {}
42
+ field_combo.each do |field|
43
+ bad_options[field] = @options[field]
44
+ end
45
+
46
+ expect{ GithubToTrello.new(bad_options)}.to raise_error(ArgumentError)
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ describe "update" do
53
+ it "iterates over issues" do
54
+ issues = ["first", "second", "third"]
55
+ fake_github_gateway = fake_trello_gateway = double()
56
+
57
+
58
+ allow(GithubGateway).to receive(:new).and_return(fake_github_gateway)
59
+ allow(TrelloGateway).to receive(:new).and_return(fake_trello_gateway)
60
+
61
+ gateway = GithubToTrello.new(@options)
62
+
63
+ expect(fake_github_gateway).to receive(:issues).and_return(issues)
64
+
65
+ issues.each do |issue|
66
+ expect(fake_trello_gateway).to receive(:create_or_update_card).with(issue)
67
+ end
68
+
69
+ gateway.update
70
+ end
71
+ end
72
+ end
@@ -3,12 +3,13 @@ require_relative '../lib/github_to_trello/trello_gateway'
3
3
 
4
4
  describe TrelloGateway do
5
5
  before(:each) do
6
- public_key = "56acdaa7404ebcc8bbaffab18428d4d2"
7
- token = "08f4481d00aba0091592ad9e0ce7e025ac9e238ead31852fe4a75270fbd562e9"
8
- board_id = "5jGWvKui"
9
- repo = "django_blog"
6
+ @gateway = TrelloGateway.new(
7
+ :public_key => "56acdaa7404ebcc8bbaffab18428d4d2",
8
+ :token => "08f4481d00aba0091592ad9e0ce7e025ac9e238ead31852fe4a75270fbd562e9",
9
+ :board_id => "5jGWvKui",
10
+ :inbox_name => "django_blog",
11
+ )
10
12
 
11
- @gateway = TrelloGateway.new(public_key, token, board_id, repo)
12
13
  @issue = double(:issue,
13
14
  :title => "Test",
14
15
  :id => "91374795",
@@ -21,23 +22,14 @@ describe TrelloGateway do
21
22
  after(:each) do
22
23
  @gateway.board.lists.each do |list|
23
24
  list.cards.each(&:delete)
25
+ list.close!
24
26
  end
25
27
  end
26
28
 
27
29
  describe "initialization" do
28
- it "has a list named for the repo" do
29
- expect(@gateway.list).to be_a Trello::List
30
- expect(@gateway.list.name).to eq("django_blog")
31
- end
32
-
33
- it "has a list called 'Claimed'" do
34
- expect(@gateway.list).to be_a Trello::List
35
- expect(@gateway.claimed_list.name).to eq("Claimed")
36
- end
37
-
38
- it "has a list called 'Done'" do
39
- expect(@gateway.list).to be_a Trello::List
40
- expect(@gateway.done_list.name).to eq("Done")
30
+ it "creates the inbox list" do
31
+ expect(@gateway.inbox).to be_a Trello::List
32
+ expect(@gateway.inbox.name).to eq("django_blog")
41
33
  end
42
34
 
43
35
  it "has a board" do
@@ -45,29 +37,21 @@ describe TrelloGateway do
45
37
  end
46
38
  end
47
39
 
48
- describe "_existing_card?" do
49
- it "returns the existing trello card if the card exists in it's repos list" do
40
+ describe "_existing_card" do
41
+ it "returns the existing trello card if the card exists in the inbox folder" do
50
42
  card = @gateway.create_or_update_card(@issue)
51
43
 
52
- existing_card = @gateway._existing_card?(@issue)
44
+ existing_card = @gateway._existing_card(@issue)
53
45
  expect(existing_card).to be_a(Trello::Card)
54
46
  expect(existing_card.name).to eq("Test")
55
47
  end
56
48
 
57
- it "returns the existing trello card if the card exists in the 'Claimed' list" do
49
+ it "returns the existing trello card if the card exists in list other than the inbox" do
50
+ other_list = Trello::List.create(:name => "some other list", :board_id => @gateway.board.id)
58
51
  card = @gateway.create_or_update_card(@issue)
59
- card.move_to_list(@gateway.claimed_list.id)
52
+ card.move_to_list(other_list.id)
60
53
 
61
- existing_card = @gateway._existing_card?(@issue)
62
- expect(existing_card).to be_a(Trello::Card)
63
- expect(existing_card.name).to eq("Test")
64
- end
65
-
66
- it "returns the existing trello card if the card exists in the 'Done' list" do
67
- card = @gateway.create_or_update_card(@issue)
68
- card.move_to_list(@gateway.done_list.id)
69
-
70
- existing_card = @gateway._existing_card?(@issue)
54
+ existing_card = @gateway._existing_card(@issue)
71
55
  expect(existing_card).to be_a(Trello::Card)
72
56
  expect(existing_card.name).to eq("Test")
73
57
  end
@@ -83,11 +67,23 @@ describe TrelloGateway do
83
67
 
84
68
  @gateway.create_or_update_card(not_the_issue)
85
69
 
86
- existing_card = @gateway._existing_card?(@issue)
70
+ existing_card = @gateway._existing_card(@issue)
87
71
  expect(existing_card).to be_nil
88
72
  end
89
73
  end
90
74
 
75
+ describe "lists" do
76
+ it "presents all lists on the board" do
77
+ expect(@gateway.lists.count).to eq(1)
78
+ expect(@gateway.lists.first).to be_a Trello::List
79
+ expect(@gateway.lists.first.name).to eq("django_blog")
80
+ 5.times do |number|
81
+ Trello::List.create(:name => "list_number_#{number}", :board_id => @gateway.board.id)
82
+ end
83
+ expect(@gateway.lists.count).to eq(6)
84
+ end
85
+ end
86
+
91
87
  describe "create_or_update_card" do
92
88
  it "creates a new card on the appropriate list if it does not exist" do
93
89
  card = @gateway.create_or_update_card(@issue)
@@ -113,48 +109,22 @@ describe TrelloGateway do
113
109
  expect(card.name).to eq("Test")
114
110
  end
115
111
 
116
- it "does not add a duplicate card if card exists in a list called 'claimed'" do
117
- issue = double(:issue,
118
- :title => "Test",
119
- :id => "91374795",
120
- :updated_at => Date.today.to_s,
121
- :body => "This is a test",
122
- :html_url => "https://github.com/chrissiedeist/django_blog/issues/1",
123
- )
124
-
125
- @gateway.claimed_list.cards.length.should == 0
126
-
127
- card = @gateway.create_or_update_card(issue)
128
- card.list.name.should == "django_blog"
129
-
130
- card.move_to_list(@gateway.claimed_list.id)
131
- card = @gateway.create_or_update_card(issue)
132
-
133
- card.list.name.should == "Claimed"
134
- @gateway.claimed_list.cards.length.should == 1
135
- @gateway.list.cards.length.should == 0
136
- end
137
-
138
- it "does not add a duplicate card if card exists in a list called 'done'" do
139
- issue = double(:issue,
140
- :title => "Test",
141
- :id => "91374795",
142
- :updated_at => Date.today.to_s,
143
- :body => "This is a test",
144
- :html_url => "https://github.com/chrissiedeist/django_blog/issues/1",
145
- )
146
-
147
- @gateway.done_list.cards.length.should == 0
112
+ it "does not add a duplicate card if card exists in a list" do
113
+ card = @gateway.create_or_update_card(@issue)
114
+ expect(card.list.name).to eq("django_blog")
115
+ expect(@gateway.inbox.cards.length).to eq(1)
148
116
 
149
- card = @gateway.create_or_update_card(issue)
150
- card.list.name.should == "django_blog"
117
+ other_list = Trello::List.create(:name => "some other list", :board_id => @gateway.board.id)
118
+ expect(other_list.cards.length).to eq(0)
151
119
 
152
- card.move_to_list(@gateway.done_list.id)
153
- card = @gateway.create_or_update_card(issue)
120
+ card.move_to_list(other_list.id)
121
+ expect(other_list.cards.length).to eq(1)
122
+ expect(@gateway.inbox.cards.length).to eq(0)
154
123
 
155
- card.list.name.should == "Done"
156
- @gateway.done_list.cards.length.should == 1
157
- @gateway.list.cards.length.should == 0
124
+ card = @gateway.create_or_update_card(@issue)
125
+ expect(card.list.name).to eq("some other list")
126
+ expect(other_list.cards.length).to eq(1)
127
+ expect(@gateway.inbox.cards.length).to eq(0)
158
128
  end
159
129
  end
160
130
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_to_trello
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.7
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrissie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-27 00:00:00.000000000 Z
11
+ date: 2015-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: octokit
@@ -98,6 +98,7 @@ files:
98
98
  - lib/github_to_trello/trello_gateway.rb
99
99
  - lib/github_to_trello/version.rb
100
100
  - spec/github_gateway_spec.rb
101
+ - spec/github_to_trello_spec.rb
101
102
  - spec/trello_gateway_spec.rb
102
103
  homepage: https://github.com/chrissiedeist/github_to_trello
103
104
  licenses:
@@ -126,4 +127,5 @@ summary: Pulls github issues from specified repos and automatically creates/popu
126
127
  trello lists with the repo names on a specified board.
127
128
  test_files:
128
129
  - spec/github_gateway_spec.rb
130
+ - spec/github_to_trello_spec.rb
129
131
  - spec/trello_gateway_spec.rb