github-trello-cl 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ae309b5667e125bcc1e13bfff8b932109547616
4
+ data.tar.gz: f0a476e318e67b9da2db3f3fbd2d20e19fb2ce69
5
+ SHA512:
6
+ metadata.gz: b9d93f3582be6b1067dda282f2396eeb94c9c8995801247b30758b308e19db2b5a86cb2a8d1e8d96b69fd25dce5d1e6a5644c23a9ec2d865ee2605b7bedd66ac
7
+ data.tar.gz: e43af0607cd3ae4a1ac167691f479300c377779af3c9486582cd77e6f26d6cd022a751f076aaa6c15d913a066419a006019f89c57a8ec90d1a92b64c1faaf4df
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,35 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ trello (0.0.2)
5
+ commander
6
+ configuration
7
+ httparty
8
+ launchy
9
+ recursive-open-struct
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ addressable (2.3.7)
15
+ commander (4.3.0)
16
+ highline (~> 1.6.11)
17
+ configuration (1.3.4)
18
+ highline (1.6.21)
19
+ httparty (0.13.3)
20
+ json (~> 1.8)
21
+ multi_xml (>= 0.5.2)
22
+ json (1.8.2)
23
+ launchy (2.4.3)
24
+ addressable (~> 2.3)
25
+ multi_xml (0.5.5)
26
+ rake (10.3.2)
27
+ recursive-open-struct (0.5.0)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ bundler (~> 1.6)
34
+ rake (~> 10.3.1)
35
+ trello!
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # trello-cl
2
+ Command-line tool to allow users to interact with Trello without actually using Trello.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/trello ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'trello'
4
+
5
+ Trello::Main.new.run
@@ -0,0 +1 @@
1
+ {}
data/lib/trello.rb ADDED
@@ -0,0 +1,150 @@
1
+ require 'commander'
2
+ require 'httparty'
3
+ require 'launchy'
4
+ require 'recursive-open-struct'
5
+ require 'trello/constants'
6
+ require 'trello/helpers'
7
+
8
+ module Trello
9
+ class Main
10
+ include Commander::Methods
11
+
12
+ def run
13
+ program :name, "Trello"
14
+ program :description, 'Trello interface'
15
+ program :version, '1.0.0'
16
+
17
+ command :init do |c|
18
+ c.syntax = 'trello init'
19
+ c.description = 'Generates a default config file for the Trello CLI so it can be used in this directory.'
20
+ c.action do |args, options|
21
+ FileUtils.cp(File.join(Helpers::root, '.trelloconfig.default'), './.trelloconfig')
22
+ say "Created .trelloconfig in this directory."
23
+ end
24
+ end
25
+
26
+ command 'server-config' do |c|
27
+ c.syntax = 'trello server-config'
28
+ c.description = 'Builds a config file for your API backend.'
29
+ c.action do |args, options|
30
+ trello_config = {base_url: "https://api.trello.com/1/"}
31
+ trello_config[:api_key] = ask("API key?")
32
+
33
+ url = "https://trello.com/1/authorize?key=#{trello_config[:api_key]}&name=Your+Application&expiration=never&response_type=token&scope=read,write"
34
+ puts "Requesting access to this application..."
35
+ sleep(0.5)
36
+ Launchy.open(url)
37
+ sleep(0.5)
38
+ trello_config[:token] = ask("What was the token?")
39
+
40
+ trello_config[:board_id] = Helpers::prompt_for("Which board should the API reference? (ID)") do
41
+ result = Helpers::make_trello_api_call(:get, "members/me", key: trello_config[:api_key], token: trello_config[:token], boards: 'open')['boards']
42
+
43
+ result.map do |board|
44
+ {id: board['id'], name: board['name']}
45
+ end
46
+ end
47
+
48
+ lists_resp = Helpers::make_trello_api_call(:get, "boards/#{trello_config[:board_id]}", key: trello_config[:api_key], token: trello_config[:token], lists: 'open')
49
+ lists = lists_resp['lists'].map do |list|
50
+ {id: list['id'], name: list['name']}
51
+ end
52
+
53
+ trello_config[:pending_columns] = Helpers::prompt_for_array("Which lists hold pending tasks? (ID,ID)") { lists }
54
+
55
+ {
56
+ in_development_column: "Which column represents tasks in development? (ID)",
57
+ in_review_column: "Which column represents tasks in review? (ID)",
58
+ approved_merged_column: "Which column represents tasks approved/merged to staging? (ID)",
59
+ deployed_column: "Which column represents tasks deployed to production? (ID)"
60
+ }.each do |field, message|
61
+ trello_config[field] = Helpers::prompt_for(message) { lists }
62
+ end
63
+
64
+ config_file = {
65
+ trello: trello_config
66
+ }
67
+
68
+ puts "Saving to config.json..."
69
+
70
+ Helpers::write_json_to_file(config_file, './config.json')
71
+ end
72
+ end
73
+
74
+ command :config do |c|
75
+ c.syntax = 'trello config --<field> value'
76
+ c.description = 'Configure options for the integration'
77
+ c.option '--user USERNAME', 'Configures the user\'s Trello username (required)'
78
+ c.option '--prefix initials', 'Initials to prepend to new branch names, e.g. \'[initials]-branch-name\''
79
+ c.action do |args, options|
80
+ if options.user
81
+ response = Helpers::make_trello_api_call(:get, "members/#{options.user}", {fields: :none},
82
+ not_found: "Couldn't find user #{options.user}.")
83
+ Helpers::config.user = response['id']
84
+ end
85
+
86
+ Helpers::config.prefix = options.prefix if options.prefix
87
+
88
+ Helpers::save_config
89
+ end
90
+ end
91
+
92
+ command :tasks do |c|
93
+ c.syntax = 'trello tasks [status]'
94
+ c.description = 'Shows tasks assigned to the configured user. If status is provided, shows tasks with the given status'
95
+ c.option '--all', 'Shows all tasks with the provided status, regardless of assignee'
96
+ c.action do |args, options|
97
+ user = options.all ? nil : Helpers::config['user']
98
+
99
+ status = args[0] || 'pending'
100
+
101
+ response = Helpers::make_integration_api_call(:get, "cards/#{status}", {},
102
+ bad_request: "Could not find lists for status #{status}.")
103
+
104
+ enable_paging
105
+ response.each do |list|
106
+ if user && list['cards'].none? {|card| card['idMembers'].include? user}
107
+ next
108
+ end
109
+
110
+ list_name = list['name']
111
+ say list_name
112
+ say ('-' * list_name.length)
113
+ list['cards'].each do |task|
114
+ if options.all || (user && task['idMembers'].include?(user))
115
+ say " ##{task['idShort']}: #{task['name']}"
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
121
+ alias_command :ls, :tasks
122
+ alias_command :list, :tasks
123
+
124
+ command :start do |c|
125
+ c.syntax = 'trello start 123 <branch>'
126
+ c.description = "Marks the specified card as 'in development' on Trello and associates the specified branch with the card."
127
+ c.option '--no-branch', 'Starts the card without creating a new branch.'
128
+ c.action do |args, options|
129
+ user = Helpers::config['user']
130
+ unless user
131
+ abort "You don't have a username configured - set one up so you can be assigned to cards"
132
+ end
133
+
134
+ unless args[1] || options['no-branch']
135
+ abort 'You need a branch name. To start this card without a branch, set the --no-branch flag (-n).'
136
+ end
137
+
138
+ branch = Helpers::config['prefix'] ? "#{Helpers::config['prefix']}-#{args[1]}" : args[1]
139
+
140
+ response = Helpers::make_integration_api_call(:post, "cards/#{args[0]}/start", {user: user, branch: branch},
141
+ not_found: "Could not find card #{args[0]}.")
142
+
143
+ say "Started card '#{response.parsed_response['name']}' with branch #{branch}."
144
+ end
145
+ end
146
+
147
+ run!
148
+ end
149
+ end
150
+ end
@@ -0,0 +1,9 @@
1
+ CONFIG_FILE_NAME = '.trelloconfig'
2
+ # API_BASE_PATH = "https://trello.bookbub.com/api/"
3
+ API_BASE_PATH = "http://trellobub.herokuapp.com/"
4
+ DEFAULT_ERROR_MESSAGES = {
5
+ bad_request: "Invalid request.",
6
+ auth: "Failed to authenticate.",
7
+ not_found: "Couldn't find the site.",
8
+ server_error: "Something broke in the server."
9
+ }
@@ -0,0 +1,119 @@
1
+ module Trello
2
+ module Helpers
3
+ class << self
4
+ def root
5
+ File.dirname __dir__
6
+ end
7
+
8
+ def make_api_call(method, url, body, errors = {})
9
+ api_errors = DEFAULT_ERROR_MESSAGES.merge(errors)
10
+ result = HTTParty.public_send(method, url, body: body)
11
+
12
+ unless result.success?
13
+ bad_response_msg = case result.code
14
+ when 400
15
+ api_errors[:bad_request]
16
+ when 401
17
+ api_errors[:auth]
18
+ when 404
19
+ api_errors[:not_found]
20
+ when 500
21
+ api_errors[:server_error]
22
+ else
23
+ "No message for error #{result.code}, message returned was #{result.inspect}"
24
+ end
25
+
26
+ abort bad_response_msg
27
+ end
28
+
29
+ result
30
+ end
31
+
32
+ def make_trello_api_call(method, endpoint, body, errors = {})
33
+ trello_errors = {
34
+ bad_request: "Authentication failed with token #{body[:token]}",
35
+ not_found: "Could not find Trello server - are you online?",
36
+ server_error: "Something blew up."
37
+ }.merge(errors)
38
+
39
+ make_api_call(method, "https://api.trello.com/1/#{endpoint}", body, trello_errors)
40
+ end
41
+
42
+ def make_integration_api_call(method, endpoint, body, errors = {})
43
+ make_api_call(method, "#{API_BASE_PATH}#{endpoint}", body, errors)
44
+ end
45
+
46
+ def to_i(str)
47
+ begin
48
+ Integer(str || '')
49
+ rescue ArgumentError
50
+ nil
51
+ end
52
+ end
53
+
54
+ def config
55
+ begin
56
+ @config ||= RecursiveOpenStruct.new(YAML.load_file(CONFIG_FILE_NAME))
57
+ rescue
58
+ abort "Could not load config - run 'trello init' to generate a config file."
59
+ end
60
+ end
61
+
62
+ def user_check
63
+ unless config['user']
64
+ abort "No user defined! Specify a user with trello config --user <username>."
65
+ end
66
+ end
67
+
68
+ def save_config
69
+ File.open(CONFIG_FILE_NAME, 'w') {|f| f.write config.to_hash.to_yaml }
70
+ end
71
+
72
+ def generate_branch(name, type)
73
+ prefix = config.name_prefix ? "#{config.name_prefix}-" : ''
74
+ try_external_command "git flow #{type} start #{prefix}#{name}"
75
+ end
76
+
77
+ def prompt_for_array(prompt_message)
78
+ var = nil
79
+ options = yield
80
+ options.each_with_index do |opt, i|
81
+ puts "#{i}: #{opt[:name]}"
82
+ end
83
+ until var
84
+ response = ask(prompt_message).split(',').map{|resp| to_i(resp)}
85
+ if response.all?{|id| id && options[id] }
86
+ var = options.values_at(*response).map{|option| option[:id]}
87
+ else
88
+ puts "Invalid array indices"
89
+ end
90
+ end
91
+
92
+ var
93
+ end
94
+
95
+ def prompt_for(prompt_message)
96
+ var = nil
97
+ options = yield
98
+ options.each_with_index do |opt, i|
99
+ puts "#{i}: #{opt[:name]}"
100
+ end
101
+ until var
102
+ response = to_i(ask(prompt_message))
103
+ if response && options[response]
104
+ var = options[response][:id]
105
+ else
106
+ say "Invalid array index"
107
+ end
108
+ end
109
+
110
+ var
111
+ end
112
+
113
+ def write_json_to_file(hash, filename)
114
+ puts hash
115
+ File.open(filename, 'w') {|f| f.write JSON.pretty_generate(hash)}
116
+ end
117
+ end
118
+ end
119
+ end
data/trello.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ $LOAD_PATH << File.expand_path('../lib', __FILE__)
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'github-trello-cl'
5
+ s.version = '0.0.3'
6
+ s.date = '2015-02-23'
7
+ s.summary = "Interface with trello"
8
+ s.description = "A tool to allow people using Trello as a workflow to interface with it via command line access to an API"
9
+ s.authors = ["Steve Pletcher"]
10
+ s.email = 'steve@steve-pletcher.com'
11
+ s.files = `git ls-files -z`.split("\x0")
12
+ s.require_paths = ["lib"]
13
+ s.executables = ["trello"]
14
+ s.homepage = 'http://rubygems.org/gems/trello'
15
+
16
+ s.add_development_dependency 'bundler', '~> 1.6'
17
+ s.add_development_dependency 'rake', '~> 10.3.1'
18
+
19
+ s.add_runtime_dependency 'commander'
20
+ s.add_runtime_dependency 'httparty'
21
+ s.add_runtime_dependency 'configuration'
22
+ s.add_runtime_dependency 'launchy'
23
+ s.add_runtime_dependency 'recursive-open-struct'
24
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github-trello-cl
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ platform: ruby
6
+ authors:
7
+ - Steve Pletcher
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-23 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 10.3.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 10.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: commander
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: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: configuration
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: launchy
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: recursive-open-struct
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A tool to allow people using Trello as a workflow to interface with it
112
+ via command line access to an API
113
+ email: steve@steve-pletcher.com
114
+ executables:
115
+ - trello
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - README.md
123
+ - Rakefile
124
+ - bin/trello
125
+ - lib/.trelloconfig.default
126
+ - lib/trello.rb
127
+ - lib/trello/constants.rb
128
+ - lib/trello/helpers.rb
129
+ - trello.gemspec
130
+ homepage: http://rubygems.org/gems/trello
131
+ licenses: []
132
+ metadata: {}
133
+ post_install_message:
134
+ rdoc_options: []
135
+ require_paths:
136
+ - lib
137
+ required_ruby_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ required_rubygems_version: !ruby/object:Gem::Requirement
143
+ requirements:
144
+ - - '>='
145
+ - !ruby/object:Gem::Version
146
+ version: '0'
147
+ requirements: []
148
+ rubyforge_project:
149
+ rubygems_version: 2.0.14
150
+ signing_key:
151
+ specification_version: 4
152
+ summary: Interface with trello
153
+ test_files: []