obst 0.1.7 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc318da9a56d9fd4593627a727f36a2ff01ab2e9ba5d1f4969bc4d299acce702
4
- data.tar.gz: 6f649344c285a743333d35d7bd4cf11844a38f810fee94040c3de7a46e75f8f4
3
+ metadata.gz: 33dbda872356a5eaec6905a2054093af4a49555183ad517160a8bcb27f0b7ddd
4
+ data.tar.gz: 77d38fa97ae8e8319b05f85c3106e3fda15a7c14bb3b737a9ecae874c0a81599
5
5
  SHA512:
6
- metadata.gz: 21c1eea8e6a53ba8c9f94d09d3996eee64f522bd503458600d4db87d584ceb1b2496d55fcb031123a8bcd0b3a3b957c9e6b36772921e8f7f71e19f537fe13b98
7
- data.tar.gz: b44b1782a1e95a5d791b90538e2023515a3da8d69432b76a93bd376d5ef65699190972675354c1c6a76a6233b6e5bf1e1bf171c0f78655a0dfd9917df39c0621
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,18 +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
17
22
  f.puts "\n"
18
- f.puts Obst::LongTimeNoSee.new(C: path).to_s
23
+ f.puts Obst::LongTimeNoSee.new(C: path, cfg: cfg).to_s
19
24
  f.puts "\n"
20
- f.puts Obst::TouchedFiles.new(C: path).to_s
25
+ f.puts Obst::TouchedFiles.new(C: path, cfg: cfg).to_s
21
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
- @daily_gauge = Obst::DailyGauge.new(C: opts[:C]).lazy
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
- @daily = Obst::GroupByDays.new(C: opts[:C]).lazy
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
@@ -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
@@ -4,6 +4,9 @@ module Obst
4
4
  class LongTimeNoSee
5
5
  def initialize(**opts)
6
6
  opts = opts.merge(days: 7)
7
+ if cfg = opts[:cfg]
8
+ opts[:pathspec] ||= cfg.dig('long_time_no_see', 'pathspec')
9
+ end
7
10
  @weekly = LastSeen.new(**opts)
8
11
  end
9
12
 
@@ -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,7 +45,7 @@ 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
data/lib/obst/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Obst
2
- VERSION = "0.1.7"
2
+ VERSION = "0.1.8"
3
3
  end
data/lib/obst.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "obst/version"
2
+ require "obst/config"
2
3
  require "obst/git_log"
3
4
  require "obst/group_by_days"
4
5
  require "obst/touched_files"
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.7
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-27 00:00:00.000000000 Z
11
+ date: 2022-11-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -30,6 +30,7 @@ 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