fewald-worklog 0.3.7 → 0.3.8

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 (5) hide show
  1. checksums.yaml +4 -4
  2. data/.version +1 -1
  3. data/lib/storage.rb +7 -4
  4. data/lib/worklog.rb +37 -0
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 403f517a4187813057f08fa0152df86fdbcc29271a6881650c9de260b1026283
4
- data.tar.gz: 8a6fc79840438dc25323ffa4b7a172919be95982783259658dfbdccf90286449
3
+ metadata.gz: 7eebce5b88e954faa6242724ed451878b495285aa11757e40361ad430d45e5d5
4
+ data.tar.gz: 683dd70aff93d5a0731bf56472d7ed55c5a62dfb71aba141b6534da100c90c6d
5
5
  SHA512:
6
- metadata.gz: 1a4e9fd85a1b1c80a8432763706a06b5496fc8160dac7a1bd07f487ded8cd250040d0cd8442e72c78de570ec29bfac6fdb7eab6168817e0af3bb9f4c4b682ade
7
- data.tar.gz: 7a36f2c3dbe92fc4543a359d4736a80078b2a5f80a544df354d60df684c14036ed44782d342a7ac25d51ea300688cf0098ca25eef9b8729fb5892081168cb567
6
+ metadata.gz: 9fda2165e1a06fe4df84eaa3c7d7396bcdf8f0fa14468bbadf89632c35cce0ba425e9b80fab2844fa07c8a65f18330d29593d142c5b8695e1976bb6b343f3e0f
7
+ data.tar.gz: 217d4319ee3dd036000c4b14c9fc9a413e3920391d4b538a786db2239107bf46e56832fe23161416940fe0f98a086676b5cb25d2edb23e4978b9b33b3f8807c9
data/.version CHANGED
@@ -1 +1 @@
1
- 0.3.7
1
+ 0.3.8
data/lib/storage.rb CHANGED
@@ -222,10 +222,13 @@ module Worklog
222
222
  end
223
223
 
224
224
  # Write the default config file if it does not exist
225
- return if File.exist?(Configuration.config_file_path)
226
-
227
- File.write(Configuration.config_file_path,
228
- Configuration::CONFIGURATION_TEMPLATE.result)
225
+ if File.exist?(Configuration.config_file_path)
226
+ WorkLogger.info "Configuration file (#{Configuration.config_file_path}) already exists, skipping creation."
227
+ else
228
+ WorkLogger.info "Creating default configuration file at #{Configuration.config_file_path}."
229
+ File.write(Configuration.config_file_path,
230
+ Configuration::CONFIGURATION_TEMPLATE.result)
231
+ end
229
232
  end
230
233
 
231
234
  # Construct filepath for a given date.
data/lib/worklog.rb CHANGED
@@ -134,6 +134,43 @@ module Worklog
134
134
  WorkLogger.info Rainbow("Updated work log for #{options[:date]}").green
135
135
  end
136
136
 
137
+ # Fetch latest events from GitHub for a specified user and add them to the work log.
138
+ #
139
+ # @param options [Hash] the options hash containing GitHub username and other parameters.
140
+ def github(_options = {})
141
+ github = Github::Client.new(@config)
142
+ github_events = github.fetch_events
143
+
144
+ WorkLogger.info Rainbow("Fetched #{github_events.size} events from GitHub.").green
145
+
146
+ events_by_date = github_events.group_by { |event| event.to_log_entry.time.to_date }
147
+
148
+ events_by_date.each do |date, events|
149
+ WorkLogger.info Rainbow("Found #{events.size} events for #{date}").green
150
+ puts "Processing #{events.size} events for '#{date}'"
151
+ @storage.create_file_skeleton(date)
152
+ daily_log = @storage.load_log!(@storage.filepath(date))
153
+ entries_before = daily_log.entries.size
154
+ events.each do |event|
155
+ log_entry = event.to_log_entry
156
+ WorkLogger.debug('Entry already exists, skipping') if daily_log.key?(log_entry.key)
157
+ daily_log << log_entry unless daily_log.key?(log_entry.key)
158
+ WorkLogger.debug "Added entry: #{log_entry.message_string}"
159
+ end
160
+ entries_after = daily_log.entries.size
161
+ WorkLogger.info Rainbow("Added #{entries_after - entries_before} new entries for #{date}").green
162
+
163
+ # Write log back to storage
164
+ @storage.write_log(@storage.filepath(date), daily_log)
165
+ end
166
+ end
167
+
168
+ # Initialize the work log storage with default files and folders.
169
+ # This method will not overwrite existing files and is thus safe to run multiple times.
170
+ def init(_options = {})
171
+ @storage.create_default_files
172
+ end
173
+
137
174
  # Show the work log for a specific date range or a single date.
138
175
  #
139
176
  # @param options [Hash] the options hash containing date range or single date.
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.3.7
4
+ version: 0.3.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Friedrich Ewald