git_trello_post_commit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +85 -0
- data/Rakefile +1 -0
- data/git_trello_post_commit.gemspec +26 -0
- data/lib/git_trello_post_commit/trello-http.rb +62 -0
- data/lib/git_trello_post_commit/version.rb +3 -0
- data/lib/git_trello_post_commit.rb +69 -0
- metadata +112 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 650ea741b6a6a41902715be311f92a0e01bdd365
|
4
|
+
data.tar.gz: 29659334553f6b7c9e92a241212385595215b7c1
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d12535d71a22eb1fb3554852f4200cd85cb99447f36daa53754cecf1f2a71942604b18af7d909b4ad8826fdeaf45ec7a83f954d74e10f8773e7b80da239ec248
|
7
|
+
data.tar.gz: c2f80d764567d0f398833e460949d36f6cbcabc48f6c0cf1e81518412605aea64ebf9f5197e9b0423bf1ef7f15add9f7227a235a4a0822500d2922da59278934
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 jmchambers
|
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,85 @@
|
|
1
|
+
# git_trello_post_commit
|
2
|
+
|
3
|
+
This gem can be used in a post-commit hook in any Git repository to comment on and move Trello cards in a specified board. The actions performed by the hook depend on the Git commit message. For example, if a message contains 'Card #20', the hook will add the rest of the commit message as a comment on card #20.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'git_trello_post_commit'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install git_trello_post_commit
|
18
|
+
|
19
|
+
## Setup
|
20
|
+
|
21
|
+
Add a file like this to your repo:
|
22
|
+
|
23
|
+
**my_repo/.git/hooks/post-commit**
|
24
|
+
|
25
|
+
#!/usr/bin/env ruby
|
26
|
+
require 'git_trello_post_commit'
|
27
|
+
GitTrelloPostCommit::Hook.new(
|
28
|
+
:api_key => 'API_KEY',
|
29
|
+
:oauth_token => 'OAUTH_TOKEN',
|
30
|
+
:list_id_in_progress => 'LIST_ID_IN_PROGRESS',
|
31
|
+
:list_id_done => 'LIST_ID_IN_DONE',
|
32
|
+
:board_id => 'TRELLO_BOARD_ID',
|
33
|
+
:commit_url_prefix => 'https://github.com/my_github_username/my_repo/commits/'
|
34
|
+
).run
|
35
|
+
|
36
|
+
|
37
|
+
Filling in the details using the following approach...
|
38
|
+
|
39
|
+
### api_key
|
40
|
+
|
41
|
+
Get your developer key from: https://trello.com/1/appKey/generate
|
42
|
+
|
43
|
+
### oauth_token
|
44
|
+
|
45
|
+
You need to authorize the app with `API_KEY` to access each board separatelly. To do that:
|
46
|
+
|
47
|
+
https://trello.com/1/authorize?response_type=token&name=`BOARD_NAME_AS_SHOWN_IN_URL`&scope=read,write&expiration=never&key=`API_KEY`
|
48
|
+
|
49
|
+
### list_id_in_progress & list_id_done
|
50
|
+
|
51
|
+
Open a card from your "in progress" and "completed" lists (or whatever you've called them), click the 'More' link in the bottom-right-hand corner, select 'Export JSON' and find the `idList` value.
|
52
|
+
|
53
|
+
### board_id
|
54
|
+
|
55
|
+
While examining the JSON from the previous step, you can also grab the value of `idBoard`.
|
56
|
+
|
57
|
+
### commit_url_prefix
|
58
|
+
|
59
|
+
If you have a web view of your Git repo (such as Github), you can enter the URL which, when sufixed with the commit SHA will show the commit in question. The hook will add a link to the commit in the comment it adds to the card.
|
60
|
+
|
61
|
+
If you ommit the parameter, a link won't be added.
|
62
|
+
|
63
|
+
## Usage
|
64
|
+
|
65
|
+
The gem uses the following regex to detect a reference to a card:
|
66
|
+
|
67
|
+
/((case|card|close|fix)e?s? \D?([0-9]+))/i
|
68
|
+
|
69
|
+
So an example commit message might be:
|
70
|
+
|
71
|
+
Added that awesome feature closes #42
|
72
|
+
|
73
|
+
For the 'case' and 'card' keywords, the card is moved to the list with id `LIST_ID_IN_PROGRESS`, while for keywords 'close' and 'fix', the card is moved to the list with id `LIST_ID_IN_DONE` .
|
74
|
+
|
75
|
+
## Contributing
|
76
|
+
|
77
|
+
1. Fork it
|
78
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
79
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
81
|
+
5. Create new Pull Request
|
82
|
+
|
83
|
+
## Acknowledgments
|
84
|
+
|
85
|
+
This gem is a quick-and-dirty mod of https://github.com/zmilojko/git-trello, so credit to [@zmilojko](https://github.com/zmilojko).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -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 'git_trello_post_commit/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "git_trello_post_commit"
|
8
|
+
spec.version = GitTrelloPostCommit::VERSION
|
9
|
+
spec.authors = ["jmchambers"]
|
10
|
+
spec.email = ["j.chambers@gmx.net"]
|
11
|
+
spec.description = %q{This gem can be used in a post-commit hook in any Git repository to comment on and move Trello cards in a specified board. What will be done is based on a Git commit message:for example, if a message contains 'Card #20', post-commit will add the rest of comment message as a comment on card #20.}
|
12
|
+
spec.summary = %q{Update Trello cards with git commit messages.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
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_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'json'
|
25
|
+
spec.add_runtime_dependency "git", "~> 1.2"
|
26
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
#Copyright (c) 2011 Zachary Anker
|
2
|
+
#Minor modifications by Zeljko Milojkovic
|
3
|
+
|
4
|
+
require "cgi"
|
5
|
+
require "net/https"
|
6
|
+
|
7
|
+
module GitTrelloPostCommit
|
8
|
+
module Trello
|
9
|
+
class HTTP
|
10
|
+
def initialize(token, api_key)
|
11
|
+
@token, @api_key = token, api_key
|
12
|
+
@uri = URI("https://api.trello.com")
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_card(board_id, card_id)
|
16
|
+
http_request(:get, "/1/boards/#{board_id}/cards/#{card_id}", :params => {:fields => "idList,closed"})
|
17
|
+
end
|
18
|
+
|
19
|
+
def update_card(card_id, params)
|
20
|
+
http_request(:put, "/1/cards/#{card_id}", :params => params)
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_comment(card_id, comment)
|
24
|
+
http_request(:post, "/1/cards/#{card_id}/actions/comments", :body => "text=#{CGI::escape(comment)}")
|
25
|
+
end
|
26
|
+
|
27
|
+
def get_cards(list_id)
|
28
|
+
http_request(:get, "/1/lists/#{list_id}/cards", :params => {:fields => "idList"})
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def http_request(method, request_path, args={})
|
34
|
+
request_path << "?"
|
35
|
+
args[:params] ||= {}
|
36
|
+
args[:params][:key] = @api_key
|
37
|
+
args[:params][:token] = @token
|
38
|
+
args[:params].each {|k, v| request_path << "#{k}=#{CGI::escape(v.to_s)}&"}
|
39
|
+
|
40
|
+
http = Net::HTTP.new(@uri.host, @uri.port)
|
41
|
+
http.use_ssl = true
|
42
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
43
|
+
|
44
|
+
http.start
|
45
|
+
|
46
|
+
if method == :get
|
47
|
+
response = http.request_get(request_path)
|
48
|
+
elsif method == :post
|
49
|
+
response = http.request_post(request_path, args.delete(:body))
|
50
|
+
elsif method == :put
|
51
|
+
response = http.request_put(request_path, args.delete(:body))
|
52
|
+
end
|
53
|
+
|
54
|
+
unless response.code == "200" or response.code == "201"
|
55
|
+
raise Net::HTTPError.new("#{response.body == "" ? response.message : response.body.strip} (#{response.code})", response)
|
56
|
+
end
|
57
|
+
|
58
|
+
response.body
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require "git_trello_post_commit/version"
|
2
|
+
require "git_trello_post_commit/trello-http"
|
3
|
+
require "json"
|
4
|
+
require "git"
|
5
|
+
|
6
|
+
module GitTrelloPostCommit
|
7
|
+
|
8
|
+
class Hook
|
9
|
+
|
10
|
+
def initialize(config)
|
11
|
+
@api_key = config[:api_key]
|
12
|
+
@oauth_token = config[:oauth_token]
|
13
|
+
@repodir = config[:repodir] || Dir.pwd
|
14
|
+
@board_id = config[:board_id]
|
15
|
+
@list_id_in_progress = config[:list_id_in_progress]
|
16
|
+
@list_id_done = config[:list_id_done]
|
17
|
+
@commit_url_prefix = config[:commit_url_prefix]
|
18
|
+
|
19
|
+
@http = GitTrelloPostCommit::Trello::HTTP.new(@oauth_token, @api_key)
|
20
|
+
@repo = Git.open(@repodir)
|
21
|
+
end
|
22
|
+
|
23
|
+
def run
|
24
|
+
|
25
|
+
#get the commit and it's sha from HEAD
|
26
|
+
commit = @repo.gcommit('HEAD')
|
27
|
+
new_sha = commit.sha
|
28
|
+
|
29
|
+
# Figure out the card short id
|
30
|
+
match = commit.message.match(/((case|card|close|fix)e?s? \D?([0-9]+))/i)
|
31
|
+
return unless match and match[3].to_i > 0
|
32
|
+
|
33
|
+
puts "Trello: Commenting on card ##{match[3].to_i}"
|
34
|
+
|
35
|
+
results = @http.get_card(@board_id, match[3].to_i)
|
36
|
+
unless results
|
37
|
+
puts "Trello: Cannot find card matching ID #{match[3]}"
|
38
|
+
return
|
39
|
+
end
|
40
|
+
results = JSON.parse(results)
|
41
|
+
|
42
|
+
# Determine the action to take
|
43
|
+
target_list_id = ""
|
44
|
+
target_list_id = case match[2].downcase
|
45
|
+
when "case", "card" then @list_id_in_progress
|
46
|
+
when "close", "fix" then @list_id_done
|
47
|
+
end
|
48
|
+
|
49
|
+
# Add the commit comment
|
50
|
+
message = "#{commit.author.name}:\n#{commit.message}"
|
51
|
+
message << "\n\n#{@commit_url_prefix}#{new_sha}" unless @commit_url_prefix.nil?
|
52
|
+
message.gsub!(match[1], "")
|
53
|
+
message.gsub!(/\(\)$/, "")
|
54
|
+
message.gsub!(/Signed-off-by: (.*) <(.*)>/,"")
|
55
|
+
@http.add_comment(results["id"], message)
|
56
|
+
|
57
|
+
unless target_list_id == ""
|
58
|
+
to_update = {}
|
59
|
+
unless results["idList"] == target_list_id
|
60
|
+
puts "Trello: Moving card ##{match[3].to_i} to list #{target_list_id}"
|
61
|
+
to_update[:idList] = target_list_id
|
62
|
+
@http.update_card(results["id"], to_update)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_trello_post_commit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jmchambers
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
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: json
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: git
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.2'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.2'
|
69
|
+
description: 'This gem can be used in a post-commit hook in any Git repository to
|
70
|
+
comment on and move Trello cards in a specified board. What will be done is based
|
71
|
+
on a Git commit message:for example, if a message contains ''Card #20'', post-commit
|
72
|
+
will add the rest of comment message as a comment on card #20.'
|
73
|
+
email:
|
74
|
+
- j.chambers@gmx.net
|
75
|
+
executables: []
|
76
|
+
extensions: []
|
77
|
+
extra_rdoc_files: []
|
78
|
+
files:
|
79
|
+
- .gitignore
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- git_trello_post_commit.gemspec
|
85
|
+
- lib/git_trello_post_commit.rb
|
86
|
+
- lib/git_trello_post_commit/trello-http.rb
|
87
|
+
- lib/git_trello_post_commit/version.rb
|
88
|
+
homepage: ''
|
89
|
+
licenses:
|
90
|
+
- MIT
|
91
|
+
metadata: {}
|
92
|
+
post_install_message:
|
93
|
+
rdoc_options: []
|
94
|
+
require_paths:
|
95
|
+
- lib
|
96
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
requirements: []
|
107
|
+
rubyforge_project:
|
108
|
+
rubygems_version: 2.1.10
|
109
|
+
signing_key:
|
110
|
+
specification_version: 4
|
111
|
+
summary: Update Trello cards with git commit messages.
|
112
|
+
test_files: []
|