obst 0.1.6 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -0
- data/exe/obst +9 -2
- data/lib/obst/chart.rb +4 -2
- data/lib/obst/config.rb +27 -0
- data/lib/obst/git_log.rb +4 -0
- data/lib/obst/last_seen.rb +28 -0
- data/lib/obst/long_time_no_see.rb +34 -0
- data/lib/obst/pack_log.rb +22 -0
- data/lib/obst/touched_files.rb +11 -20
- data/lib/obst/version.rb +1 -1
- data/lib/obst.rb +2 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33dbda872356a5eaec6905a2054093af4a49555183ad517160a8bcb27f0b7ddd
|
4
|
+
data.tar.gz: 77d38fa97ae8e8319b05f85c3106e3fda15a7c14bb3b737a9ecae874c0a81599
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e22696c10025df791b9d11e4b6dac10e3deb965d093bb1b511d8d12cfa22019dee5f8794f0f129da60be3782ed7585afc585880f1dbd5ec49ae5f175cb03cf4d
|
7
|
+
data.tar.gz: 85721a438531b6028efc7f1680e47a9be127fe199196371cf8459cfd95091bbe1e6d957f39048574575b98a6b826d9cdd09a26e4c4f5cfb0c1b2341fe0d4ab6e
|
data/README.md
CHANGED
@@ -38,6 +38,21 @@ Group by Days
|
|
38
38
|
Obst::GroupByDays.new(C: '/path/to/local/git/repo', after: '2022-10-20T00:00:00', days: 7)
|
39
39
|
```
|
40
40
|
|
41
|
+
## Config
|
42
|
+
|
43
|
+
Place .obst.json under dir where you run obst. Content for example:
|
44
|
+
|
45
|
+
```json
|
46
|
+
{
|
47
|
+
// for all stats
|
48
|
+
"pathspec": [":!.obsidian", ":!calendar"],
|
49
|
+
// for specific stats
|
50
|
+
"long_time_no_see": {
|
51
|
+
"pathspec": [":!.obsidian", ":!calendar"]
|
52
|
+
}
|
53
|
+
}
|
54
|
+
```
|
55
|
+
|
41
56
|
## Development
|
42
57
|
|
43
58
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/exe/obst
CHANGED
@@ -4,16 +4,23 @@ require "obst"
|
|
4
4
|
|
5
5
|
path = ARGV[0] || '.'
|
6
6
|
|
7
|
+
# setup .gitignore
|
7
8
|
gitignore = File.join(path, '.gitignore')
|
8
9
|
File.open(gitignore, 'a+') do |f|
|
9
10
|
f.puts("# Obst\nobst.md") unless f.read =~ /# Obst/
|
10
11
|
end
|
11
12
|
|
13
|
+
# read config
|
14
|
+
cfg = Obst::Config.new(path)
|
15
|
+
|
16
|
+
# print stats
|
12
17
|
obst_md = File.join(path, 'obst.md')
|
13
18
|
File.open(obst_md, 'w') do |f|
|
14
19
|
f.puts Obst::Chart::DailyCount.new(C: path).to_s
|
15
20
|
f.puts "\n"
|
16
|
-
f.puts Obst::Chart::DailyChange.new(C: path).to_s
|
21
|
+
f.puts Obst::Chart::DailyChange.new(C: path, cfg: cfg).to_s
|
22
|
+
f.puts "\n"
|
23
|
+
f.puts Obst::LongTimeNoSee.new(C: path, cfg: cfg).to_s
|
17
24
|
f.puts "\n"
|
18
|
-
f.puts Obst::TouchedFiles.new(C: path).to_s
|
25
|
+
f.puts Obst::TouchedFiles.new(C: path, cfg: cfg).to_s
|
19
26
|
end
|
data/lib/obst/chart.rb
CHANGED
@@ -2,7 +2,8 @@ module Obst
|
|
2
2
|
class Chart
|
3
3
|
class DailyCount
|
4
4
|
def initialize(**opts)
|
5
|
-
|
5
|
+
pathspec = opts[:cfg]&.dig_any(['pathspec'], ['chart_daily_count', 'pathspec'])
|
6
|
+
@daily_gauge = Obst::DailyGauge.new(C: opts[:C], pathspec: pathspec).lazy
|
6
7
|
end
|
7
8
|
|
8
9
|
def to_s
|
@@ -30,7 +31,8 @@ module Obst
|
|
30
31
|
|
31
32
|
class DailyChange
|
32
33
|
def initialize(**opts)
|
33
|
-
|
34
|
+
pathspec = opts[:cfg]&.dig_any(['pathspec'], ['chart_daily_change', 'pathspec'])
|
35
|
+
@daily = Obst::GroupByDays.new(C: opts[:C], pathspec: pathspec).lazy
|
34
36
|
end
|
35
37
|
|
36
38
|
def to_s
|
data/lib/obst/config.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require "json"
|
2
|
+
|
3
|
+
module Obst
|
4
|
+
class Config
|
5
|
+
def initialize(dir)
|
6
|
+
@cfg = nil
|
7
|
+
location = File.join(dir, '.obst.json')
|
8
|
+
return @cfg = {} unless File.exist?(location)
|
9
|
+
|
10
|
+
File.open(location) do |f|
|
11
|
+
@cfg = JSON.parse(f.read)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def dig(*path)
|
16
|
+
@cfg.dig(*path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def dig_any(*paths)
|
20
|
+
paths.each do |path|
|
21
|
+
v = dig(*path)
|
22
|
+
return v if v
|
23
|
+
end
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/obst/git_log.rb
CHANGED
@@ -7,6 +7,7 @@ module Obst
|
|
7
7
|
@cmd = ['git', '-C', path, 'log', '--name-status', '--pretty=format:%ad', "--date=format:'%Y-%m-%dT%H:%M:%S'"]
|
8
8
|
@cmd << '--after' << opts[:after] if opts[:after]
|
9
9
|
@cmd << '--before' << opts[:before] if opts[:before]
|
10
|
+
Array(opts[:pathspec]).each{ |s| @cmd << s }
|
10
11
|
end
|
11
12
|
|
12
13
|
def to_s
|
@@ -58,6 +59,9 @@ module Obst
|
|
58
59
|
raise 'fail to loop git log' unless status_thread.value.success?
|
59
60
|
end
|
60
61
|
y << Commit.new(batch)
|
62
|
+
rescue => e
|
63
|
+
puts @cmd
|
64
|
+
raise e
|
61
65
|
end
|
62
66
|
end
|
63
67
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "set"
|
2
|
+
require "obst/group_by_days"
|
3
|
+
|
4
|
+
module Obst
|
5
|
+
class LastSeen
|
6
|
+
include Enumerable
|
7
|
+
|
8
|
+
def initialize(**opts)
|
9
|
+
@groups = Obst::GroupByDays.new(**opts)
|
10
|
+
end
|
11
|
+
|
12
|
+
def each(&block)
|
13
|
+
return self unless block
|
14
|
+
|
15
|
+
seen = Set.new
|
16
|
+
@groups.each do |record|
|
17
|
+
record.file_changes.keys.each do |file|
|
18
|
+
if seen.include?(file)
|
19
|
+
record.file_changes.delete(file)
|
20
|
+
else
|
21
|
+
seen << file
|
22
|
+
end
|
23
|
+
end
|
24
|
+
block.call(record)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require "obst/last_seen"
|
2
|
+
|
3
|
+
module Obst
|
4
|
+
class LongTimeNoSee
|
5
|
+
def initialize(**opts)
|
6
|
+
opts = opts.merge(days: 7)
|
7
|
+
if cfg = opts[:cfg]
|
8
|
+
opts[:pathspec] ||= cfg.dig('long_time_no_see', 'pathspec')
|
9
|
+
end
|
10
|
+
@weekly = LastSeen.new(**opts)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_s
|
14
|
+
@buffer = ["# Long time no see\n"]
|
15
|
+
@weekly.each_with_index do |record, i|
|
16
|
+
@buffer << "- #{record.time} #{week_count(i)} (#{record.file_changes.count})"
|
17
|
+
list_files(record)
|
18
|
+
end
|
19
|
+
@buffer.join("\n")
|
20
|
+
end
|
21
|
+
|
22
|
+
def list_files(record)
|
23
|
+
record.group_inlines do |line|
|
24
|
+
@buffer << "\t- #{line}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def week_count(i)
|
29
|
+
return 'today' if i == 0
|
30
|
+
return '1.week.ago' if i == 1
|
31
|
+
"#{i}.weeks.ago"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/obst/pack_log.rb
CHANGED
@@ -46,6 +46,28 @@ module Obst
|
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
49
|
+
|
50
|
+
def group_by_final_status
|
51
|
+
groups = Hash.new{ |h, k| h[k] = [] }
|
52
|
+
file_changes.each_pair{ |file, changes| groups[changes.final] << file }
|
53
|
+
groups
|
54
|
+
end
|
55
|
+
|
56
|
+
def group_inlines(&block)
|
57
|
+
gbfs = group_by_final_status
|
58
|
+
|
59
|
+
[
|
60
|
+
[:new, :a, '#2db7b5'],
|
61
|
+
[:mod, :m, '#d3be03'],
|
62
|
+
[:del, :d, '#c71585'],
|
63
|
+
[:nil, nil, 'grey']
|
64
|
+
].each do |long, short, color|
|
65
|
+
files = gbfs[short]
|
66
|
+
next if files.empty?
|
67
|
+
inline_str = files.sort!.map{ |name| "[[#{name}]]" }.join(' / ')
|
68
|
+
block.call("<font color='#{color}'>#{long} #{files.count}:</font> #{inline_str}")
|
69
|
+
end
|
70
|
+
end
|
49
71
|
end
|
50
72
|
|
51
73
|
# yield PackLog::Record(
|
data/lib/obst/touched_files.rb
CHANGED
@@ -4,6 +4,12 @@ module Obst
|
|
4
4
|
class TouchedFiles
|
5
5
|
def initialize(**opts)
|
6
6
|
@path = opts[:C]
|
7
|
+
|
8
|
+
@pathspec =
|
9
|
+
if cfg = opts[:cfg]
|
10
|
+
opts[:pathspec] ||= cfg.dig_any(['pathspec'], ['touched_files', 'pathspec'])
|
11
|
+
end
|
12
|
+
|
7
13
|
@buffer = ["# Touch files in periods\n"]
|
8
14
|
end
|
9
15
|
|
@@ -17,7 +23,7 @@ module Obst
|
|
17
23
|
def last_7_days
|
18
24
|
@buffer << "- Last 7 days"
|
19
25
|
|
20
|
-
GroupByDays.new(C: @path).take(7).each do |record|
|
26
|
+
GroupByDays.new(C: @path, pathspec: @pathspec).take(7).each do |record|
|
21
27
|
@buffer << "\t- #{record.date_wday} (#{record.file_changes.count})"
|
22
28
|
list_files(record)
|
23
29
|
end
|
@@ -28,7 +34,7 @@ module Obst
|
|
28
34
|
|
29
35
|
@buffer << "- 1 week ago"
|
30
36
|
|
31
|
-
GroupByDays.new(C: @path, before: before, days: 7).take(3).each_with_index do |record, i|
|
37
|
+
GroupByDays.new(C: @path, before: before, days: 7, pathspec: @pathspec).take(3).each_with_index do |record, i|
|
32
38
|
@buffer << "\t- #{record.time} is #{1+i}.week#{suffix_s(i)}.ago (#{record.file_changes.count})"
|
33
39
|
list_files(record)
|
34
40
|
end
|
@@ -39,33 +45,18 @@ module Obst
|
|
39
45
|
|
40
46
|
@buffer << "- 1 month ago"
|
41
47
|
|
42
|
-
GroupByDays.new(C: @path, before: before, days: 28).take(2).each_with_index do |record, i|
|
48
|
+
GroupByDays.new(C: @path, before: before, days: 28, pathspec: @pathspec).take(2).each_with_index do |record, i|
|
43
49
|
@buffer << "\t- #{record.time} is #{1+i}.month#{suffix_s(i)}.ago (#{record.file_changes.count})"
|
44
50
|
list_files(record)
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
48
54
|
def list_files(record)
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
[
|
53
|
-
[:new, :a, '#2db7b5'],
|
54
|
-
[:mod, :m, '#d3be03'],
|
55
|
-
[:del, :d, '#c71585'],
|
56
|
-
[:nil, nil, 'grey']
|
57
|
-
].each do |long, short, color|
|
58
|
-
files = group_by_final_status[short]
|
59
|
-
next if files.empty?
|
60
|
-
inline_str = inline(files)
|
61
|
-
@buffer << "\t\t- <font color='#{color}'>#{long} #{files.count}:</font> #{inline_str}"
|
55
|
+
record.group_inlines do |line|
|
56
|
+
@buffer << "\t\t- #{line}"
|
62
57
|
end
|
63
58
|
end
|
64
59
|
|
65
|
-
def inline(files)
|
66
|
-
files.sort!.map{ |name| "[[#{name}]]" }.join(' / ')
|
67
|
-
end
|
68
|
-
|
69
60
|
def suffix_s(i)
|
70
61
|
i == 0 ? '' : 's'
|
71
62
|
end
|
data/lib/obst/version.rb
CHANGED
data/lib/obst.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: obst
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ken
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-11-
|
11
|
+
date: 2022-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -30,10 +30,13 @@ files:
|
|
30
30
|
- exe/obst
|
31
31
|
- lib/obst.rb
|
32
32
|
- lib/obst/chart.rb
|
33
|
+
- lib/obst/config.rb
|
33
34
|
- lib/obst/daily_gauge.rb
|
34
35
|
- lib/obst/daily_increment.rb
|
35
36
|
- lib/obst/git_log.rb
|
36
37
|
- lib/obst/group_by_days.rb
|
38
|
+
- lib/obst/last_seen.rb
|
39
|
+
- lib/obst/long_time_no_see.rb
|
37
40
|
- lib/obst/pack_log.rb
|
38
41
|
- lib/obst/touched_files.rb
|
39
42
|
- lib/obst/version.rb
|