pello 0.3 → 0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c85bd4f1d9080e27d0b8738141d556464c690f10b3cca2685aaaf79fa8d4511
4
- data.tar.gz: 6fee889e4547385203fe90833fc959cab8fdf0cdf8bc084535ef7cba974a61cb
3
+ metadata.gz: 74bd8b698e92b1cd698098387770e68aa62da299b6b72552694ef5345a385a41
4
+ data.tar.gz: e0eff537dbc2c3da8f66282317b529ff773fa2d4a7dda7c14bf19e5744f1f3b3
5
5
  SHA512:
6
- metadata.gz: 4a9d6a69228c7d7d3d1a05e9a2706d4e8692158345a603d32251ce283a7af0d2bbfd453a539ae0056edab0aa51dcbab0cf282dde939a77d00ec502211e3875b4
7
- data.tar.gz: bd0c992649f399d3bdd95572859eb5a6c04d1805056d46a62866887f946e2d1bc96766a36398b58402c549b85aef3adb1cadf7cdef9b24d7d10c25b24566d180
6
+ metadata.gz: 820369d314e252c1b758235d8a24d271eacf418991d204bcd5a4e6098687462702c25ef456cf91e02ffe6c668a15f41547f0a9e6e93ded41a604f2295ed6a53c
7
+ data.tar.gz: 2d5cd13e26ed76b138731770d01232fd66d61a54698e40a4750e907de72a0d9b0ac6020765584f821cb49ce7288eecd13ebf9f51e32aab30fa7e7f1f31dcc956
@@ -3,10 +3,11 @@
3
3
  module Pello
4
4
  module Actions
5
5
  class AddPomodoriToCard
6
- attr_reader :prompt
6
+ attr_reader :prompt, :logger
7
7
 
8
- def initialize(prompt)
8
+ def initialize(prompt, logger = Pello::CardLogger.new)
9
9
  @prompt = prompt
10
+ @logger = logger
10
11
  end
11
12
 
12
13
  def run(user, board_url, list_name)
@@ -33,7 +34,7 @@ module Pello
33
34
  if prompt.yes?('Confirm?')
34
35
  card.name = new_name
35
36
  card.save
36
- card.log "[#{Time.now}] #{card.extract_name} (#{pomodori_before} -> #{card.extract_pomodori})", user
37
+ logger.log user, card, "[#{Time.now}] #{card.extract_name} (#{pomodori_before} -> #{card.extract_pomodori})"
37
38
  puts('Done!')
38
39
  else
39
40
  puts 'Ok, bye!'
@@ -3,10 +3,11 @@
3
3
  module Pello
4
4
  module Actions
5
5
  class MoveCard
6
- attr_reader :prompt
6
+ attr_reader :prompt, :logger
7
7
 
8
- def initialize(prompt)
8
+ def initialize(prompt, logger = Pello::CardLogger.new)
9
9
  @prompt = prompt
10
+ @logger = logger
10
11
  end
11
12
 
12
13
  def run(user, board_url, list_name)
@@ -30,7 +31,7 @@ module Pello
30
31
  if prompt.yes?('Confirm?')
31
32
  card.list_id = target_list.id
32
33
  card.save
33
- card.log "[#{Time.now}] #{card.extract_name} (#{source_list.name} -> #{target_list.name})", user
34
+ logger.log user, card, "[#{Time.now}] #{card.extract_name} (#{source_list.name} -> #{target_list.name})"
34
35
  puts('Done!')
35
36
  else
36
37
  puts 'Ok, bye!'
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pello
4
+ module Actions
5
+ class Report
6
+ POMODORI_ADDED_COMMENT = /\((\d+) -> (\d+)\)$/.freeze
7
+
8
+ def run(user, board_url)
9
+ board = Pello::Inputs.choose_board user, board_url
10
+ return unless board
11
+
12
+ board_totals = {}
13
+
14
+ lists = board.lists
15
+ lists.each do |list|
16
+ list_totals = {}
17
+ list.cards.each do |card|
18
+ card.comments.select { |comment| pello_log?(comment) }.each do |comment|
19
+ lines_with_pomodori_increases_in(comment).each do |line|
20
+ author_name = cached_author_name(comment.creator_id)
21
+ pom_before, pom_after = pomodori_before_and_after_from(line)
22
+ update_counters(list_totals, author_name, (pom_after - pom_before))
23
+ update_counters(board_totals, author_name, (pom_after - pom_before))
24
+ end
25
+ end
26
+ end
27
+
28
+ print_counters(list_totals, list.name) if list_totals.any?
29
+ end
30
+
31
+ print_counters(board_totals, 'Totals')
32
+ puts "\n"
33
+ end
34
+
35
+ def pomodori_before_and_after_from(comment_line)
36
+ comment_line.match(POMODORI_ADDED_COMMENT)[1, 2].map(&:to_i)
37
+ end
38
+
39
+ def lines_with_pomodori_increases_in(comment)
40
+ comment.data['text'].split("\n").select { |line| line.match? POMODORI_ADDED_COMMENT }
41
+ end
42
+
43
+ def pello_log?(comment)
44
+ comment.data['text'] =~ /PELLO LOG/
45
+ end
46
+
47
+ def update_counters(counters, author_name, amount_to_add)
48
+ counters[author_name] ||= 0
49
+ counters[author_name] = counters[author_name] + amount_to_add
50
+ end
51
+
52
+ def print_counters(counters, label)
53
+ puts "\n-- #{label}:"
54
+ counters.each { |author_name, author_total| puts "* #{author_name}: #{author_total}" }
55
+ end
56
+
57
+ def cached_author_name(author_id)
58
+ @author_names ||= {}
59
+ @author_names[author_id] ||= Trello::Member.find(author_id).full_name
60
+ @author_names[author_id]
61
+ end
62
+ end
63
+ end
64
+ end
data/lib/pello/card.rb CHANGED
@@ -28,17 +28,5 @@ module Pello
28
28
  points ||= 0
29
29
  points.to_f
30
30
  end
31
-
32
- def log(event, user)
33
- comment = comments.select { |c| c.creator_id == user.id && c.data['text'] =~ /PELLO LOG/ }.first
34
- if comment
35
- new_text = [comment.data['text'], event].join("\n")
36
- comment.delete
37
- add_comment new_text
38
- else
39
- text = ['~~~PELLO LOG', event].join("\n")
40
- add_comment text
41
- end
42
- end
43
31
  end
44
32
  end
@@ -0,0 +1,14 @@
1
+ module Pello
2
+ class CardLogger
3
+ def log(user, card, event)
4
+ comment = card.comments.select { |c| c.creator_id == user.id && c.data['text'] =~ /PELLO LOG/ }.first
5
+ if comment
6
+ text = [comment.data['text'], event].join("\n")
7
+ comment.delete
8
+ else
9
+ text = ['~~~PELLO LOG', event].join("\n")
10
+ end
11
+ card.add_comment text
12
+ end
13
+ end
14
+ end
data/lib/pello/runner.rb CHANGED
@@ -24,6 +24,7 @@ module Pello
24
24
  case prompt.select('Choose task') do |menu|
25
25
  menu.choice name: 'Add pomodori', value: :add_pomodori
26
26
  menu.choice name: 'Move card', value: :move_card
27
+ menu.choice name: 'Print board pomodori report', value: :report
27
28
  menu.choice name: 'Edit config', value: :edit_config
28
29
  menu.choice name: 'quit', value: :quit
29
30
  end
@@ -31,6 +32,8 @@ module Pello
31
32
  add_pomodori_to_card
32
33
  when :move_card
33
34
  move_card
35
+ when :report
36
+ report
34
37
  when :edit_config
35
38
  editor = ENV['EDITOR'] || 'vim'
36
39
  system 'mkdir -p ~/.config/pello'
@@ -52,6 +55,10 @@ module Pello
52
55
  Pello::Actions::MoveCard.new(prompt).run(@user, board_url, list_name)
53
56
  end
54
57
 
58
+ def report
59
+ Pello::Actions::Report.new.run(@user, board_url)
60
+ end
61
+
55
62
  def configure_pello
56
63
  config = Pello::Config.new
57
64
  if config.valid?
data/lib/pello/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pello
2
- VERSION = "0.3"
2
+ VERSION = "0.4"
3
3
  end
data/lib/pello.rb CHANGED
@@ -4,8 +4,10 @@ require 'pello/inputs'
4
4
  require 'pello/board'
5
5
  require 'pello/list'
6
6
  require 'pello/card'
7
+ require 'pello/card_logger'
7
8
  require 'pello/actions/add_pomodori_to_card'
8
9
  require 'pello/actions/move_card'
10
+ require 'pello/actions/report'
9
11
  require 'pello/config'
10
12
 
11
13
  module Pello
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pello
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrea Schiavini
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-01-30 00:00:00.000000000 Z
11
+ date: 2022-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-trello
@@ -65,8 +65,10 @@ files:
65
65
  - lib/pello.rb
66
66
  - lib/pello/actions/add_pomodori_to_card.rb
67
67
  - lib/pello/actions/move_card.rb
68
+ - lib/pello/actions/report.rb
68
69
  - lib/pello/board.rb
69
70
  - lib/pello/card.rb
71
+ - lib/pello/card_logger.rb
70
72
  - lib/pello/config.rb
71
73
  - lib/pello/inputs.rb
72
74
  - lib/pello/list.rb