pello 0.1.1 → 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: ad5aeac8cb842a98bd69be325b1ebbaecbec31bedbc078773dbb2245123f2dce
4
- data.tar.gz: 59d677d28e39e48cf1b86fc7ff86ffd7645e44b473f42e45a7cf41d903aa992f
3
+ metadata.gz: 74bd8b698e92b1cd698098387770e68aa62da299b6b72552694ef5345a385a41
4
+ data.tar.gz: e0eff537dbc2c3da8f66282317b529ff773fa2d4a7dda7c14bf19e5744f1f3b3
5
5
  SHA512:
6
- metadata.gz: 6b26cc8641bf5f4230bd5adea22fdf5e5440c528e7dc651fe632d919bdc7ee3a2484baeec781af2e0df37986bbdb881046dc182bf845963807a76514c8738d78
7
- data.tar.gz: 6baac99b9a92d8c75fea887c17451bdc290feb756bb8e8968968c011a165d326da7c3bfbd16a6bb1466397ec2e3fe6a9740c02b19fd62128d7be2c2762388382
6
+ metadata.gz: 820369d314e252c1b758235d8a24d271eacf418991d204bcd5a4e6098687462702c25ef456cf91e02ffe6c668a15f41547f0a9e6e93ded41a604f2295ed6a53c
7
+ data.tar.gz: 2d5cd13e26ed76b138731770d01232fd66d61a54698e40a4750e907de72a0d9b0ac6020765584f821cb49ce7288eecd13ebf9f51e32aab30fa7e7f1f31dcc956
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pello
4
+ module Actions
5
+ class AddPomodoriToCard
6
+ attr_reader :prompt, :logger
7
+
8
+ def initialize(prompt, logger = Pello::CardLogger.new)
9
+ @prompt = prompt
10
+ @logger = logger
11
+ end
12
+
13
+ def run(user, board_url, list_name)
14
+ board = Pello::Inputs.choose_board user, board_url
15
+ return unless board
16
+
17
+ puts board.as_table
18
+ continue = true
19
+ while continue
20
+ list = Pello::Inputs.choose_list board, list_name
21
+ return unless list
22
+
23
+ card = Pello::Inputs.choose_card list
24
+ next unless card
25
+
26
+ pomodori_before = card.extract_pomodori
27
+ pomodori_to_add = prompt.ask('Pomodori', default: 1)
28
+
29
+ new_name = name_with_added_pomodori(card, pomodori_to_add.to_i)
30
+
31
+ puts "Updating card #{card.name}"
32
+ puts "New title: #{new_name}"
33
+
34
+ if prompt.yes?('Confirm?')
35
+ card.name = new_name
36
+ card.save
37
+ logger.log user, card, "[#{Time.now}] #{card.extract_name} (#{pomodori_before} -> #{card.extract_pomodori})"
38
+ puts('Done!')
39
+ else
40
+ puts 'Ok, bye!'
41
+ nil
42
+ end
43
+
44
+ continue = prompt.yes?('Another one?')
45
+ end
46
+ end
47
+
48
+ private
49
+
50
+ def name_with_added_pomodori(card, pomodori_to_add)
51
+ current_pomodori = card.extract_pomodori
52
+ current_points = card.extract_points
53
+ current_name = card.extract_name
54
+
55
+ result = []
56
+ result << "(#{current_points})" unless current_points.zero?
57
+ result << "#{current_pomodori + pomodori_to_add} 🍅"
58
+ result << current_name
59
+ result.join(' ')
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pello
4
+ module Actions
5
+ class MoveCard
6
+ attr_reader :prompt, :logger
7
+
8
+ def initialize(prompt, logger = Pello::CardLogger.new)
9
+ @prompt = prompt
10
+ @logger = logger
11
+ end
12
+
13
+ def run(user, board_url, list_name)
14
+ board = Pello::Inputs.choose_board user, board_url
15
+ return unless board
16
+
17
+ puts board.as_table
18
+ continue = true
19
+ while continue
20
+ source_list = Pello::Inputs.choose_list board, list_name, 'Choose source list'
21
+ return unless source_list
22
+
23
+ card = Pello::Inputs.choose_card source_list
24
+ next unless card
25
+
26
+ target_list = Pello::Inputs.choose_list board, list_name, 'Choose target list'
27
+ return unless target_list && target_list != source_list
28
+
29
+ puts "Moving card #{card.name} from \"#{source_list.name}\" to \"#{target_list.name}\""
30
+
31
+ if prompt.yes?('Confirm?')
32
+ card.list_id = target_list.id
33
+ card.save
34
+ logger.log user, card, "[#{Time.now}] #{card.extract_name} (#{source_list.name} -> #{target_list.name})"
35
+ puts('Done!')
36
+ else
37
+ puts 'Ok, bye!'
38
+ nil
39
+ end
40
+
41
+ continue = prompt.yes?('Another one?')
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -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
@@ -5,51 +5,28 @@ module Pello
5
5
  class Card
6
6
  extend Forwardable
7
7
 
8
- TITLE_REGEX = /(\(([0-9.]*)\))*\s*([0-9.]*)\s*🍅*\s*(.*)/.freeze
8
+ NAME_REGEX = /(\(([0-9.]*)\))*\s*([0-9.]*)\s*🍅*\s*(.*)/.freeze
9
9
  attr_accessor :trello_card
10
- def_delegators :@trello_card, :name, :name=, :comments, :add_comment, :save, :id
10
+ def_delegators :@trello_card, :name, :name=, :comments, :add_comment, :save, :id, :list_id, :list_id=
11
11
 
12
12
  def initialize(trello_card)
13
13
  @trello_card = trello_card
14
14
  end
15
15
 
16
16
  def extract_pomodori
17
- pomos = name.match(TITLE_REGEX)[3]
17
+ pomos = name.match(NAME_REGEX)[3]
18
18
  pomos ||= 0
19
19
  pomos.to_i
20
20
  end
21
21
 
22
- def extract_title
23
- name.match(TITLE_REGEX)[-1]
22
+ def extract_name
23
+ name.match(NAME_REGEX)[-1]
24
24
  end
25
25
 
26
26
  def extract_points
27
- points = name.match(TITLE_REGEX)[2]
27
+ points = name.match(NAME_REGEX)[2]
28
28
  points ||= 0
29
29
  points.to_f
30
30
  end
31
-
32
- def title_with_added_pomodori(how_many = 1)
33
- current_pomodori = extract_pomodori
34
- current_points = extract_points
35
- current_title = extract_title
36
- result = []
37
- result << "(#{current_points})" unless current_points.zero?
38
- result << "#{current_pomodori + how_many} 🍅"
39
- result << current_title
40
- result.join(' ')
41
- end
42
-
43
- def log(event)
44
- comment = comments.select { |c| c.data['text'] =~ /PELLO LOG/ }.first
45
- if comment
46
- new_text = [comment.data['text'], event].join("\n")
47
- comment.delete
48
- add_comment new_text
49
- else
50
- text = ['~~~PELLO LOG', event].join("\n")
51
- add_comment text
52
- end
53
- end
54
31
  end
55
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/config.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module Pello
2
2
  class Config
3
3
  CONFIG_FILE_PATH = "#{ENV['HOME']}/.config/pello/pello.yaml".freeze
4
- attr_accessor :board_url, :developer_public_key, :list_name, :log_file, :member_token, :username, :error
4
+ attr_accessor :board_url, :developer_public_key, :list_name, :member_token, :username, :error
5
5
 
6
6
  def initialize
7
7
  if File.exist?(CONFIG_FILE_PATH)
@@ -15,7 +15,6 @@ module Pello
15
15
  @username = pello_config['username']
16
16
  @board_url = pello_config['board_url']
17
17
  @list_name = pello_config['list_name']
18
- @log_file = pello_config['log_file']
19
18
  @error = false
20
19
  else
21
20
  @error = true
@@ -39,7 +38,6 @@ module Pello
39
38
  file.puts ' board_url: ""'
40
39
  file.puts ' username: ""'
41
40
  file.puts ' list_name: "In progress"'
42
- file.puts ' log_file: "/Users/your_name/.pello_log"'
43
41
  end
44
42
  end
45
43
  end
data/lib/pello/inputs.rb CHANGED
@@ -15,12 +15,12 @@ module Pello
15
15
  Pello::Board.new(user.boards.detect { |b| b.name == input })
16
16
  end
17
17
 
18
- def self.choose_list(board, list_name)
18
+ def self.choose_list(board, list_name, prompt_text = 'Choose list')
19
19
  prompt = TTY::Prompt.new
20
20
  list_names = board.lists.map(&:name)
21
21
  list_names << BACK_OPTION
22
22
  default_list = board.lists.select { |l| l.name == list_name }.first.try(:name)
23
- input = prompt.select('Choose list', list_names, per_page: 15, default: default_list)
23
+ input = prompt.select(prompt_text, list_names, per_page: 15, default: default_list)
24
24
  return nil if input == BACK_OPTION
25
25
 
26
26
  Pello::List.new(board.lists.detect { |l| l.name == input })
data/lib/pello/list.rb CHANGED
@@ -4,7 +4,7 @@ module Pello
4
4
  class List
5
5
  extend Forwardable
6
6
  attr_accessor :trello_list
7
- def_delegators :@trello_list, :cards
7
+ def_delegators :@trello_list, :cards, :name, :id
8
8
 
9
9
  def initialize(trello_list)
10
10
  @trello_list = trello_list
data/lib/pello/runner.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'yaml'
2
4
  require 'trello'
3
5
  require 'tty-prompt'
@@ -21,14 +23,21 @@ module Pello
21
23
  while continue
22
24
  case prompt.select('Choose task') do |menu|
23
25
  menu.choice name: 'Add pomodori', value: :add_pomodori
26
+ menu.choice name: 'Move card', value: :move_card
27
+ menu.choice name: 'Print board pomodori report', value: :report
24
28
  menu.choice name: 'Edit config', value: :edit_config
25
29
  menu.choice name: 'quit', value: :quit
26
30
  end
27
31
  when :add_pomodori
28
32
  add_pomodori_to_card
33
+ when :move_card
34
+ move_card
35
+ when :report
36
+ report
29
37
  when :edit_config
38
+ editor = ENV['EDITOR'] || 'vim'
30
39
  system 'mkdir -p ~/.config/pello'
31
- system "#{ENV['EDITOR']} ~/.config/pello/pello.yaml"
40
+ system "#{editor} ~/.config/pello/pello.yaml"
32
41
  when :quit
33
42
  puts 'Ok, bye!'
34
43
  exit
@@ -38,44 +47,16 @@ module Pello
38
47
 
39
48
  private
40
49
 
41
- def file_log(text)
42
- File.open(@log_file_path, 'a+') do |file|
43
- file.puts(text)
44
- end
45
- end
46
-
47
50
  def add_pomodori_to_card
48
- board = Pello::Inputs.choose_board @user, @board_url
49
- return unless board
50
-
51
- puts board.as_table
52
- continue = true
53
- while continue
54
- list = Pello::Inputs.choose_list board, @list_name
55
- return unless list
56
-
57
- card = Pello::Inputs.choose_card list
58
- next unless card
59
-
60
- pomodori_before = card.extract_pomodori
61
- pomodori_to_add = prompt.ask('Pomodori', default: 1)
62
-
63
- puts "Updating card #{card.name}"
64
- puts "New title: #{card.title_with_added_pomodori(pomodori_to_add.to_i)}"
51
+ Pello::Actions::AddPomodoriToCard.new(prompt).run(@user, board_url, list_name)
52
+ end
65
53
 
66
- if prompt.yes?('Confirm?')
67
- card.name = card.title_with_added_pomodori(pomodori_to_add.to_i)
68
- card.save
69
- file_log "[#{Time.now} - #{@user.full_name}] #{card.extract_title} (#{pomodori_before} -> #{card.extract_pomodori})"
70
- card.log "[#{Time.now} - #{@user.full_name}] #{card.extract_title} (#{pomodori_before} -> #{card.extract_pomodori})"
71
- puts('Done!')
72
- else
73
- puts 'Ok, bye!'
74
- nil
75
- end
54
+ def move_card
55
+ Pello::Actions::MoveCard.new(prompt).run(@user, board_url, list_name)
56
+ end
76
57
 
77
- continue = prompt.yes?('Another one?')
78
- end
58
+ def report
59
+ Pello::Actions::Report.new.run(@user, board_url)
79
60
  end
80
61
 
81
62
  def configure_pello
@@ -89,7 +70,6 @@ module Pello
89
70
  @user = Trello::Member.find config.username
90
71
  @board_url = config.board_url
91
72
  @list_name = config.list_name
92
- @log_file_path = config.log_file
93
73
  else
94
74
  puts 'No config found, opening config file...'
95
75
  Pello::Config.write_empty_config
data/lib/pello/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Pello
2
- VERSION = "0.1.1"
2
+ VERSION = "0.4"
3
3
  end
data/lib/pello.rb CHANGED
@@ -4,6 +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'
8
+ require 'pello/actions/add_pomodori_to_card'
9
+ require 'pello/actions/move_card'
10
+ require 'pello/actions/report'
7
11
  require 'pello/config'
8
12
 
9
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.1.1
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: 2021-12-20 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
@@ -52,7 +52,8 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- description: Perform Trello operations like adding pomodori to a card title
55
+ description: Perform Trello operations like adding pomodori to a card name and moving
56
+ cards across lists
56
57
  email:
57
58
  - metalelf0@gmail.com
58
59
  executables:
@@ -62,8 +63,12 @@ extra_rdoc_files: []
62
63
  files:
63
64
  - bin/pello
64
65
  - lib/pello.rb
66
+ - lib/pello/actions/add_pomodori_to_card.rb
67
+ - lib/pello/actions/move_card.rb
68
+ - lib/pello/actions/report.rb
65
69
  - lib/pello/board.rb
66
70
  - lib/pello/card.rb
71
+ - lib/pello/card_logger.rb
67
72
  - lib/pello/config.rb
68
73
  - lib/pello/inputs.rb
69
74
  - lib/pello/list.rb