trello2wr 1.0.5 → 1.0.6

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/trello2wr +22 -1
  3. data/lib/trello2wr.rb +52 -39
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 61018a6dcf0faacb02b37ae78ddce7bc5a00095f
4
- data.tar.gz: 4e0ef00e5bfb175d1bcfa4fbc0517947588d52dd
3
+ metadata.gz: cbd6bcc6972385e8f135e49a1385a1803c89e0f1
4
+ data.tar.gz: 3acd92c94a7599cb85fdc27e2120d6f63591ee2f
5
5
  SHA512:
6
- metadata.gz: 9bd0789fe25d140ea381d476ebacd9556e131054190b09b65a0bd55190f632a8571fffff739f6d02d4e3612e65a147330343072770193ac9a26f43e448e48862
7
- data.tar.gz: 2ae41ec2a78fcff704a040a1778b0a141f90be513d0560dd5514b35571f1d508fb5d0cfe85a459211de496e500bbad7d3635c59517a9fff45c515b6a5552213b
6
+ metadata.gz: dcde24bebeffe678fd56c0ce0ecb57cc3d31ef457617876c4607f4cc0acf2a36f89e698d3f2698649342bfcf7ced6a62341eb588103e1103a411fb2d0ff410af
7
+ data.tar.gz: 4f00acba191f90d6729c6e1fb60a21f4558dcc40bfe2f8336e3a5e92376666bf34ff26a4ff9d3c0e03c623a1e7080c64844085608344474e1286b24fd77552da
@@ -3,5 +3,26 @@ $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
3
3
 
4
4
  require 'rubygems'
5
5
  require 'trello2wr'
6
+ require 'optparse'
6
7
 
7
- Trello2WR.new().export
8
+ options = { week: Date.today.cweek-1 }
9
+
10
+ OptionParser.new do |opts|
11
+ opts.banner = "Usage: trello2wr [options]"
12
+
13
+ opts.on("-s", "--sprint [SPRINT NUMBER]", Numeric, "Generate a report for given sprint") do |s|
14
+ options[:sprint] = s
15
+ end
16
+
17
+ opts.on("-w", "--week [WEEK NUMBER]", Numeric, "Generate a report for given week") do |w|
18
+ options[:week] = w
19
+ end
20
+
21
+ opts.on("-h", "--help", "Prints this help") do
22
+ puts opts
23
+ exit
24
+ end
25
+
26
+ end.parse!
27
+
28
+ Trello2WR.new(options[:sprint], options[:week]).export
@@ -2,58 +2,71 @@ require 'trello'
2
2
  require 'yaml'
3
3
  require 'uri'
4
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
5
  class Trello2WR
12
6
  include Trello
13
7
  include Trello::Authorization
14
8
 
15
- attr_reader :user, :board, :year, :week
9
+ attr_reader :user, :board, :week
16
10
  @@debug = true
17
11
 
18
- def initialize
12
+ def initialize(sprint=nil, week)
13
+ @config = load_config
14
+
15
+ authenticate
16
+
17
+ @sprint = sprint
18
+ @week = week
19
+
20
+ @username = @config['trello']['username']
21
+ @user = find_member(@username)
22
+ @board = find_board
23
+ end
24
+
25
+ def authenticate
19
26
  Trello::Authorization.const_set :AuthPolicy, OAuthPolicy
27
+ OAuthPolicy.consumer_credential = OAuthCredential.new @config['trello']['developer_public_key'], @config['trello']['developer_secret']
28
+ OAuthPolicy.token = OAuthCredential.new @config['trello']['member_token'], nil
29
+ end
20
30
 
31
+ def load_config
21
32
  # 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
33
+ if File.exist? File.expand_path("~/.trello2wr/config.yml")
34
+ YAML.load_file(File.expand_path("~/.trello2wr/config.yml"))
35
+ else
36
+ raise "ERROR: Config file not found!"
37
+ end
38
+ end
28
39
 
29
- self.log("*** Searching for user '#{CONFIG['trello']['username']}'")
40
+ def find_member(username)
41
+ self.log("*** Searching for user '#{username}'")
30
42
 
31
43
  begin
32
- @user = Member.find(CONFIG['trello']['username'])
44
+ Member.find(username)
33
45
  rescue Trello::Error
34
- raise "ERROR: user '#{CONFIG['trello']['username']}' not found!}"
46
+ raise "ERROR: user '#{username}' not found!}"
35
47
  end
48
+ end
36
49
 
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}
50
+ def find_board
51
+ board = @config['trello']['boards'].first
52
+ self.log("*** Getting lists for '#{board}' board")
53
+ @user.boards.find{|b| b.name == board}
43
54
  end
44
55
 
45
56
  def cards(board, list_name)
46
57
  self.log("*** Getting cards for '#{list_name}' list")
47
58
 
48
59
  if board
60
+ lists = board.lists
61
+
49
62
  if list_name == 'Done'
50
- previous_week = (self.week-1)
51
- done_lists = board.lists.select{|l| l.name.include?('Done')}
52
- latest_list = done_lists.sort_by(&:name).last
53
- latest_list.cards.select{|c| c.last_activity_date.to_datetime.cweek == previous_week && c.member_ids.include?(user.id) }
63
+ lists = lists.select{|l| l.name.include?('Done')}
64
+ list = @sprint ? lists.select{|l| l.name.include?(@sprint.to_s) }.first : lists.sort_by{|l| l.id }.last
65
+
66
+ self.log("*** Getting cards for '#{list.name}' list (week #{@week})")
67
+ list.cards.select{|c| c.last_activity_date.to_datetime.cweek == @week && c.member_ids.include?(user.id) }
54
68
  else
55
- list = board.lists.find{|l| l.name == list_name}
56
- list.cards.select{|c| c.member_ids.include? self.user.id}
69
+ lists.find{|l| l.name == list_name}.cards.select{|c| c.member_ids.include? self.user.id}
57
70
  end
58
71
  else
59
72
  raise "ERROR: Board '#{list_name}' not found!"
@@ -74,10 +87,10 @@ class Trello2WR
74
87
  elsif list_name.downcase.include? 'review'
75
88
  body += "\nIn review:\n"
76
89
  elsif list_name.downcase.include? 'to do'
77
- body += "\nObjectives:\n" if list_name.downcase.include? 'to do'
90
+ body += "\nObjectives:\n"
78
91
  end
79
92
 
80
- self.cards(self.board, list_name).each do |card|
93
+ self.cards(board, list_name).each do |card|
81
94
  if list_name.downcase.include? 'doing'
82
95
  body += "- #{card.name} (##{card.short_id}) [WIP]\n"
83
96
  else
@@ -87,15 +100,15 @@ class Trello2WR
87
100
  end
88
101
 
89
102
  body += "\n\nNOTE: (#<number>) are Trello board card IDs"
90
- self.escape(body)
103
+
104
+ escape(body)
91
105
  end
92
106
 
93
107
  def construct_mail_to_url(recipient, subject, body)
94
- if CONFIG['email'].has_key?('cc') && CONFIG['email']['cc'].present?
95
- URI::MailTo.build({:to => recipient, :headers => {"cc" => CONFIG['email']['cc'], "subject" => subject, "body" => body}}).to_s.inspect
96
- else
97
- URI::MailTo.build({:to => recipient, :headers => {"subject" => subject, "body" => body}}).to_s.inspect
98
- end
108
+ headers = { subject: subject, body: body }
109
+ headers[:cc] = @config['email']['cc'] if @config['email'].has_key?('cc') && @config['email']['cc'].present?
110
+
111
+ URI::MailTo.build({:to => recipient, :headers => headers.stringify_keys}).to_s.inspect
99
112
  end
100
113
 
101
114
  def escape(string)
@@ -103,10 +116,10 @@ class Trello2WR
103
116
  end
104
117
 
105
118
  def export
106
- mailto = self.construct_mail_to_url(CONFIG['email']['recipient'], self.subject, self.body)
119
+ mailto = self.construct_mail_to_url(@config['email']['recipient'], subject, body)
107
120
  self.log("*** Preparing email, please wait ...")
108
121
 
109
- system("#{CONFIG['email']['client']} #{mailto}")
122
+ system("#{@config['email']['client']} #{mailto}")
110
123
 
111
124
  self.log("*** DONE")
112
125
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trello2wr
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Lewin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-10 00:00:00.000000000 Z
11
+ date: 2015-05-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-trello