github_to_trello 0.1.0 → 0.1.7

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: 9e528de9a7db2c2af22f6acf465537a6544537bd
4
- data.tar.gz: 021d708220d4c174e51d6990d8afd0120dd6016e
3
+ metadata.gz: b464b0a427c1163e851727141f3613ed8a6f8f21
4
+ data.tar.gz: e8a7ed8820e4fb3a3126c473911142e39ac11e00
5
5
  SHA512:
6
- metadata.gz: 5c5bad6b82be125718570e03d48ca07816cbacbc0d454e37ab3cb3345f52e7ecef597083b37a1f682543f2c4203e091a580c54d362ba21ce701d6468abc4b0ae
7
- data.tar.gz: bcae15f004db55b3a68d7ce4e33216e0e28466b3cf8d83d895928affbb7c506a00fe04037e72dccebf18ed9ceef720cb02191433a728a835da200fac30d893a7
6
+ metadata.gz: d1aa2cdb541a725e72a1c7ac65ed3219e2c75c9b079144ad509c9f346908bcef3fc52c3da8066aa984016a63102b24cbdc3e0e8773d03f2e1e6237a70d3071cf
7
+ data.tar.gz: dabab364b1bd6b317bdcf687d13d4556876a388fe6daed9f87425a1ec1f257bd28d27d60bd21d5987d40141a94795b72126e7dddacec22697c7adba33b42afe1
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  gem 'ruby-trello'
4
+ gem 'rspec', '~> 3.3.0'
4
5
  gem 'octokit'
5
- gem 'dotenv'
data/README.md CHANGED
@@ -1,37 +1,9 @@
1
1
  ## Overview
2
- Creates/updates trello cards for all open issues in specified github repo.
3
-
4
- Running this script/using this gem:
5
- - Creates a list for specified repo (if a list for that repo is not already present)
6
- - Adds or updates cards for all open issues or PRs in that repo
7
- - Adds or updates color labels to cards based on date last updated
8
-
9
- ## Prerequisites
10
-
11
- 1. A trello account with access to the board you are populating with github issues.
12
- 2. A public key and token giving access to that trello account
13
- - `PUBLIC_KEY` - Log into trello and visit https://trello.com/app-key
14
- - `TOKEN` - Go to
15
- https://trello.com/1/connect?key=...&name=MyApp&response_type=token&scope=read,write
16
- (substituting the public key for ... a unique name for MyApp)
2
+ Generates trello cards on a specified board for all open issues in specified github repo(s).
17
3
 
4
+ ## Usage
18
5
 
19
- ## USAGE 1: (running as a standalone script)
20
-
21
- 1. Create a .env file with with the following variables
22
- defined:
23
- - `BOARD_ID` - The ID of the trello board to add the cards to
24
- - `REPOS` - The name(s) of the github repos to pull issues from
25
- (comma separated: `REPOS=your_name/your_repo,your_name/your_other_repo`)
26
- - `PUBLIC_KEY` - Log into trello and visit https://trello.com/app-key
27
- - `TOKEN` - Go to
28
- https://trello.com/1/connect?key=...&name=MyApp&response_type=token&scope=read,write
29
- (substituting the public key for ... a unique name for MyApp)
30
-
31
- 2. Run `ruby github_to_trello.rb`
32
-
33
- ## USAGE 2: (gem)
34
-
6
+ After completing [prerequisites](#prerequisites):
35
7
  `gem install github_to_trello`
36
8
 
37
9
  ```
@@ -45,6 +17,20 @@ repo_name = "your_name/your_repo"
45
17
  GithubToTrello.new(public_key, token, board_id, repo_name).update
46
18
  ```
47
19
 
20
+ ## Prerequisites
21
+
22
+ 1. A trello account with access to the board you are populating with github issues.
23
+ 2. A public key and token giving access to that trello account
24
+ - `PUBLIC_KEY` - Log into trello and visit https://trello.com/app-key
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)
28
+
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
48
34
 
49
35
  Sites used for reference
50
36
  - http://www.sitepoint.com/customizing-trello-ruby/
@@ -14,10 +14,14 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
19
+ spec.required_ruby_version = '>= 1.9.3'
20
+
21
+ spec.add_dependency "octokit", "~> 4.0.1"
22
+ spec.add_dependency "ruby-trello", "~> 1.2.1"
20
23
 
21
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rspec", "~> 3.3.0"
22
26
  spec.add_development_dependency "rake"
23
27
  end
@@ -2,9 +2,7 @@ require_relative './github_to_trello/github_gateway'
2
2
  require_relative './github_to_trello/trello_gateway'
3
3
  require 'octokit'
4
4
  require 'trello'
5
- require 'dotenv'
6
5
 
7
- Dotenv.load
8
6
 
9
7
  class GithubToTrello
10
8
  def initialize(public_key, token, board_id, repo_name)
@@ -22,15 +20,17 @@ class GithubToTrello
22
20
  end
23
21
  end
24
22
 
25
- 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|
32
- puts "Updating repo: #{repo}"
33
- GithubToTrello.new(public_key, token, board_id, repo).update
34
- end
35
- end
23
+ # Example usage with dotenv gem and .env file
24
+ #
25
+ # 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|
32
+ # puts "Updating repo: #{repo}"
33
+ # GithubToTrello.new(public_key, token, board_id, repo).update
34
+ # end
35
+ # end
36
36
 
@@ -5,57 +5,63 @@ DAYS_TIL_OLD = 14
5
5
  DAYS_TIL_REALLY_OLD = 28
6
6
 
7
7
  class TrelloGateway
8
- def initialize(public_key, token, board_id, repo)
8
+ attr_reader :list, :board, :claimed_list, :done_list
9
+
10
+ def initialize(public_key, token, board_id, repo_name)
9
11
  Trello.configure do |c|
10
12
  c.developer_public_key = public_key
11
13
  c.member_token = token
12
14
  end
13
15
 
14
16
  @board = _board(board_id)
15
- @repo = repo
16
- @list = _list
17
+ @list = _list(repo_name)
18
+ @claimed_list = _list("Claimed")
19
+ @done_list = _list("Done")
17
20
  end
18
21
 
19
22
  def create_or_update_card(issue)
20
23
  existing_card = _existing_card?(issue)
21
- card = existing_card.class == (Trello::Card) ? existing_card : _create_card(issue)
22
- _update(issue, card)
23
- end
24
-
25
- def _update(issue, card)
26
- if issue.updated_at < (Time.now - DAYS_TIL_REALLY_OLD * SECONDS_PER_DAY)
27
- card.card_labels = [:red]
28
- elsif issue.updated_at < (Time.now - DAYS_TIL_OLD * SECONDS_PER_DAY)
29
- card.card_labels = [:yellow]
30
- else
31
- card.card_labels = []
32
- end
33
- card.save
34
- card
24
+ existing_card.nil? ? _create_card(issue) : existing_card
35
25
  end
36
26
 
37
27
  def _existing_card?(issue)
38
- @list.cards.detect do |card|
39
- card.name == issue.title
40
- end
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)
31
+
32
+ unclaimed_card || claimed_card || done_card
41
33
  end
42
34
 
43
35
  def _create_card(issue)
44
- Trello::Card.create(
36
+ card = Trello::Card.create(
45
37
  :name => issue.title,
46
38
  :list_id => @list.id,
47
- :desc => issue.body + "\n" + issue.html_url + "\n" + issue.updated_at.to_s
39
+ :desc => issue.body + "\n" + issue.html_url + "\n" + issue.updated_at.to_s,
48
40
  )
41
+ _add_checklist_to(card)
42
+ card
43
+ end
44
+
45
+ def _add_checklist_to(card)
46
+ checklist = Trello::Checklist.create(:name => "Todo", :board_id => @board.id)
47
+ checklist.add_item("Initial Response")
48
+ card.add_checklist(checklist)
49
+ end
50
+
51
+ def _list_contains_issue?(list, issue)
52
+ list.cards.detect do |card|
53
+ card.name == issue.title
54
+ end
49
55
  end
50
56
 
51
57
  def _board(id)
52
58
  Trello::Board.find(id)
53
59
  end
54
60
 
55
- def _list
56
- list = @board.lists.detect do |list|
57
- list.name =~ /#{@repo}/
61
+ def _list(name)
62
+ found_list = @board.lists.detect do |list|
63
+ list.name =~ /#{name}/
58
64
  end
59
- list = list || Trello::List.create(:name => @repo, :board_id => @board.id)
65
+ found_list || Trello::List.create(:name => name, :board_id => @board.id)
60
66
  end
61
67
  end
@@ -1,3 +1,3 @@
1
1
  module GithubToTrello
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.7"
3
3
  end
@@ -1,5 +1,5 @@
1
1
  require 'rspec'
2
- require 'github_gateway'
2
+ require_relative '../lib/github_to_trello/github_gateway'
3
3
 
4
4
  describe GithubGateway do
5
5
  before(:all) do
@@ -1,11 +1,10 @@
1
- require 'dotenv'
2
1
  require 'rspec'
3
- require 'trello_gateway'
2
+ require_relative '../lib/github_to_trello/trello_gateway'
4
3
 
5
4
  describe TrelloGateway do
6
5
  before(:each) do
7
6
  public_key = "56acdaa7404ebcc8bbaffab18428d4d2"
8
- token = "748c2116942c251bf6ed8000c13196293443ddcb407422ccacd92d0001b831da"
7
+ token = "08f4481d00aba0091592ad9e0ce7e025ac9e238ead31852fe4a75270fbd562e9"
9
8
  board_id = "5jGWvKui"
10
9
  repo = "django_blog"
11
10
 
@@ -13,41 +12,149 @@ describe TrelloGateway do
13
12
  @issue = double(:issue,
14
13
  :title => "Test",
15
14
  :id => "91374795",
16
- :updated_at => "2015-06-26T22:08:36Z",
15
+ :updated_at => Date.today.to_s,
17
16
  :body => "This is a test",
18
17
  :html_url => "https://github.com/chrissiedeist/django_blog/issues/1",
19
18
  )
20
19
  end
21
20
 
21
+ after(:each) do
22
+ @gateway.board.lists.each do |list|
23
+ list.cards.each(&:delete)
24
+ end
25
+ end
26
+
27
+ 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")
41
+ end
42
+
43
+ it "has a board" do
44
+ expect(@gateway.board).to be_a Trello::Board
45
+ end
46
+ end
47
+
48
+ describe "_existing_card?" do
49
+ it "returns the existing trello card if the card exists in it's repos list" do
50
+ card = @gateway.create_or_update_card(@issue)
51
+
52
+ existing_card = @gateway._existing_card?(@issue)
53
+ expect(existing_card).to be_a(Trello::Card)
54
+ expect(existing_card.name).to eq("Test")
55
+ end
56
+
57
+ it "returns the existing trello card if the card exists in the 'Claimed' list" do
58
+ card = @gateway.create_or_update_card(@issue)
59
+ card.move_to_list(@gateway.claimed_list.id)
60
+
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)
71
+ expect(existing_card).to be_a(Trello::Card)
72
+ expect(existing_card.name).to eq("Test")
73
+ end
74
+
75
+ it "returns nil if no card has been created for the issue" do
76
+ not_the_issue = double(:issue,
77
+ :title => "Test 2",
78
+ :id => "91374796",
79
+ :updated_at => Date.today.to_s,
80
+ :body => "This is a test",
81
+ :html_url => "https://github.com/chrissiedeist/django_blog/issues/2",
82
+ )
83
+
84
+ @gateway.create_or_update_card(not_the_issue)
85
+
86
+ existing_card = @gateway._existing_card?(@issue)
87
+ expect(existing_card).to be_nil
88
+ end
89
+ end
90
+
22
91
  describe "create_or_update_card" do
23
92
  it "creates a new card on the appropriate list if it does not exist" do
24
93
  card = @gateway.create_or_update_card(@issue)
25
94
  expect(card.class).to be(Trello::Card)
26
95
  expect(card.name).to eq("Test")
27
- expect(card.list.name).to eq("chrissiedeist/django_blog")
96
+ expect(card.list.name).to eq("django_blog")
97
+ end
28
98
 
99
+ it "includes a checklist with item for initial response when creating cards" do
100
+ card = @gateway.create_or_update_card(@issue)
101
+ expect(card.checklists.length).to eq 1
102
+
103
+ checklist = card.checklists.first
104
+ expect(checklist.items.length).to eq 1
105
+ expect(checklist.items.first.name).to eq "Initial Response"
29
106
  end
30
107
 
31
- it "does not add a duplicate card if card exits" do
108
+ it "does not add a duplicate card if card exits in list already" do
32
109
  card = @gateway.create_or_update_card(@issue)
33
110
  card = @gateway.create_or_update_card(@issue)
34
111
 
35
112
  expect(card.list.cards.length).to eq(1)
113
+ expect(card.name).to eq("Test")
36
114
  end
37
115
 
38
- it "adds a red label if card is more than 28 days old" do
39
- card = @gateway.create_or_update_card(@issue)
40
- expect(card.card_labels).to eq([])
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)
41
132
 
42
- updated_issue = double(:issue,
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,
43
140
  :title => "Test",
44
141
  :id => "91374795",
45
- :updated_at => "2015-01-27T22:08:36Z",
142
+ :updated_at => Date.today.to_s,
46
143
  :body => "This is a test",
47
144
  :html_url => "https://github.com/chrissiedeist/django_blog/issues/1",
48
145
  )
49
- card = @gateway.create_or_update_card(updated_issue)
50
- expect(card.card_labels).to eq([:red])
146
+
147
+ @gateway.done_list.cards.length.should == 0
148
+
149
+ card = @gateway.create_or_update_card(issue)
150
+ card.list.name.should == "django_blog"
151
+
152
+ card.move_to_list(@gateway.done_list.id)
153
+ card = @gateway.create_or_update_card(issue)
154
+
155
+ card.list.name.should == "Done"
156
+ @gateway.done_list.cards.length.should == 1
157
+ @gateway.list.cards.length.should == 0
51
158
  end
52
159
  end
53
160
  end
metadata CHANGED
@@ -1,41 +1,83 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_to_trello
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - chrissie
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-21 00:00:00.000000000 Z
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
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: 4.0.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-trello
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.1
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
16
44
  requirements:
17
- - - ~>
45
+ - - "~>"
18
46
  - !ruby/object:Gem::Version
19
47
  version: '1.3'
20
48
  type: :development
21
49
  prerelease: false
22
50
  version_requirements: !ruby/object:Gem::Requirement
23
51
  requirements:
24
- - - ~>
52
+ - - "~>"
25
53
  - !ruby/object:Gem::Version
26
54
  version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.3.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.3.0
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: rake
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
- - - '>='
73
+ - - ">="
32
74
  - !ruby/object:Gem::Version
33
75
  version: '0'
34
76
  type: :development
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
- - - '>='
80
+ - - ">="
39
81
  - !ruby/object:Gem::Version
40
82
  version: '0'
41
83
  description: A gem for converting github issues into trello cards
@@ -45,14 +87,12 @@ executables: []
45
87
  extensions: []
46
88
  extra_rdoc_files: []
47
89
  files:
48
- - .gitignore
90
+ - ".gitignore"
49
91
  - Gemfile
50
92
  - LICENSE.txt
51
93
  - README.md
52
94
  - Rakefile
53
- - github_to_trello-0.0.1.gem
54
95
  - github_to_trello.gemspec
55
- - github_to_trello.sh
56
96
  - lib/github_to_trello.rb
57
97
  - lib/github_to_trello/github_gateway.rb
58
98
  - lib/github_to_trello/trello_gateway.rb
@@ -69,17 +109,17 @@ require_paths:
69
109
  - lib
70
110
  required_ruby_version: !ruby/object:Gem::Requirement
71
111
  requirements:
72
- - - '>='
112
+ - - ">="
73
113
  - !ruby/object:Gem::Version
74
- version: '0'
114
+ version: 1.9.3
75
115
  required_rubygems_version: !ruby/object:Gem::Requirement
76
116
  requirements:
77
- - - '>='
117
+ - - ">="
78
118
  - !ruby/object:Gem::Version
79
119
  version: '0'
80
120
  requirements: []
81
121
  rubyforge_project:
82
- rubygems_version: 2.0.14
122
+ rubygems_version: 2.4.6
83
123
  signing_key:
84
124
  specification_version: 4
85
125
  summary: Pulls github issues from specified repos and automatically creates/populates
Binary file
data/github_to_trello.sh DELETED
@@ -1,17 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'github_to_trello'
3
-
4
- Dotenv.load
5
-
6
- if __FILE__ == $PROGRAM_NAME
7
- public_key = ENV["PUBLIC_KEY"]
8
- token = ENV["TOKEN"]
9
- board_id = ENV["BOARD_ID"]
10
- repos = ENV["REPOS"].split(",")
11
-
12
- repos.each do |repo|
13
- puts "Updating repo: #{repo}"
14
- GithubToTrello.new(public_key, token, board_id, repo).update
15
- end
16
- end
17
-