spoom 1.1.16 → 1.2.1

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.
@@ -1,17 +1,15 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative "git"
5
-
6
4
  module Spoom
7
5
  class Timeline
8
6
  extend T::Sig
9
7
 
10
- sig { params(from: Time, to: Time, path: String).void }
11
- def initialize(from, to, path: ".")
8
+ sig { params(context: Context, from: Time, to: Time).void }
9
+ def initialize(context, from, to)
10
+ @context = context
12
11
  @from = from
13
12
  @to = to
14
- @path = path
15
13
  end
16
14
 
17
15
  # Return one commit for each month between `from` and `to`
@@ -37,17 +35,16 @@ module Spoom
37
35
  sig { params(dates: T::Array[Time]).returns(T::Array[Git::Commit]) }
38
36
  def commits_for_dates(dates)
39
37
  dates.map do |t|
40
- result = Spoom::Git.log(
38
+ result = @context.git_log(
41
39
  "--since='#{t}'",
42
40
  "--until='#{t.to_date.next_month}'",
43
41
  "--format='format:%h %at'",
44
42
  "--author-date-order",
45
43
  "-1",
46
- path: @path,
47
44
  )
48
45
  next if result.out.empty?
49
46
 
50
- Git.parse_commit(result.out.strip)
47
+ Spoom::Git::Commit.parse_line(result.out.strip)
51
48
  end.compact.uniq(&:sha)
52
49
  end
53
50
  end
data/lib/spoom/version.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Spoom
5
- VERSION = "1.1.16"
5
+ VERSION = "1.2.1"
6
6
  end
data/lib/spoom.rb CHANGED
@@ -10,60 +10,9 @@ module Spoom
10
10
  SPOOM_PATH = T.let((Pathname.new(__FILE__) / ".." / "..").to_s, String)
11
11
 
12
12
  class Error < StandardError; end
13
-
14
- class ExecResult < T::Struct
15
- extend T::Sig
16
-
17
- const :out, String
18
- const :err, T.nilable(String)
19
- const :status, T::Boolean
20
- const :exit_code, Integer
21
-
22
- sig { returns(String) }
23
- def to_s
24
- <<~STR
25
- ########## STDOUT ##########
26
- #{out.empty? ? "<empty>" : out}
27
- ########## STDERR ##########
28
- #{err&.empty? ? "<empty>" : err}
29
- ########## STATUS: #{status} ##########
30
- STR
31
- end
32
- end
33
-
34
- class << self
35
- extend T::Sig
36
-
37
- sig do
38
- params(
39
- cmd: String,
40
- arg: String,
41
- path: String,
42
- capture_err: T::Boolean,
43
- ).returns(ExecResult)
44
- end
45
- def exec(cmd, *arg, path: ".", capture_err: true)
46
- if capture_err
47
- stdout, stderr, status = T.unsafe(Open3).capture3([cmd, *arg].join(" "), chdir: path)
48
- ExecResult.new(
49
- out: stdout,
50
- err: stderr,
51
- status: status.success?,
52
- exit_code: status.exitstatus,
53
- )
54
- else
55
- stdout, status = T.unsafe(Open3).capture2([cmd, *arg].join(" "), chdir: path)
56
- ExecResult.new(
57
- out: stdout,
58
- err: nil,
59
- status: status.success?,
60
- exit_code: status.exitstatus,
61
- )
62
- end
63
- end
64
- end
65
13
  end
66
14
 
15
+ require "spoom/file_collector"
67
16
  require "spoom/context"
68
17
  require "spoom/colors"
69
18
  require "spoom/sorbet"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spoom
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.16
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Terrasa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-28 00:00:00.000000000 Z
11
+ date: 2023-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -130,6 +130,11 @@ files:
130
130
  - lib/spoom/cli/run.rb
131
131
  - lib/spoom/colors.rb
132
132
  - lib/spoom/context.rb
133
+ - lib/spoom/context/bundle.rb
134
+ - lib/spoom/context/exec.rb
135
+ - lib/spoom/context/file_system.rb
136
+ - lib/spoom/context/git.rb
137
+ - lib/spoom/context/sorbet.rb
133
138
  - lib/spoom/coverage.rb
134
139
  - lib/spoom/coverage/d3.rb
135
140
  - lib/spoom/coverage/d3/base.rb
@@ -138,8 +143,8 @@ files:
138
143
  - lib/spoom/coverage/d3/timeline.rb
139
144
  - lib/spoom/coverage/report.rb
140
145
  - lib/spoom/coverage/snapshot.rb
146
+ - lib/spoom/file_collector.rb
141
147
  - lib/spoom/file_tree.rb
142
- - lib/spoom/git.rb
143
148
  - lib/spoom/printer.rb
144
149
  - lib/spoom/sorbet.rb
145
150
  - lib/spoom/sorbet/config.rb
@@ -175,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
180
  - !ruby/object:Gem::Version
176
181
  version: '0'
177
182
  requirements: []
178
- rubygems_version: 3.3.3
183
+ rubygems_version: 3.4.9
179
184
  signing_key:
180
185
  specification_version: 4
181
186
  summary: Useful tools for Sorbet enthusiasts.
data/lib/spoom/git.rb DELETED
@@ -1,109 +0,0 @@
1
- # typed: strict
2
- # frozen_string_literal: true
3
-
4
- require "time"
5
-
6
- module Spoom
7
- # Execute git commands
8
- module Git
9
- class Commit < T::Struct
10
- extend T::Sig
11
-
12
- const :sha, String
13
- const :time, Time
14
-
15
- sig { returns(Integer) }
16
- def timestamp
17
- time.to_i
18
- end
19
- end
20
-
21
- class << self
22
- extend T::Sig
23
-
24
- # Git commands
25
-
26
- sig { params(arg: String, path: String).returns(ExecResult) }
27
- def checkout(*arg, path: ".")
28
- Spoom.exec("git checkout -q #{arg.join(" ")}", path: path)
29
- end
30
-
31
- sig { params(arg: String, path: String).returns(ExecResult) }
32
- def diff(*arg, path: ".")
33
- Spoom.exec("git diff #{arg.join(" ")}", path: path)
34
- end
35
-
36
- sig { params(arg: String, path: String).returns(ExecResult) }
37
- def log(*arg, path: ".")
38
- Spoom.exec("git log #{arg.join(" ")}", path: path)
39
- end
40
-
41
- sig { params(arg: String, path: String).returns(ExecResult) }
42
- def show(*arg, path: ".")
43
- Spoom.exec("git show #{arg.join(" ")}", path: path)
44
- end
45
-
46
- sig { params(path: String).returns(T.nilable(String)) }
47
- def current_branch(path: ".")
48
- result = Spoom.exec("git branch --show-current", path: path)
49
- return nil unless result.status
50
-
51
- result.out.strip
52
- end
53
-
54
- # Utils
55
-
56
- # Get the last commit in the currently checked out branch
57
- sig { params(path: String, short_sha: T::Boolean).returns(T.nilable(Commit)) }
58
- def last_commit(path: ".", short_sha: true)
59
- result = log("HEAD --format='%#{short_sha ? "h" : "H"} %at' -1", path: path)
60
- return nil unless result.status
61
-
62
- out = result.out.strip
63
- return nil if out.empty?
64
-
65
- parse_commit(out)
66
- end
67
-
68
- # Is there uncommited changes in `path`?
69
- sig { params(path: String).returns(T::Boolean) }
70
- def workdir_clean?(path: ".")
71
- diff("HEAD", path: path).out.empty?
72
- end
73
-
74
- # Get the commit introducing the `sorbet/config` file
75
- sig { params(path: String).returns(T.nilable(Commit)) }
76
- def sorbet_intro_commit(path: ".")
77
- result = log("--diff-filter=A --format='%h %at' -1 -- sorbet/config", path: path)
78
- return nil unless result.status
79
-
80
- out = result.out.strip
81
- return nil if out.empty?
82
-
83
- parse_commit(out)
84
- end
85
-
86
- # Get the commit removing the `sorbet/config` file
87
- sig { params(path: String).returns(T.nilable(Commit)) }
88
- def sorbet_removal_commit(path: ".")
89
- result = log("--diff-filter=D --format='%h %at' -1 -- sorbet/config", path: path)
90
- return nil unless result.status
91
-
92
- out = result.out.strip
93
- return nil if out.empty?
94
-
95
- parse_commit(out)
96
- end
97
-
98
- # Parse a line formated as `%h %at` into a `Commit`
99
- sig { params(string: String).returns(T.nilable(Commit)) }
100
- def parse_commit(string)
101
- sha, epoch = string.split(" ", 2)
102
- return nil unless sha && epoch
103
-
104
- time = Time.strptime(epoch, "%s")
105
- Commit.new(sha: sha, time: time)
106
- end
107
- end
108
- end
109
- end