github-trello 0.0.3

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.
data/MIT-LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 Zachary Anker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ Overview
2
+ ===
3
+ Allows you to manage or reference your Trello board through commits to Github. Tag a commit with "Closes 1234" to have a card automatically archived, or "Card 1234" to have the commit sent to the card.
4
+
5
+ Commands
6
+ -
7
+ Commit messages are searched for `(case|card|close|archive|fix)e?s? \D?([0-9]+)` to find the card short id. Case/card resolve to on_start configuration, close/fix resolve to on_close, and archive will just archive the card regardless.
8
+
9
+ The commit message is added as a comment to the card as well.
10
+
11
+ Usage
12
+ -
13
+
14
+ See `trello-web --help` for a list of arguments for starting the server. If your domain name is foobar.com and the server is listening on port 4000, then set the posthook URL on Github to __http://foobar.com:4000/posthook__
15
+
16
+ On the first run, it will create an empty configuration file for you that you will need to configure based on how you want it to manage.
17
+
18
+ You will need to get your api key and OAuth token with read/write access that won't expire for this to work. You can either use your own account, or create a separate deployment one for this.
19
+
20
+ Go to https://trello.com/1/appKey/generate to get your key, then go to _https://trello.com/1/authorize?response_type=token&name=Trello+Github+Integration&scope=read,write&expiration=never&key=[Your Key Here]_ replacing __[Your Key Here]__ with the key Trello gave you. Authorize the request and then add the token and key to your trello.yml file.
21
+
22
+ You can get the board id from the URL, for example https://trello.com/board/trello-development/4d5ea62fd76aa1136000000c the board id is _4d5ea62fd76aa1136000000ca_.
23
+
24
+ There are 3 actions you can configure to decide what happens to a card. Currently due to a bug in Trello's API, you cannot move a card to another list through the API, so only __archive__ will work. The code is already in, just waiting on Trello to fix the bug.
25
+
26
+ To do
27
+ -
28
+ Once Trello fixes the list API bug, I'll be implementing an on deploy action for people who want to be able to move cards from list A to B, such as moving from a "Pending Deployment" to "Live" or just archiving the cards.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ require "bundler"
2
+ Bundler.setup
3
+
4
+ require "rake"
5
+ require "rspec"
6
+ require "rspec/core/rake_task"
7
+
8
+ RSpec::Core::RakeTask.new("spec") do |spec|
9
+ spec.pattern = "spec/**/*_spec.rb"
10
+ end
11
+
12
+ task :default => :spec
data/bin/trello-web ADDED
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + "/../lib")
3
+
4
+ require "vegas"
5
+ require "yaml"
6
+ require "github-trello/server"
7
+
8
+ Vegas::Runner.new(GithubTrello::Server, "trello-web", {
9
+ :launch_path => lambda {|vegas|
10
+ path = File.join(vegas.app_dir, "trello.yml")
11
+ if File.exists?(path)
12
+ GithubTrello::Server.config = YAML::load(File.read(path))
13
+ else
14
+ puts "[WARNING] No configuration found at #{path}."
15
+ puts "We've generated an example one for you, but you need to configure it still."
16
+
17
+ File.open(path, "w+") do |f|
18
+ f.write("# NOTE: Due to a Trello API bug, currently only archive is supported and not move_to.\n\nboard_ids:\n [repo name]: [board id]\noauth_token: [token]\napi_key: [key]\non_start:\n move_to: [list id]\non_close:\n move_to: [list id]\n archive: false\non_deploy:\n move_to: [list id]\n archive: true")
19
+ end
20
+
21
+ exit
22
+ end
23
+
24
+ nil
25
+ }
26
+ })
@@ -0,0 +1 @@
1
+ require "github-trello/version"
@@ -0,0 +1,52 @@
1
+ require "cgi"
2
+ require "net/https"
3
+
4
+ module GithubTrello
5
+ class HTTP
6
+ def initialize(token, api_key)
7
+ @token, @api_key = token, api_key
8
+ @uri = URI("https://api.trello.com")
9
+ end
10
+
11
+ def get_card(board_id, card_id)
12
+ http_request(:get, "/1/boards/#{board_id}/cards/#{card_id}", :params => {:fields => "idList,closed"})
13
+ end
14
+
15
+ def update_card(card_id, params)
16
+ http_request(:put, "/1/cards/#{card_id}", :params => params)
17
+ end
18
+
19
+ def add_comment(card_id, comment)
20
+ http_request(:post, "/1/cards/#{card_id}/actions/comments", :body => "text=#{CGI::escape(comment)}")
21
+ end
22
+
23
+ private
24
+ def http_request(method, request_path, args={})
25
+ request_path << "?"
26
+ args[:params] ||= {}
27
+ args[:params][:key] = @api_key
28
+ args[:params][:token] = @token
29
+ args[:params].each {|k, v| request_path << "#{k}=#{CGI::escape(v.to_s)}&"}
30
+
31
+ http = Net::HTTP.new(@uri.host, @uri.port)
32
+ http.use_ssl = true
33
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
34
+
35
+ http.start
36
+
37
+ if method == :get
38
+ response = http.request_get(request_path)
39
+ elsif method == :post
40
+ response = http.request_post(request_path, args.delete(:body))
41
+ elsif method == :put
42
+ response = http.request_put(request_path, args.delete(:body))
43
+ end
44
+
45
+ unless response.code == "200" or response.code == "201"
46
+ raise Net::HTTPError.new("#{response.body == "" ? response.message : response.body.strip} (#{response.code})", response)
47
+ end
48
+
49
+ response.body
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,87 @@
1
+ require "json"
2
+ require "sinatra/base"
3
+ require "github-trello/version"
4
+ require "github-trello/http"
5
+
6
+ module GithubTrello
7
+ class Server < Sinatra::Base
8
+ post "/posthook" do
9
+ config, http = self.class.config, self.class.http
10
+
11
+ payload = JSON.parse(params[:payload])
12
+
13
+ board_id = config["board_ids"][payload["repository"]["name"]]
14
+ unless board_id
15
+ puts "[ERROR] Commit from #{payload["repository"]["name"]} but no board_id entry found in config"
16
+ return
17
+ end
18
+
19
+ branch = payload["ref"].gsub("refs/heads/", "")
20
+ if config["blacklist_branches"] and config["blacklist_branches"].include?(branch)
21
+ return
22
+ elsif config["whitelist_branches"] and !config["whitelist_branches"].include?(branch)
23
+ return
24
+ end
25
+
26
+ payload["commits"].each do |commit|
27
+ # Figure out the card short id
28
+ match = commit["message"].match(/((case|card|close|archive|fix)e?s? \D?([0-9]+))/i)
29
+ next unless match and match[3].to_i > 0
30
+
31
+ results = http.get_card(board_id, match[3].to_i)
32
+ unless results
33
+ puts "[ERROR] Cannot find card matching ID #{match[3]}"
34
+ next
35
+ end
36
+
37
+ results = JSON.parse(results)
38
+
39
+ # Add the commit comment
40
+ message = "#{commit["author"]["name"]}: #{commit["message"]}\n\n[#{branch}] #{commit["url"]}"
41
+ message.gsub!(match[1], "")
42
+ message.gsub!(/\(\)$/, "")
43
+
44
+ http.add_comment(results["id"], message)
45
+
46
+ # Determine the action to take
47
+ update_config = case match[2].downcase
48
+ when "case", "card" then config["on_start"]
49
+ when "close", "fix" then config["on_close"]
50
+ when "archive" then {:archive => true}
51
+ end
52
+
53
+ next unless update_config.is_a?(Hash)
54
+
55
+ # Modify it if needed
56
+ to_update = {}
57
+
58
+ # Disabled for now due to a Trello bug
59
+ #unless results["idList"] == update_config["move_to"]
60
+ # to_update[:idList] = update_config["move_to"]
61
+ #end
62
+
63
+ if !results["closed"] and update_config["archive"]
64
+ to_update[:closed] = true
65
+ end
66
+
67
+ unless to_update.empty?
68
+ http.update_card(results["id"], to_update)
69
+ end
70
+ end
71
+
72
+ ""
73
+ end
74
+
75
+ get "/" do
76
+ "Nothing to see here"
77
+ end
78
+
79
+ def self.config=(config)
80
+ @config = config
81
+ @http = GithubTrello::HTTP.new(config["oauth_token"], config["api_key"])
82
+ end
83
+
84
+ def self.config; @config end
85
+ def self.http; @http end
86
+ end
87
+ end
@@ -0,0 +1,3 @@
1
+ module GithubTrello
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github-trello
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Zachary Anker
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-04-10 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: vegas
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 0.1.8
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: 0.1.8
30
+ - !ruby/object:Gem::Dependency
31
+ name: sinatra
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: 1.3.2
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: 1.3.2
46
+ description: Enables managing Trello cards through Github posthooks and Git commits
47
+ email:
48
+ - zach.anker@gmail.com
49
+ executables:
50
+ - trello-web
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - lib/github-trello/http.rb
55
+ - lib/github-trello/server.rb
56
+ - lib/github-trello/version.rb
57
+ - lib/github-trello.rb
58
+ - MIT-LICENSE
59
+ - README.md
60
+ - Rakefile
61
+ - !binary |-
62
+ YmluL3RyZWxsby13ZWI=
63
+ homepage: http://github.com/zanker/github-trello
64
+ licenses: []
65
+ post_install_message:
66
+ rdoc_options: []
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ! '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ! '>='
79
+ - !ruby/object:Gem::Version
80
+ version: 1.3.6
81
+ requirements: []
82
+ rubyforge_project: github-trello
83
+ rubygems_version: 1.8.21
84
+ signing_key:
85
+ specification_version: 3
86
+ summary: Github -> Trello integration
87
+ test_files: []