fewald-worklog 0.2.31 → 0.2.33

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: 1448a0024e80bc4c30592f79384dad240264fe601595f760e6cfd9d239bc3fcf
4
- data.tar.gz: 8ac2ece9829a3bce2d6713a2c99fed746142511af900f7ad4129d62289982496
3
+ metadata.gz: c28fcf1980d7fba6dbe1585ef1ae6d41520329470c4289f427dc8feb689c4cba
4
+ data.tar.gz: d6db27c34cd1288d19042579426a947b96fa5ca30f7fd7a88887ee220f2adc16
5
5
  SHA512:
6
- metadata.gz: 0a0c67bfa31766e1e56c5f7a45c9efff5dabbf177f03d1a358054079966228d68b3d0ba37bb19acca8d1d7540f2b89709b1fc03f21d3dac29266bd15b8238f2f
7
- data.tar.gz: f664b7b885a37b5c4659e0484b37fb85c3ebba5e81b4ef565d0522e3f8ff925816cd220baba0b3a3b617ceec1db5c65d181fd8597e92d0d9b0d782188cc6dc77
6
+ metadata.gz: 4116746f5d7df43bfb7764a68c36dfc19d9ed3ccee6c8f1965306db4ffde3e1a7c56608293fc6d8b0c30810149ef0cdbfd83bb9881fb05d84feb0b368079883c
7
+ data.tar.gz: 0ec8ef405b87a6e07c9ca6a4c0191de9fc0c5fbc19bbd30656e332d9a6489db90fa8ae81532c481c9c3a4169fed3d5f9679a7d9cee4e9f5ee07a3af6d3ebc9d6
data/.version CHANGED
@@ -1 +1 @@
1
- 0.2.31
1
+ 0.2.33
data/lib/cli.rb CHANGED
@@ -49,7 +49,9 @@ class WorklogCLI < Thor
49
49
  an alphanumeric string.
50
50
  LONGDESC
51
51
  option :date, type: :string, default: DateTime.now.strftime('%Y-%m-%d'), desc: 'Set the date of the entry'
52
- option :time, type: :string, default: DateTime.now.strftime('%H:%M:%S'), desc: 'Set the time of the entry'
52
+ option :time, type: :string, default: DateTime.now.strftime('%H:%M:%S'), desc: <<~DESC
53
+ Set the time of the entry. Can be provided in HHMM, HH:MM, or HH:MM:SS format.
54
+ DESC
53
55
  option :tags, type: :array, default: [], desc: 'Add tags to the entry'
54
56
  option :ticket, type: :string, desc: 'Ticket number associated with the entry. Can be any alphanumeric string.'
55
57
  option :url, type: :string, desc: 'URL to associate with the entry'
data/lib/daily_log.rb CHANGED
@@ -13,7 +13,7 @@ module Worklog
13
13
 
14
14
  def initialize(params = {})
15
15
  @date = params[:date]
16
- @entries = params[:entries]
16
+ @entries = params[:entries] || []
17
17
  end
18
18
 
19
19
  # Returns true if there are people mentioned in any entry of the current day.
data/lib/log_entry.rb CHANGED
@@ -8,6 +8,8 @@ require 'hash'
8
8
  module Worklog
9
9
  # A single log entry in a DailyLog.
10
10
  # @see DailyLog
11
+ # @!attribute [rw] key
12
+ # @return [String] the unique key of the log entry. The key is generated based on the time and message.
11
13
  # @!attribute [rw] time
12
14
  # @return [DateTime] the date and time of the log entry.
13
15
  # @!attribute [rw] tags
@@ -27,11 +29,13 @@ module Worklog
27
29
 
28
30
  include Hashify
29
31
 
30
- attr_accessor :time, :tags, :ticket, :url, :epic, :message, :project
32
+ attr_accessor :key, :time, :tags, :ticket, :url, :epic, :message, :project
31
33
 
32
34
  attr_reader :day
33
35
 
34
36
  def initialize(params = {})
37
+ # key can be nil. This is needed for backwards compatibility with older log entries.
38
+ @key = params[:key]
35
39
  @time = params[:time]
36
40
  # If tags are nil, set to empty array.
37
41
  # This is similar to the CLI default value.
@@ -105,19 +109,12 @@ module Worklog
105
109
  end
106
110
 
107
111
  # Create a LogEntry from a hash with symbolized keys
112
+ # This is an alias for the constructor and here for consistency with other classes.
108
113
  #
109
114
  # @param hash [Hash] the hash to convert
110
115
  # @return [LogEntry] the created LogEntry object
111
116
  def self.from_hash(hash)
112
- new(
113
- time: hash[:time],
114
- tags: hash[:tags],
115
- ticket: hash[:ticket],
116
- url: hash[:url],
117
- epic: hash[:epic],
118
- message: hash[:message],
119
- project: hash[:project]
120
- )
117
+ new(**hash)
121
118
  end
122
119
 
123
120
  # Convert the log entry to YAML format.
data/lib/worklog.rb CHANGED
@@ -6,6 +6,7 @@ require 'rainbow'
6
6
  require 'yaml'
7
7
 
8
8
  require 'configuration'
9
+ require 'digest'
9
10
  require 'hash'
10
11
  require 'daily_log'
11
12
  require 'date_parser'
@@ -80,16 +81,17 @@ module Worklog
80
81
  date = Date.strptime(options[:date], '%Y-%m-%d')
81
82
 
82
83
  # Append seconds to time if not provided
83
- time = options[:time]
84
- time += ':00' if options[:time].split(':').size == 2
85
- time = Time.strptime(time, '%H:%M:%S')
84
+ time = parse_time_string!(options[:time])
86
85
  @storage.create_file_skeleton(date)
87
86
 
88
87
  # Validate that the project exists if provided
89
88
  validate_projects!(options[:project]) if options[:project] && !options[:project].empty?
90
89
 
90
+ # Use the first 7 characters of the SHA256 hash of message as the key
91
+ key = Digest::SHA256.hexdigest(message)[..6]
92
+
91
93
  daily_log = @storage.load_log!(@storage.filepath(date))
92
- new_entry = LogEntry.new(time:, tags: options[:tags], ticket: options[:ticket], url: options[:url],
94
+ new_entry = LogEntry.new(key:, time:, tags: options[:tags], ticket: options[:ticket], url: options[:url],
93
95
  epic: options[:epic], message:, project: options[:project])
94
96
  daily_log.entries << new_entry
95
97
 
@@ -465,5 +467,27 @@ module Worklog
465
467
 
466
468
  raise ProjectNotFoundError, "Project with key '#{project_key}' does not exist."
467
469
  end
470
+
471
+ # Parse a time string in HHMM, HH:MM, or HH:MM:SS format.
472
+ # @param time_string [String] the time string to parse
473
+ # @return [Time] the parsed Time object
474
+ def parse_time_string!(time_string)
475
+ # Validate the time string format
476
+ unless time_string.match?(/^\d{1,2}:?\d{2}:?\d{2}?$/)
477
+ raise ArgumentError, 'Invalid time format. Expected HHMM, HH:MM, or HH:MM:SS.'
478
+ end
479
+
480
+ # Prefix with 0 if needed
481
+ time_string = "0#{time_string}" if time_string.length == 3
482
+
483
+ # Split hours and minutes if in HHMM format
484
+ if time_string.length == 4 && time_string.match?(/^\d{4}$/)
485
+ time_string = "#{time_string[0..1]}:#{time_string[2..3]}"
486
+ end
487
+
488
+ # Append seconds to time if not provided
489
+ time_string += ':00' if time_string.split(':').size == 2
490
+ Time.strptime(time_string, '%H:%M:%S')
491
+ end
468
492
  end
469
493
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fewald-worklog
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.31
4
+ version: 0.2.33
5
5
  platform: ruby
6
6
  authors:
7
7
  - Friedrich Ewald