trello2wr 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +7 -0
  2. data/bin/trello2wr +7 -0
  3. data/lib/trello2wr.rb +119 -0
  4. metadata +60 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5e156c9a390fea6dbc9bee88f6f63771a78df91d
4
+ data.tar.gz: 64db4c05cbded8f29c12d4a3adacfcf8285a459b
5
+ SHA512:
6
+ metadata.gz: eecd37d0bde6b33b9e91dfe743f962b2b3e59f84901026110b678cfb76cbfc3cdeab781b9f01e32e97a66415e6a9c3f9b42647c1b207900cc86a49cf13a57faf
7
+ data.tar.gz: 19c13de1bcaaeb12ddc8e68ec16b2065d73a3923751acaa9c5ef98eb6cb6a9f72ccafda0b94029c1f8423c47b58b98e1ef8a5ee33a0b6f1a41cb379571899ec7
data/bin/trello2wr ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
+
4
+ require 'rubygems'
5
+ require 'trello2wr'
6
+
7
+ Trello2WR.new().export
data/lib/trello2wr.rb ADDED
@@ -0,0 +1,119 @@
1
+ require 'trello'
2
+ require 'yaml'
3
+ require 'uri'
4
+
5
+ if File.exist? File.expand_path("~/.trello2wr/config.yml")
6
+ CONFIG = YAML.load_file(File.expand_path("~/.trello2wr/config.yml"))
7
+ else
8
+ raise "ERROR: Config file not found!"
9
+ end
10
+
11
+ class Trello2WR
12
+ include Trello
13
+ include Trello::Authorization
14
+
15
+ attr_reader :user, :board, :year, :week
16
+ @@debug = true
17
+
18
+ def initialize
19
+ Trello::Authorization.const_set :AuthPolicy, OAuthPolicy
20
+
21
+ # Read keys from ~/trello2wr/config.yml
22
+ key = CONFIG['trello']['developer_public_key']
23
+ secret = CONFIG['trello']['developer_secret']
24
+ token = CONFIG['trello']['member_token']
25
+
26
+ OAuthPolicy.consumer_credential = OAuthCredential.new key, secret
27
+ OAuthPolicy.token = OAuthCredential.new token, nil
28
+
29
+ self.log("*** Searching for user '#{CONFIG['trello']['username']}'")
30
+
31
+ begin
32
+ @user = Member.find(CONFIG['trello']['username'])
33
+ rescue Trello::Error
34
+ raise "ERROR: user '#{CONFIG['trello']['username']}' not found!}"
35
+ end
36
+
37
+ @year = Date.today.year
38
+ @week = Date.today.cweek
39
+
40
+ # FIXME: Allow more than one board
41
+ # self.log("*** Getting lists for '#{CONFIG['trello']['boards'].first}' board")
42
+ @board = @user.boards.find{|b| b.name == CONFIG['trello']['boards'].first}
43
+ end
44
+
45
+ def cards(board, list_name)
46
+ self.log("*** Getting cards for '#{list_name}' list")
47
+
48
+ if board
49
+ if list_name == 'Done'
50
+ list = board.lists.select{|l| l.name.include?('Done') && l.name.include?((self.week-1).to_s) }.first
51
+ else
52
+ list = board.lists.find{|l| l.name == list_name}
53
+ end
54
+
55
+ cards = list.cards.select{|c| c.member_ids.include? self.user.id}
56
+
57
+ return cards
58
+ else
59
+ raise "ERROR: Board '#{list_name}' not found!"
60
+ end
61
+ end
62
+
63
+ # Prepare mail header
64
+ def subject
65
+ self.escape("A&O Week ##{self.week} #{self.user.username}")
66
+ end
67
+
68
+ # Prepare mail body
69
+ def body
70
+ body = ''
71
+ ['Done', 'In review', 'To Do', 'Doing'].each do |list_name|
72
+ if list_name.downcase.include? 'done'
73
+ body += "Accomplishments:\n"
74
+ elsif list_name.downcase.include? 'review'
75
+ body += "\nIn review:\n"
76
+ elsif list_name.downcase.include? 'to do'
77
+ body += "\nObjectives:\n" if list_name.downcase.include? 'to do'
78
+ end
79
+
80
+ self.cards(self.board, list_name).each do |card|
81
+ if list_name.downcase.include? 'doing'
82
+ body += "- #{card.name} (##{card.short_id}) [WIP]\n"
83
+ elsif list_name.downcase.include? 'review'
84
+ body += "- #{card.name} (##{card.short_id}) [REVIEW]\n"
85
+ else
86
+ body += "- #{card.name} (##{card.short_id})\n"
87
+ end
88
+ end
89
+ end
90
+
91
+ body += "\n\nNOTE: (#<number>) are Trello board card IDs"
92
+ self.escape(body)
93
+ end
94
+
95
+ def construct_mail_to_url(recipient, subject, body)
96
+ if CONFIG['email'].has_key?('cc') && CONFIG['email']['cc'].present?
97
+ URI::MailTo.build({:to => recipient, :headers => {"cc" => CONFIG['email']['cc'], "subject" => subject, "body" => body}}).to_s.inspect
98
+ else
99
+ URI::MailTo.build({:to => recipient, :headers => {"subject" => subject, "body" => body}}).to_s.inspect
100
+ end
101
+ end
102
+
103
+ def escape(string)
104
+ URI.escape(string, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
105
+ end
106
+
107
+ def export
108
+ mailto = self.construct_mail_to_url(CONFIG['email']['recipient'], self.subject, self.body)
109
+ self.log("*** Preparing email, please wait ...")
110
+
111
+ system("#{CONFIG['email']['client']} #{mailto}")
112
+
113
+ self.log("*** DONE")
114
+ end
115
+
116
+ def log(message)
117
+ puts message if @@debug
118
+ end
119
+ end
metadata ADDED
@@ -0,0 +1,60 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trello2wr
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Vladislav Lewin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-trello
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: Generates weekly work report (A&O) from Trello board
28
+ email: vlewin@suse.de
29
+ executables:
30
+ - trello2wr
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - lib/trello2wr.rb
35
+ - bin/trello2wr
36
+ homepage: https://github.com/vlewin/trello2wr
37
+ licenses: []
38
+ metadata: {}
39
+ post_install_message:
40
+ rdoc_options: []
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 2.1.11
56
+ signing_key:
57
+ specification_version: 4
58
+ summary: A&O from Trello
59
+ test_files: []
60
+ has_rdoc: