obst 0.1.1 → 0.1.3

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: 8fa5dec61f4c26ed664472ec781fc2cd49cd9e394045bd5300a0cce2553df855
4
- data.tar.gz: 2ae5084507590446957c8082d5764fb81fd6c53f7fec007c0b066f266be8be8e
3
+ metadata.gz: 98098746bf391bc2ef384eb8fd5f5a16ed462ecb2392aedafa4ad817a173afb6
4
+ data.tar.gz: a96c73fed2dcf4f6a14c695f8da6e08fb8f62e6e93d579d867971453b40b6dd5
5
5
  SHA512:
6
- metadata.gz: e24d2cabc29a3b9366bf5f556adf56b70144edef016dd2b68097efcc4766ddb006aca9218a3686bab089b089fdb473b7f4914357af4280c151f35935ba0e4d5c
7
- data.tar.gz: 6a0336b13a65f370496b004fa315928951a2e4f69b8ee097e1d944b7933c23de85204258378031922943b417bd351f8e0d33f887f34286c1a3b08532c4910b66
6
+ metadata.gz: 2a168e81dc31da12781806ebd4ab199ef5554d9293b39d3d7578085fc9bd3b5f1dcb7a0a8cacca5f2af655ba8111e1b4299690c14c7a7573e0ef0413a6468061
7
+ data.tar.gz: 5bd90a681ea26bf5b8f599465ab6a47b3a8b51baf913df9211b26792418122294228f7aff8848ed1f25d109e4242409f3aa779e9f08b199c6ab0eebc07f246fe
data/exe/obst ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "obst"
4
+
5
+ path = ARGV[0] || '.'
6
+
7
+ gitignore = File.join(path, '.gitignore')
8
+ File.open(gitignore, 'a+') do |f|
9
+ f.puts("# Obst\nobst.md") unless f.read =~ /# Obst/
10
+ end
11
+
12
+ obst_md = File.join(path, 'obst.md')
13
+ File.open(obst_md, 'w') do |f|
14
+ f.puts Obst::TouchedFiles.new(C: path).to_s
15
+ end
data/lib/obst/git_log.rb CHANGED
@@ -4,7 +4,7 @@ module Obst
4
4
  class GitLog
5
5
  def initialize(**opts)
6
6
  path = opts[:C] || '.'
7
- @cmd = ['git', '-C', path, 'log', '--name-status', '--pretty=format:%ad', "--date=format:'%Y-%m-%d %H:%M:%S'"]
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
10
  end
@@ -8,7 +8,7 @@ module Obst
8
8
  ONE_DAY = 60 * 60 * 24
9
9
 
10
10
  def initialize(**opts)
11
- duration = ONE_DAY* (opts[:days] || 1)
11
+ duration = ONE_DAY * (opts[:days] || 1)
12
12
  latest = opts[:before] ? Time.parse(opts[:before]) : Time.parse(Time.now.strftime('%F 23:59:59'))
13
13
 
14
14
  @timeline = Enumerator.new do |y|
data/lib/obst/pack_log.rb CHANGED
@@ -18,9 +18,31 @@ module Obst
18
18
  def inspect
19
19
  @arr
20
20
  end
21
+
22
+ def final
23
+ return :d if @arr[0] == :d
24
+ return :a if @arr[-1] == :a
25
+ :m
26
+ end
21
27
  end
22
28
 
23
- Record = Struct.new(:time, :statuses)
29
+ Record = Struct.new(:time, :statuses) do
30
+ def status_sum
31
+ sum = Hash.new{ |h, k| h[k] = 0 }
32
+ statuses.each_value do |status|
33
+ sum[status.final] += 1
34
+ end
35
+ sum
36
+ end
37
+
38
+ def str_status_sum
39
+ sb = []
40
+ status_sum.each_pair do |st, count|
41
+ sb << "#{st}: #{count}"
42
+ end
43
+ sb.join(', ')
44
+ end
45
+ end
24
46
 
25
47
  def each(&block)
26
48
  current_time = nil
@@ -0,0 +1,58 @@
1
+ require "obst/group_by_days"
2
+
3
+ module Obst
4
+ class TouchedFiles
5
+ def initialize(**opts)
6
+ @path = opts[:C]
7
+ @buffer = []
8
+ end
9
+
10
+ def to_s
11
+ last_7_days
12
+ @buffer << ''
13
+ last_4_weeks_without_last_7_days
14
+ @buffer << ''
15
+ last_3_months_without_last_4_weeks
16
+ @buffer.join("\n")
17
+ end
18
+
19
+ def last_7_days
20
+ @buffer << "# Last 7 days\n"
21
+
22
+ GroupByDays.new(C: @path).take(7).each do |record|
23
+ wday = Time.parse(record.time).strftime('%a')
24
+ @buffer << "- #{record.time} #{wday} (#{record.statuses.size})"
25
+ list_files(record)
26
+ end
27
+ end
28
+
29
+ def last_4_weeks_without_last_7_days
30
+ before = (Time.now - (60 * 60 * 24 * 7)).strftime('%FT23:59:59')
31
+
32
+ @buffer << "# 3 weeks earlier\n"
33
+
34
+ GroupByDays.new(C: @path, before: before, days: 7).take(3).each do |record|
35
+ @buffer << "- #{record.time} (#{record.statuses.size})"
36
+ list_files(record)
37
+ end
38
+ end
39
+
40
+ def last_3_months_without_last_4_weeks
41
+ before = (Time.now - (60 * 60 * 24 * 28)).strftime('%FT23:59:59')
42
+
43
+ @buffer << "# 1 month earlier\n"
44
+
45
+ GroupByDays.new(C: @path, before: before, days: 28).take(2).each do |record|
46
+ @buffer << "- #{record.time} (#{record.statuses.size})"
47
+ list_files(record)
48
+ end
49
+ end
50
+
51
+ def list_files(record)
52
+ record.statuses.each_pair do |name, status|
53
+ entry = status.final == :a ? "\t- [[#{name}]] *new !*" : "\t- [[#{name}]]"
54
+ @buffer << entry
55
+ end
56
+ end
57
+ end
58
+ end
data/lib/obst/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Obst
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.3"
3
3
  end
data/lib/obst.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require "obst/version"
2
2
  require "obst/git_log"
3
3
  require "obst/group_by_days"
4
+ require "obst/touched_files"
4
5
 
5
6
  module Obst
6
7
  end
metadata CHANGED
@@ -1,19 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obst
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
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-24 00:00:00.000000000 Z
11
+ date: 2022-11-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
15
15
  - block24block@gmail.com
16
- executables: []
16
+ executables:
17
+ - obst
17
18
  extensions: []
18
19
  extra_rdoc_files: []
19
20
  files:
@@ -26,10 +27,12 @@ files:
26
27
  - Rakefile
27
28
  - bin/console
28
29
  - bin/setup
30
+ - exe/obst
29
31
  - lib/obst.rb
30
32
  - lib/obst/git_log.rb
31
33
  - lib/obst/group_by_days.rb
32
34
  - lib/obst/pack_log.rb
35
+ - lib/obst/touched_files.rb
33
36
  - lib/obst/version.rb
34
37
  - obst.gemspec
35
38
  homepage: https://github.com/turnon/obst