spoom 1.1.16 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/spoom.rb CHANGED
@@ -10,58 +10,6 @@ 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
 
67
15
  require "spoom/context"
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.0
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-30 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
@@ -139,7 +144,6 @@ files:
139
144
  - lib/spoom/coverage/report.rb
140
145
  - lib/spoom/coverage/snapshot.rb
141
146
  - lib/spoom/file_tree.rb
142
- - lib/spoom/git.rb
143
147
  - lib/spoom/printer.rb
144
148
  - lib/spoom/sorbet.rb
145
149
  - lib/spoom/sorbet/config.rb
@@ -175,7 +179,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
179
  - !ruby/object:Gem::Version
176
180
  version: '0'
177
181
  requirements: []
178
- rubygems_version: 3.3.3
182
+ rubygems_version: 3.4.9
179
183
  signing_key:
180
184
  specification_version: 4
181
185
  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