fewald-worklog 0.3.12 → 0.3.14
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 +4 -4
- data/.version +1 -1
- data/lib/cli.rb +1 -0
- data/lib/github/repository.rb +33 -0
- data/lib/project.rb +43 -7
- data/lib/project_storage.rb +3 -0
- data/lib/worklog.rb +4 -8
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ab7a9c5136dd285ee57cfe1331f6890c244bd99ec989e0c6a48ff19f57c8a0b0
|
|
4
|
+
data.tar.gz: 7b5fb34ba1ef5dfe6292b0eccf85b3148f0e7de3d2d6406f3d19e5f5633fca50
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 46d5f939c05647cc241c084528b9508fb4abac538484e65576d53558a81bcd4efb6229ea8efb86654d4f2ecb8eb472bb75eba73c045a9a38edd45892eae9adaf
|
|
7
|
+
data.tar.gz: 1244216988115f3c18d8fffadb19b1908f5e95e2d4eebfc7bd942b1bb009ea79415e9e11e16900174d7b03bf764926687fb760eea4c67931138d6055cdc65fee
|
data/.version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.3.
|
|
1
|
+
0.3.14
|
data/lib/cli.rb
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Worklog
|
|
4
|
+
# Functions related to Github repositories
|
|
5
|
+
module Github
|
|
6
|
+
# Represents a GitHub repository with an owner and name.
|
|
7
|
+
Repository = Struct.new(:owner, :name, keyword_init: true) do
|
|
8
|
+
# Extracts the repository name and owner from a GitHub repository URL.
|
|
9
|
+
# @param url [String] The GitHub repository URL or owner/repository string.
|
|
10
|
+
# @return [Hash, nil] A hash with :owner and :repository keys, or nil if the URL is invalid.
|
|
11
|
+
# @example
|
|
12
|
+
# repo = Worklog::Github::Repository.new
|
|
13
|
+
# repo.repository_from_url('https://github.com/owner/repository')
|
|
14
|
+
# # => <# owner: 'owner', repository: 'repository' }
|
|
15
|
+
# @example
|
|
16
|
+
# repo.repository_from_url('owner/repository')
|
|
17
|
+
# # => #<struct Worklog::Github::Repository owner="owner", name="repository">
|
|
18
|
+
def self.from_url(url)
|
|
19
|
+
match = url.match(%r{github\.com[:/](?<owner>[^/]+)/(?<repo>[^/]+)(?:\.git)?$})
|
|
20
|
+
match = url.match(%r{^(?<owner>[^/]+)/(?<repo>[^/]+)$}) if match.nil?
|
|
21
|
+
return nil if match.nil?
|
|
22
|
+
|
|
23
|
+
Repository.new(owner: match[:owner], name: match[:repo])
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Returns a string representation of the repository in the format "owner/name".
|
|
27
|
+
# @return [String] The string representation of the repository.
|
|
28
|
+
def to_s
|
|
29
|
+
"#{owner}/#{name}"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/project.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'github/repository'
|
|
4
|
+
|
|
3
5
|
module Worklog
|
|
4
6
|
# Represents a project. A project is a longer running task or initiative.
|
|
5
7
|
# Single log entries can be associated with a project.
|
|
@@ -17,6 +19,10 @@ module Worklog
|
|
|
17
19
|
# @return [String, nil] The status of the project, can be nil
|
|
18
20
|
# Possible values: 'active', 'completed', 'archived', etc.
|
|
19
21
|
# Indicates the current state of the project.
|
|
22
|
+
# @!attribute [rw] repositories
|
|
23
|
+
# @return [Array<String>] An array of repository URLs associated with the project.
|
|
24
|
+
# These repositories are used for linking the Github commits to the project.
|
|
25
|
+
# At the moment, only Github repositories are supported.
|
|
20
26
|
# @!attribute [rw] entries
|
|
21
27
|
# These entries are related to the work done on this project.
|
|
22
28
|
# Entries are populated dynamically when processing daily logs.
|
|
@@ -28,7 +34,7 @@ module Worklog
|
|
|
28
34
|
# It represents the most recent log entry time for this project.
|
|
29
35
|
# @return [Date, nil] The last activity date or nil if not set.
|
|
30
36
|
class Project
|
|
31
|
-
attr_accessor :key, :name, :description, :start_date, :end_date, :status, :entries, :last_activity
|
|
37
|
+
attr_accessor :key, :name, :description, :start_date, :end_date, :status, :repositories, :entries, :last_activity
|
|
32
38
|
|
|
33
39
|
# Creates a new Project instance from a hash of attributes.
|
|
34
40
|
# @param hash [Hash] A hash containing project attributes
|
|
@@ -41,15 +47,23 @@ module Worklog
|
|
|
41
47
|
# @return [Project] A new Project instance
|
|
42
48
|
def self.from_hash(hash)
|
|
43
49
|
project = new
|
|
50
|
+
|
|
51
|
+
# Protect against nil hash
|
|
52
|
+
raise ArgumentError, 'Project hash cannot be nil' if hash.nil?
|
|
53
|
+
|
|
44
54
|
# Ensure that at least the key is present
|
|
45
55
|
raise ArgumentError, 'Project key is required' unless hash[:key] || hash['key']
|
|
46
56
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
project.
|
|
57
|
+
hash.each do |key, value|
|
|
58
|
+
instance_var = "@#{key}"
|
|
59
|
+
project.instance_variable_set(instance_var, value) if project.respond_to?("#{key}=")
|
|
60
|
+
end
|
|
61
|
+
# Set default values for repositories if not provided
|
|
62
|
+
project.repositories ||= []
|
|
63
|
+
project.repositories.map! do |repo|
|
|
64
|
+
Github::Repository.from_url(repo)
|
|
65
|
+
end
|
|
66
|
+
|
|
53
67
|
project
|
|
54
68
|
end
|
|
55
69
|
|
|
@@ -68,6 +82,28 @@ module Worklog
|
|
|
68
82
|
!end_date.nil? && end_date < Date.today
|
|
69
83
|
end
|
|
70
84
|
|
|
85
|
+
# Returns true if the project contains the given repository URL.
|
|
86
|
+
# @param repository [Worklog::Github::Repository] The repository to check
|
|
87
|
+
# @return [Boolean] true if the project contains the repository URL, false otherwise
|
|
88
|
+
def contains_repository?(repository)
|
|
89
|
+
repositories.include? repository
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Returns a string with project metadata.
|
|
93
|
+
# @return [String] A string containing project metadata.
|
|
94
|
+
def project_metadata
|
|
95
|
+
m = String.new
|
|
96
|
+
m << "#{Rainbow(name).gold} (#{key})\n"
|
|
97
|
+
m << " Description: #{description}\n" if description
|
|
98
|
+
m << " Start date: #{start_date.strftime('%b %d, %Y')}\n" if start_date
|
|
99
|
+
m << " End date: #{end_date.strftime('%b %d, %Y')}\n" if end_date
|
|
100
|
+
m << " Status: #{status}\n" if status
|
|
101
|
+
m << " Repositories: #{repositories.map(&:to_s).join(', ')}\n" unless repositories.empty?
|
|
102
|
+
m << " Last activity: #{last_activity.strftime('%b %d, %Y')}\n" if last_activity
|
|
103
|
+
m << " #{activity_graph}"
|
|
104
|
+
m
|
|
105
|
+
end
|
|
106
|
+
|
|
71
107
|
# Generate an ASCII activity graph for the project.
|
|
72
108
|
# The graph shows activity over time, with each character representing a day.
|
|
73
109
|
# More active days are represented with a different character.
|
data/lib/project_storage.rb
CHANGED
data/lib/worklog.rb
CHANGED
|
@@ -304,18 +304,14 @@ module Worklog
|
|
|
304
304
|
# Sort entries by descending time
|
|
305
305
|
project.entries.sort_by!(&:time).reverse!
|
|
306
306
|
|
|
307
|
-
|
|
308
|
-
puts
|
|
309
|
-
puts " Start date: #{project.start_date.strftime('%b %d, %Y')}" if project.start_date
|
|
310
|
-
puts " End date: #{project.end_date.strftime('%b %d, %Y')}" if project.end_date
|
|
311
|
-
puts " Status: #{project.status}" if project.status
|
|
312
|
-
puts " Last activity: #{project.last_activity.strftime('%b %d, %Y')}" if project.last_activity
|
|
313
|
-
puts " #{project.activity_graph}"
|
|
307
|
+
# Print project details/metadata
|
|
308
|
+
puts project.project_metadata
|
|
314
309
|
|
|
310
|
+
# TODO: Refactor into project metadata
|
|
315
311
|
next unless project.entries && !project.entries.empty?
|
|
316
312
|
|
|
317
313
|
puts " Last #{[project.entries&.size, 3].min} entries:"
|
|
318
|
-
puts " #{project.entries.
|
|
314
|
+
puts " #{project.entries.first(3).map do |e|
|
|
319
315
|
"#{e.time.strftime('%b %d, %Y')} #{e.message_string(@people)}"
|
|
320
316
|
end.join("\n ")}"
|
|
321
317
|
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.3.
|
|
4
|
+
version: 0.3.14
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Friedrich Ewald
|
|
@@ -146,6 +146,7 @@ files:
|
|
|
146
146
|
- lib/github/pull_request_event.rb
|
|
147
147
|
- lib/github/pull_request_review_event.rb
|
|
148
148
|
- lib/github/push_event.rb
|
|
149
|
+
- lib/github/repository.rb
|
|
149
150
|
- lib/hash.rb
|
|
150
151
|
- lib/hasher.rb
|
|
151
152
|
- lib/log_entry.rb
|