fewald-worklog 0.3.5 → 0.3.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4b6b051e9dd15f4588ddcff4a3f23686077c3b6fa8c8fda053cd6187a91a34c
4
- data.tar.gz: 7a3b6ff79f314e30016776efed9fbe2a76b68e46658c4658185577f27a7cf3bf
3
+ metadata.gz: e2554331b36043db6a3386effbe1c243c99c97bbceae33b4faa4fcbdf8242101
4
+ data.tar.gz: 8497987c745fad61def23bb27eb02a2c1785cd988bdcc21598cf13d8a0fa01b5
5
5
  SHA512:
6
- metadata.gz: 23c300fa90069057589a947ff9da63db056f28bc7021ba7a9a19cfd28dbf424ed1ada21a24a76cd29b72f1810a7f7c14bdd9c4547b84e330ef96e99b1dbfd640
7
- data.tar.gz: 627e537ca0e1530d64bf7b4a1c78709f9910bcec382ed8c1dba43d7a0c35bc32f1488f45490d8432d5aae0cf4db1e8692982a46416821b8afe7bf8108738f58f
6
+ metadata.gz: d40bccfd27b7da9e638259a5eec07d3cb5f7c898fc9692eee088dfe93a5abeb39023a617434f784ff9a4a6047ba4a9acd2c5db672c82d4006180c4b1663636cc
7
+ data.tar.gz: 8cb2393190a637bdff6cb4147d8296f71fae468103dee080778c17035d1438c23db5b3e8cee8a79533029f8acb784690da1deb5f24a6d548406457ab6f2b9f6e
data/.version CHANGED
@@ -1 +1 @@
1
- 0.3.5
1
+ 0.3.6
data/lib/cli.rb CHANGED
@@ -77,6 +77,12 @@ class WorklogCLI < Thor
77
77
  worklog.github(options)
78
78
  end
79
79
 
80
+ desc 'init', 'Initialize the work log storage and configuration in the home directory'
81
+ def init
82
+ worklog = Worklog::Worklog.new
83
+ worklog.init(options)
84
+ end
85
+
80
86
  desc 'remove', 'Remove last entry from the log'
81
87
  option :date, type: :string, default: Time.now.strftime('%Y-%m-%d')
82
88
  def remove
data/lib/configuration.rb CHANGED
@@ -72,6 +72,27 @@ module Worklog
72
72
  end
73
73
  end
74
74
 
75
+ CONFIGURATION_TEMPLATE = ERB.new <<~YAML
76
+ # Worklog Configuration File
77
+ # This file contains configuration settings for Worklog.
78
+ # You can modify the values below to customize your setup.
79
+ # For more information, refer to the documentation.
80
+ storage_path: <%= Dir.home %>/.worklog
81
+ log_level: info
82
+ timezone: 'America/Los_Angeles'
83
+ webserver_port: 3000
84
+
85
+ project:
86
+ # Number of last projects to show in the project list
87
+ show_last: 3
88
+
89
+ github:
90
+ # Your GitHub API key for accessing the GitHub API
91
+ api_key: ""
92
+ # Your GitHub username for finding assigned issues and PRs
93
+ username: ""
94
+ YAML
95
+
75
96
  # Initialize configuration with optional block for setting attributes.
76
97
  # If no block is given, default values are used.
77
98
  # @example
@@ -98,7 +119,7 @@ module Worklog
98
119
  # If the file does not exist, it will use default values.
99
120
  # @return [Configuration] the loaded configuration
100
121
  def self.load
101
- file_path = File.join(Dir.home, '.worklog.yaml')
122
+ file_path = config_file_path
102
123
  config = Configuration.new
103
124
  if File.exist?(file_path)
104
125
  file_cfg = YAML.load_file(file_path)
@@ -126,5 +147,11 @@ module Worklog
126
147
  def default_storage_path?
127
148
  @storage_path == File.join(Dir.home, '.worklog')
128
149
  end
150
+
151
+ # Get the default configuration file path.
152
+ # @return [String] the default configuration file path
153
+ def self.config_file_path
154
+ File.join(Dir.home, '.worklog.yaml')
155
+ end
129
156
  end
130
157
  end
@@ -41,6 +41,9 @@ module Worklog
41
41
  @configuration = configuration
42
42
  end
43
43
 
44
+ # Returns all loaded projects.
45
+ # If the projects are not already loaded, it loads them from disk.
46
+ # @return [Hash<String, Project>] A hash of project objects keyed by their unique project keys.
44
47
  def projects
45
48
  @projects ||= load_projects
46
49
  end
data/lib/storage.rb CHANGED
@@ -17,6 +17,21 @@ module Worklog
17
17
  # Regular expression to match daily log file names
18
18
  LOG_PATTERN = /\d{4}-\d{2}-\d{2}#{FILE_SUFFIX}\z/
19
19
 
20
+ # The template for the people YAML file.
21
+ # This template is used to create a new people file if it does not exist.
22
+ PERSON_TEMPLATE = <<~YAML
23
+ ---
24
+ # Each person is defined by the following attributes:
25
+ # - handle: <unique_handle>
26
+ # github_username: <github_username>
27
+ # name: <full_name>
28
+ # team: <team_name>
29
+ # email: <email_address>
30
+ # role: <role_in_team>
31
+ # inactive: <true_or_false>
32
+ # --- Define your people below this line ---
33
+ YAML
34
+
20
35
  def initialize(config)
21
36
  @config = config
22
37
  end
@@ -157,14 +172,13 @@ module Worklog
157
172
  # Load all people from the people file
158
173
  # @return [Array<Person>] List of people
159
174
  def load_people!
160
- people_file = File.join(@config.storage_path, 'people.yaml')
161
- return [] unless File.exist?(people_file)
175
+ return [] unless File.exist?(people_filepath)
162
176
 
163
- yamltext = File.read(people_file)
177
+ yamltext = File.read(people_filepath)
164
178
  if yamltext != yamltext.gsub(/^- !.*$/, '-')
165
179
  WorkLogger.debug 'The people.yaml file contains deprecated syntax. Migrating now.'
166
180
  yamltext.gsub!(/^- !.*$/, '-')
167
- File.write(people_file, yamltext)
181
+ File.write(people_filepath, yamltext)
168
182
  end
169
183
  YAML.load(yamltext, permitted_classes: []).map { |person_hash| Person.from_hash(person_hash) }
170
184
  end
@@ -172,25 +186,59 @@ module Worklog
172
186
  # Write people to the people file
173
187
  # @param [Array<Person>] people List of people
174
188
  def write_people!(people)
175
- people_file = File.join(@config.storage_path, 'people.yaml')
176
- File.open(people_file, 'w') do |f|
189
+ File.open(people_filepath, 'w') do |f|
177
190
  f.puts people.to_yaml
178
191
  end
179
192
  end
180
193
 
181
194
  # Create folder if not exists already.
195
+ # @return [void]
182
196
  def create_default_folder
197
+ WorkLogger.debug 'Creating storage folder if it does not exist.'
198
+
183
199
  # Do nothing if the storage path is not the default path
184
- return unless @config.default_storage_path?
200
+ unless @config.default_storage_path?
201
+ WorkLogger.debug 'Custom storage path detected, skipping creation of default storage folder.'
202
+ return
203
+ end
185
204
 
186
205
  Dir.mkdir(@config.storage_path) unless Dir.exist?(@config.storage_path)
187
206
  end
188
207
 
208
+ # This method assumes that the storage folder already exists.
209
+ # It creates default files like people.yaml if they do not exist.
210
+ def create_default_files
211
+ WorkLogger.info 'Creating default files in storage folder if they do not exist.'
212
+ # projects_file = File.join(@config.storage_path, 'projects.yaml')
213
+ # unless File.exist?(projects_file)
214
+ # File.write(projects_file, [].to_yaml)
215
+ # end
216
+
217
+ if File.exist?(people_filepath)
218
+ WorkLogger.info 'people.yaml already exists, skipping creation.'
219
+ else
220
+ WorkLogger.info 'Creating default people.yaml file.'
221
+ File.write(people_filepath, PERSON_TEMPLATE)
222
+ end
223
+
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)
229
+ end
230
+
189
231
  # Construct filepath for a given date.
190
232
  # @param [Date] date The date
191
233
  # @return [String] The filepath
192
234
  def filepath(date)
193
235
  File.join(@config.storage_path, "#{date}#{FILE_SUFFIX}")
194
236
  end
237
+
238
+ # Return the full absolute filepath for the people.yaml file
239
+ # @return [String] The filepath
240
+ def people_filepath
241
+ File.join(@config.storage_path, 'people.yaml')
242
+ end
195
243
  end
196
244
  end
data/lib/worklog.rb CHANGED
@@ -24,7 +24,7 @@ require 'takeout'
24
24
  module Worklog
25
25
  # Main class providing all worklog functionality.
26
26
  # This class is the main entry point for the application.
27
- # It handles command line arguments, configuration, and logging.
27
+ # It handles configuration, data storage, and logging.
28
28
  # @!attribute [r] config
29
29
  # @return [Configuration] The configuration object containing settings for the application.
30
30
  # @!attribute [r] storage
@@ -40,7 +40,9 @@ module Worklog
40
40
  # date: '2023-10-01',
41
41
  # time: '10:00:00',
42
42
  # tags: ['feature', 'x'],
43
- # ticket: 'TICKET-123')
43
+ # ticket: 'TICKET-123',
44
+ # epic: true,
45
+ # project: 'my_project')
44
46
  class Worklog
45
47
  include StringHelper
46
48
 
@@ -50,11 +52,13 @@ module Worklog
50
52
  # Load or use provided configuration
51
53
  @config = config || Configuration.load
52
54
 
53
- # Initialize storage
54
- @storage = Storage.new(@config)
55
-
55
+ # Set log level based on configuration
56
56
  WorkLogger.level = @config.log_level == :debug ? Logger::Severity::DEBUG : Logger::Severity::INFO
57
57
 
58
+ # Initialize (project) storage
59
+ @storage = Storage.new(@config)
60
+ @project_storage = ProjectStorage.new(@config)
61
+
58
62
  bootstrap
59
63
  end
60
64
 
@@ -64,6 +68,9 @@ module Worklog
64
68
 
65
69
  # Load all people as they're used in multiple/most of the methods.
66
70
  @people = @storage.load_people_hash
71
+
72
+ # Load all projects from disk
73
+ @projects = @project_storage.load_projects
67
74
  end
68
75
 
69
76
  # Add new entry to the work log.
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.5
4
+ version: 0.3.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Friedrich Ewald