rumblestrip 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3e218ec81969b468f703a12c072f2f90c0349a57a6c2820c583d00eea7f1c246
4
+ data.tar.gz: 56f445a38c5d649153a1828d83b7f9d3039b950124a162f3d0135565eff8c6f6
5
+ SHA512:
6
+ metadata.gz: 37cf5f055cbc6eef273fcdc0806f11f37a21474f482765e0c1a6657102498ed1fa031b59c4b403a369a401791335359fe9da25b44d213922a895f726a9969a1d
7
+ data.tar.gz: 521ead08c60822e54beecdf8ea673482c750b98114539d422c587f6ab86309338ec2ed369a7044f90defc4cfc780c535206bc522e444c4837a46d47b6803a855
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chris Chandler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # rumblestrip
2
+
3
+ A local, CODEOWNERS-aware diff linter inspired by [Danger](https://github.com/danger/danger).
4
+ Write **Strips** in a `Rumblefile`; each one inspects what changed on your branch and
5
+ warns or fails on heuristic rules, scoped to the teams named in `CODEOWNERS`.
6
+
7
+ > Status: 0.1 — early and unstable. The API will change before 1.0.
8
+
9
+ ```ruby
10
+ strip "Jobs must not grow private methods", team: "@org/integrations" do
11
+ changed("app/jobs/**/*_job.rb").each do |file|
12
+ diff(file).added_lines.select { |l| l.text =~ /\A\s*private\b/ }.each do |l|
13
+ fail "Extract a service object", file: file, line: l.number
14
+ end
15
+ end
16
+ end
17
+ ```
18
+
19
+ ```
20
+ gem install rumblestrip
21
+ rumble init # writes an example Rumblefile
22
+ rumble # diff vs origin/HEAD (incl. uncommitted work); exits 1 on failures
23
+ rumble -t @org/integrations
24
+ rumble -q # failures only
25
+ rumble --json # banner line, then one JSON document
26
+ ```
27
+
28
+ ### Block commits and pushes on failures
29
+
30
+ ```
31
+ rumble install-hooks # .githooks/pre-commit + pre-push run `rumble -q`; sets core.hooksPath
32
+ rumble install-hooks --claude # also adds a Claude Code PreToolUse gate to .claude/settings.json
33
+ ```
34
+
35
+ The git hooks abort `git commit` / `git push` when any strip fails. The Claude gate (`rumble gate`)
36
+ reads the tool call from stdin and, for `git commit` / `git push`, exits 2 with the failures on
37
+ stderr so the agent can fix them. Only failures block; warnings never do. `RUMBLE_SKIP=1` bypasses
38
+ both. Existing hooks that rumble didn't write are left alone unless you pass `--force`; use
39
+ `--hooks-dir DIR` to pick a directory other than `.githooks`. Other clones need
40
+ `git config core.hooksPath .githooks` once.
41
+
42
+ See `examples/Rumblefile` for the available DSL.
@@ -0,0 +1,37 @@
1
+ # Rumblefile — each `strip` runs against what changed on this branch.
2
+ # A strip with `team:` only sees files CODEOWNERS assigns to that team.
3
+ #
4
+ # Available inside a strip:
5
+ # changed("glob"), added(..), deleted(..), changed?("glob") – file names
6
+ # diff(path).added_lines / removed_lines – [#<Line number, text>]
7
+ # content(path), base_content(path), exists?(path), repo_files("glob")
8
+ # fail / warn / message("text", file:, line:)
9
+
10
+ # Controller changes must come with specs that assert authorization.
11
+ strip "Controllers need authorization specs", team: "@acme/platform" do
12
+ changed("app/controllers/**/*_controller.rb").each do |file|
13
+ spec = file.sub(%r{\Aapp/}, "spec/").sub(/\.rb\z/, "_spec.rb")
14
+ if !exists?(spec)
15
+ fail "No spec found at #{spec}", file: file
16
+ elsif !changed?(spec)
17
+ warn "Controller changed but #{spec} did not", file: file
18
+ elsif content(spec) !~ /forbidden|unauthorized|authorize|pundit|cancan/i
19
+ warn "#{spec} doesn't appear to assert authorization", file: spec
20
+ end
21
+ end
22
+ end
23
+
24
+ # Cross-module coupling: touching billing means the invoicing suite must follow.
25
+ strip "Billing changes must update invoicing specs" do
26
+ if changed?("app/models/billing/**/*.rb") && !changed?("spec/invoicing/**/*.rb")
27
+ warn "app/models/billing changed; spec/invoicing did not"
28
+ end
29
+ end
30
+
31
+ # Jobs stay thin: logic belongs in service objects, so no private methods.
32
+ strip "Jobs delegate to service objects" do
33
+ changed("app/jobs/**/*_job.rb").each do |file|
34
+ line = content(file).each_line.with_index(1).find { |l, _| l =~ /^\s*private\b/ }
35
+ fail "Jobs must not need private methods; move logic into a service object", file: file, line: line&.last if line
36
+ end
37
+ end
data/exe/rumble ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
3
+ require "rumblestrip"
4
+ exit Rumblestrip::CLI.new(ARGV).run
@@ -0,0 +1,107 @@
1
+ require "optparse"
2
+ require "json"
3
+ require "stringio"
4
+
5
+ module Rumblestrip
6
+ class CLI
7
+ BANNER = "LET'S GET READY TO RUMBLE>>>".freeze
8
+ TEMPLATE = File.read(File.expand_path("../../examples/Rumblefile", __dir__))
9
+
10
+ def initialize(argv, out: $stdout, err: $stderr, in_io: $stdin)
11
+ @argv, @out, @err, @in = argv.dup, out, err, in_io
12
+ @opts = { file: "Rumblefile" }
13
+ end
14
+
15
+ def run
16
+ @out.puts BANNER unless @argv.include?("gate") # gate speaks only on failure
17
+ parser.parse!(@argv)
18
+ case (cmd = @argv.shift || "check")
19
+ when "check" then check
20
+ when "init" then init
21
+ when "list" then list
22
+ when "owners" then owners
23
+ when "install-hooks" then install_hooks
24
+ when "gate" then gate
25
+ else @err.puts "unknown command #{cmd.inspect}\n#{parser}"; 2
26
+ end
27
+ rescue Error, OptionParser::ParseError => e
28
+ @err.puts "rumble: #{e.message}"
29
+ 2
30
+ end
31
+
32
+ private
33
+
34
+ def parser
35
+ @parser ||= OptionParser.new do |o|
36
+ o.banner = "Usage: rumble [check|init|list|owners PATH|install-hooks|gate] [options]"
37
+ o.on("-b", "--base REF", "Base ref to diff against (default: origin/HEAD, main, master)") { |v| @opts[:base] = v }
38
+ o.on("-t", "--team TEAM", "Only run strips for this CODEOWNERS team") { |v| @opts[:team] = v }
39
+ o.on("-f", "--file PATH", "Rumblefile path (default: Rumblefile)") { |v| @opts[:file] = v }
40
+ o.on("-q", "--quiet", "Only show failures (text output)") { @opts[:quiet] = true }
41
+ o.on("-j", "--json", "Emit one JSON document after the banner line") { @opts[:json] = true }
42
+ o.on("--claude", "install-hooks: also add a Claude Code PreToolUse gate") { @opts[:claude] = true }
43
+ o.on("--hooks-dir DIR", "install-hooks: git hooks directory (default: .githooks)") { |v| @opts[:hooks_dir] = v }
44
+ o.on("--force", "install-hooks: overwrite hooks rumble didn't write") { @opts[:force] = true }
45
+ o.on("-v", "--version") { @out.puts VERSION; exit 0 }
46
+ end
47
+ end
48
+
49
+ def check
50
+ rumblefile = Rumblefile.load(@opts[:file])
51
+ diff = Diff.new(base: @opts[:base])
52
+ codeowners = Codeowners.find(diff.root)
53
+ result = Runner.new(rumblefile: rumblefile, diff: diff, codeowners: codeowners, team: @opts[:team]).run
54
+ reporter = @opts[:json] ? JsonReporter.new(io: @out) : Reporter.new(io: @out, quiet: @opts[:quiet])
55
+ reporter.report(result, diff)
56
+ result.failed? ? 1 : 0
57
+ end
58
+
59
+ def install_hooks
60
+ Hooks.new(root: Diff.new(base: @opts[:base]).root, out: @out, dir: @opts[:hooks_dir] || ".githooks",
61
+ claude: @opts[:claude], force: @opts[:force]).install
62
+ end
63
+
64
+ # Claude Code PreToolUse hook: reads the tool call JSON on stdin; blocks (exit 2, report on
65
+ # stderr so the agent sees it) `git commit`/`git push` while any strip fails.
66
+ def gate
67
+ return 0 if ENV["RUMBLE_SKIP"] && !ENV["RUMBLE_SKIP"].empty?
68
+ command = JSON.parse(@in.read).dig("tool_input", "command").to_s
69
+ return 0 unless command.match?(Hooks::CLAUDE_COMMAND_RE)
70
+ buffer = StringIO.new
71
+ code = CLI.new(%w[-q] + gate_passthrough, out: buffer, err: buffer).run
72
+ return 0 if code.zero?
73
+ @err.puts buffer.string, "rumble failed: fix the failures above before committing or pushing."
74
+ 2
75
+ rescue JSON::ParserError
76
+ 0
77
+ end
78
+
79
+ def gate_passthrough
80
+ args = []
81
+ args += ["-b", @opts[:base]] if @opts[:base]
82
+ args += ["-f", @opts[:file]] if @opts[:file] != "Rumblefile"
83
+ args
84
+ end
85
+
86
+ def init
87
+ raise Error, "#{@opts[:file]} already exists" if File.exist?(@opts[:file])
88
+ File.write(@opts[:file], TEMPLATE)
89
+ @out.puts "wrote #{@opts[:file]}"
90
+ 0
91
+ end
92
+
93
+ def list
94
+ Rumblefile.load(@opts[:file]).strips.each do |s|
95
+ @out.puts "#{s.team || '(everyone)'}\t#{s.name}"
96
+ end
97
+ 0
98
+ end
99
+
100
+ def owners
101
+ path = @argv.shift or raise Error, "usage: rumble owners PATH"
102
+ co = Codeowners.find(Diff.new(base: @opts[:base]).root) or raise Error, "no CODEOWNERS found"
103
+ @out.puts co.owners_for(path).join(" ")
104
+ 0
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,55 @@
1
+ module Rumblestrip
2
+ # Parses a GitHub-style CODEOWNERS file. Last matching rule wins.
3
+ class Codeowners
4
+ LOCATIONS = %w[CODEOWNERS .github/CODEOWNERS docs/CODEOWNERS].freeze
5
+ Rule = Struct.new(:pattern, :regex, :owners)
6
+
7
+ def self.find(root)
8
+ path = LOCATIONS.map { |l| File.join(root, l) }.find { |p| File.file?(p) }
9
+ path && new(File.read(path))
10
+ end
11
+
12
+ def initialize(text)
13
+ @rules = text.each_line.filter_map { |line| parse_line(line) }
14
+ end
15
+
16
+ def owners_for(path)
17
+ rule = @rules.reverse_each.find { |r| r.regex.match?(path) }
18
+ rule ? rule.owners : []
19
+ end
20
+
21
+ def teams
22
+ @rules.flat_map(&:owners).uniq
23
+ end
24
+
25
+ private
26
+
27
+ def parse_line(line)
28
+ line = line.sub(/(?<!\\)#.*/, "").strip
29
+ return if line.empty?
30
+ pattern, *owners = line.split(/\s+/)
31
+ Rule.new(pattern, to_regex(pattern), owners)
32
+ end
33
+
34
+ def to_regex(pattern)
35
+ dir_only = pattern.end_with?("/")
36
+ pat = pattern.chomp("/")
37
+ anchored = pat.start_with?("/") || pat.include?("/")
38
+ pat = pat.delete_prefix("/")
39
+
40
+ body = pat.gsub(%r{\*\*/|/\*\*|\*\*|\*|\?|[^*?]+}) do |tok|
41
+ case tok
42
+ when "**/" then "(?:.*/)?"
43
+ when "/**" then "/.*"
44
+ when "**" then ".*"
45
+ when "*" then "[^/]*"
46
+ when "?" then "[^/]"
47
+ else Regexp.escape(tok)
48
+ end
49
+ end
50
+ prefix = anchored ? "\\A" : "\\A(?:.*/)?"
51
+ suffix = dir_only ? "/.*\\z" : "(?:/.*)?\\z"
52
+ Regexp.new(prefix + body + suffix)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,57 @@
1
+ module Rumblestrip
2
+ # The object a Strip block is evaluated against (self inside the block).
3
+ # When the strip has a team, every file list is limited to files that
4
+ # CODEOWNERS assigns to that team.
5
+ class Context
6
+ attr_reader :findings
7
+
8
+ def initialize(strip:, diff:, codeowners:)
9
+ @strip, @diff, @codeowners = strip, diff, codeowners
10
+ @findings = []
11
+ end
12
+
13
+ # --- what changed -------------------------------------------------
14
+ def changed_files = in_scope(@diff.paths - @diff.paths(:deleted))
15
+ def added_files = in_scope(@diff.paths(:added))
16
+ def modified_files = in_scope(@diff.paths(:modified))
17
+ def deleted_files = in_scope(@diff.paths(:deleted))
18
+ def renamed_files = in_scope(@diff.paths(:renamed))
19
+
20
+ # Changed (non-deleted, in-scope) files matching any glob.
21
+ def changed(*globs) = matching(changed_files, globs)
22
+ def added(*globs) = matching(added_files, globs)
23
+ def deleted(*globs) = matching(deleted_files, globs)
24
+ def changed?(*globs) = !changed(*globs).empty?
25
+
26
+ # --- inspecting ---------------------------------------------------
27
+ def diff(path) = @diff[path] || FileDiff.new(path: path, status: :unchanged)
28
+ def content(path) = @diff.read(path)
29
+ def base_content(path) = @diff.read_base(path)
30
+ def exists?(path) = File.exist?(File.join(@diff.root, path))
31
+ def repo_files(*globs) = globs.flat_map { |g| Dir.glob(g, base: @diff.root) }.sort.uniq
32
+ def owners(path) = @codeowners ? @codeowners.owners_for(path) : []
33
+
34
+ # --- reporting ----------------------------------------------------
35
+ def fail(message, file: nil, line: nil) = report(:fail, message, file, line)
36
+ def warn(message, file: nil, line: nil) = report(:warn, message, file, line)
37
+ def message(message, file: nil, line: nil) = report(:message, message, file, line)
38
+
39
+ private
40
+
41
+ def report(severity, text, file, line)
42
+ @findings << Finding.new(severity: severity, message: text, strip: @strip.name,
43
+ team: @strip.team, file: file, line: line)
44
+ nil
45
+ end
46
+
47
+ def in_scope(paths)
48
+ return paths unless @strip.team
49
+ paths.select { |p| owners(p).include?(@strip.team) }
50
+ end
51
+
52
+ def matching(paths, globs)
53
+ globs = globs.flatten
54
+ paths.select { |p| globs.any? { |g| File.fnmatch?(g, p, File::FNM_PATHNAME | File::FNM_EXTGLOB) } }
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,125 @@
1
+ require "open3"
2
+
3
+ module Rumblestrip
4
+ # What changed in a single file relative to the base.
5
+ class FileDiff
6
+ Line = Struct.new(:number, :text)
7
+
8
+ attr_reader :path, :status, :old_path, :added_lines, :removed_lines
9
+
10
+ def initialize(path:, status:, old_path: nil)
11
+ @path, @status, @old_path = path, status, old_path
12
+ @added_lines = []
13
+ @removed_lines = []
14
+ end
15
+
16
+ def added_text = added_lines.map(&:text).join("\n")
17
+ def removed_text = removed_lines.map(&:text).join("\n")
18
+
19
+ # Did any added/removed line match?
20
+ def added?(pattern) = added_lines.any? { |l| pattern === l.text }
21
+ def removed?(pattern) = removed_lines.any? { |l| pattern === l.text }
22
+ end
23
+
24
+ # Interrogates git for the changes between a base and the working tree
25
+ # (committed + uncommitted + untracked).
26
+ class Diff
27
+ STATUS = { "A" => :added, "M" => :modified, "D" => :deleted, "R" => :renamed, "C" => :added, "T" => :modified }.freeze
28
+
29
+ attr_reader :root, :base, :merge_base
30
+
31
+ def initialize(root: Dir.pwd, base: nil)
32
+ @root = git("rev-parse", "--show-toplevel").strip
33
+ @base = base || ENV["RUMBLE_BASE"] || detect_base
34
+ @merge_base = git("merge-base", @base, "HEAD").strip
35
+ end
36
+
37
+ def files
38
+ @files ||= load_files
39
+ end
40
+
41
+ def [](path) = files[path]
42
+
43
+ def paths(*statuses)
44
+ statuses = statuses.flatten
45
+ files.values.select { |f| statuses.empty? || statuses.include?(f.status) }.map(&:path)
46
+ end
47
+
48
+ def read(path)
49
+ full = File.join(root, path)
50
+ File.file?(full) ? File.read(full) : nil
51
+ end
52
+
53
+ def read_base(path)
54
+ out, _err, st = Open3.capture3("git", "show", "#{merge_base}:#{path}", chdir: root)
55
+ st.success? ? out : nil
56
+ end
57
+
58
+ private
59
+
60
+ def detect_base
61
+ head = Open3.capture3("git", "symbolic-ref", "--short", "refs/remotes/origin/HEAD", chdir: Dir.pwd)
62
+ return head[0].strip if head[2].success? && !head[0].strip.empty?
63
+ %w[origin/main origin/master main master].find do |ref|
64
+ Open3.capture3("git", "rev-parse", "--verify", "--quiet", ref, chdir: Dir.pwd)[2].success?
65
+ end or raise Error, "could not detect a base branch; pass --base"
66
+ end
67
+
68
+ def git(*args)
69
+ out, err, st = Open3.capture3("git", "-c", "core.quotepath=false", *args, chdir: @root || Dir.pwd)
70
+ raise Error, "git #{args.join(' ')} failed: #{err.strip}" unless st.success?
71
+ out
72
+ end
73
+
74
+ def load_files
75
+ result = {}
76
+ git("diff", "--name-status", "-M", merge_base).each_line do |line|
77
+ code, a, b = line.chomp.split("\t")
78
+ status = STATUS.fetch(code[0], :modified)
79
+ path = b || a
80
+ result[path] = FileDiff.new(path: path, status: status, old_path: (a if b))
81
+ end
82
+ parse_patch(git("diff", "--unified=0", "--no-color", "--no-ext-diff", "-M", merge_base), result)
83
+
84
+ git("ls-files", "--others", "--exclude-standard").each_line do |l|
85
+ path = l.chomp
86
+ fd = FileDiff.new(path: path, status: :added)
87
+ text = read(path)
88
+ text&.valid_encoding? && text.each_line.with_index(1) { |t, n| fd.added_lines << FileDiff::Line.new(n, t.chomp) }
89
+ result[path] = fd
90
+ end
91
+ result
92
+ end
93
+
94
+ def parse_patch(patch, result)
95
+ current = nil
96
+ old_n = new_n = 0
97
+ patch.each_line do |raw|
98
+ line = raw.chomp
99
+ case line
100
+ when /\Adiff --git /
101
+ current = nil
102
+ when %r{\A\+\+\+ b/(.+)}
103
+ current = result[$1]
104
+ when /\A@@ -(\d+)(?:,\d+)? \+(\d+)/
105
+ old_n, new_n = $1.to_i, $2.to_i
106
+ when /\A\+(?!\+\+ )/, /\A\+\+\+\z/
107
+ current&.added_lines&.push(FileDiff::Line.new(new_n, line[1..]))
108
+ new_n += 1
109
+ when /\A-(?!-- )/
110
+ current&.removed_lines&.push(FileDiff::Line.new(old_n, line[1..]))
111
+ old_n += 1
112
+ end
113
+ end
114
+ # deleted files have "+++ /dev/null"; attribute their removals via "--- a/path"
115
+ attribute_deletions(patch, result)
116
+ end
117
+
118
+ def attribute_deletions(patch, result)
119
+ result.each_value.select { |f| f.status == :deleted }.each do |fd|
120
+ text = read_base(fd.path) or next
121
+ text.each_line.with_index(1) { |t, n| fd.removed_lines << FileDiff::Line.new(n, t.chomp) } if fd.removed_lines.empty?
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,75 @@
1
+ require "fileutils"
2
+ require "json"
3
+ require "open3"
4
+
5
+ module Rumblestrip
6
+ # Installs gates that run `rumble` before `git commit` / `git push`.
7
+ #
8
+ # rumble install-hooks # git pre-commit + pre-push in .githooks/, sets core.hooksPath
9
+ # rumble install-hooks --claude # also a Claude Code PreToolUse hook in .claude/settings.json
10
+ class Hooks
11
+ GIT_HOOKS = %w[pre-commit pre-push].freeze
12
+ MARKER = "# installed by `rumble install-hooks`".freeze
13
+ CLAUDE_COMMAND_RE = /(\A|[;&|]|\s)git\s+(-C\s+\S+\s+)?(commit|push)\b/
14
+
15
+ def initialize(root:, out:, dir: ".githooks", claude: false, force: false)
16
+ @root, @out, @dir, @claude, @force = root, out, dir, claude, force
17
+ end
18
+
19
+ def install
20
+ install_git_hooks
21
+ install_claude_hook if @claude
22
+ 0
23
+ end
24
+
25
+ # The command the hooks should invoke: the project binstub when present, else the gem's `rumble`.
26
+ def rumble_cmd
27
+ File.executable?(File.join(@root, "bin", "rumble")) ? "bin/rumble" : "rumble"
28
+ end
29
+
30
+ private
31
+
32
+ def install_git_hooks
33
+ dir = File.join(@root, @dir)
34
+ FileUtils.mkdir_p(dir)
35
+ GIT_HOOKS.each do |name|
36
+ path = File.join(dir, name)
37
+ if File.exist?(path) && !@force && !File.read(path).include?(MARKER)
38
+ raise Error, "#{File.join(@dir, name)} exists and wasn't written by rumble; use --force to replace it"
39
+ end
40
+ File.write(path, git_hook_script(name))
41
+ File.chmod(0o755, path)
42
+ @out.puts "wrote #{File.join(@dir, name)}"
43
+ end
44
+ _, err, status = Open3.capture3("git", "config", "core.hooksPath", @dir, chdir: @root)
45
+ raise Error, "git config core.hooksPath failed: #{err.strip}" unless status.success?
46
+ @out.puts "set core.hooksPath=#{@dir} (other clones: git config core.hooksPath #{@dir})"
47
+ end
48
+
49
+ def git_hook_script(name)
50
+ <<~SH
51
+ #!/usr/bin/env bash
52
+ #{MARKER}
53
+ # Blocks `git #{name.sub("pre-", "")}` while any strip fails. Bypass with RUMBLE_SKIP=1.
54
+ [ -n "$RUMBLE_SKIP" ] && exit 0
55
+ cd "$(git rev-parse --show-toplevel)" || exit 1
56
+ exec #{rumble_cmd} -q
57
+ SH
58
+ end
59
+
60
+ def install_claude_hook
61
+ path = File.join(@root, ".claude", "settings.json")
62
+ FileUtils.mkdir_p(File.dirname(path))
63
+ settings = File.exist?(path) ? JSON.parse(File.read(path)) : {}
64
+ command = rumble_cmd == "rumble" ? "rumble gate" : "\"$CLAUDE_PROJECT_DIR\"/#{rumble_cmd} gate"
65
+ entries = ((settings["hooks"] ||= {})["PreToolUse"] ||= [])
66
+ if entries.any? { |e| Array(e["hooks"]).any? { |h| h["command"].to_s.end_with?("rumble gate") } }
67
+ @out.puts ".claude/settings.json already has the rumble gate"
68
+ return
69
+ end
70
+ entries << { "matcher" => "Bash", "hooks" => [{ "type" => "command", "command" => command }] }
71
+ File.write(path, JSON.pretty_generate(settings) + "\n")
72
+ @out.puts "added PreToolUse gate to .claude/settings.json"
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,61 @@
1
+ require "json"
2
+
3
+ module Rumblestrip
4
+ class Reporter
5
+ STYLE = {
6
+ fail: ["\e[31m", "FAIL", "✖"],
7
+ warn: ["\e[33m", "WARN", "▲"],
8
+ message: ["\e[36m", "NOTE", "•"]
9
+ }.freeze
10
+
11
+ def initialize(io: $stdout, color: io.respond_to?(:tty?) && io.tty?, quiet: false)
12
+ @io, @color, @quiet = io, color, quiet
13
+ end
14
+
15
+ def report(result, diff)
16
+ all = result.findings
17
+ shown = @quiet ? all.select { |f| f.severity == :fail } : all
18
+ @io.puts paint("\e[1m", "Rumblestrip — #{diff.paths.size} changed file(s) vs #{diff.base}")
19
+ shown.group_by(&:strip).each do |name, fs|
20
+ team = fs.first.team
21
+ @io.puts "\n#{paint("\e[1m", name)}#{team ? paint("\e[2m", " #{team}") : ''}"
22
+ fs.each do |f|
23
+ color, label, icon = STYLE[f.severity]
24
+ where = f.file ? " (#{f.file}#{":#{f.line}" if f.line})" : ""
25
+ @io.puts " #{paint(color, "#{icon} #{label}")} #{f.message}#{paint("\e[2m", where)}"
26
+ end
27
+ end
28
+ counts = %i[fail warn message].to_h { |s| [s, all.count { |f| f.severity == s }] }
29
+ @io.puts "\n#{result.ran.size} strip(s) ran, #{result.skipped.size} skipped: " \
30
+ "#{counts[:fail]} failure(s), #{counts[:warn]} warning(s), #{counts[:message]} note(s)"
31
+ end
32
+
33
+ private
34
+
35
+ def paint(code, text) = @color ? "#{code}#{text}\e[0m" : text
36
+ end
37
+
38
+ # One JSON document on stdout (after the banner line).
39
+ class JsonReporter
40
+ def initialize(io: $stdout)
41
+ @io = io
42
+ end
43
+
44
+ def report(result, diff)
45
+ counts = %i[fail warn message].to_h { |s| [s, result.findings.count { |f| f.severity == s }] }
46
+ @io.puts JSON.pretty_generate(
47
+ version: VERSION,
48
+ passed: !result.failed?,
49
+ base: diff.base,
50
+ merge_base: diff.merge_base,
51
+ changed_files: diff.files.transform_values { |f| f.status.to_s },
52
+ summary: counts.merge(ran: result.ran.size, skipped: result.skipped.size),
53
+ ran: result.ran.map { |s| { name: s.name, team: s.team } },
54
+ skipped: result.skipped.map { |s| { name: s.name, team: s.team } },
55
+ findings: result.findings.map do |f|
56
+ { severity: f.severity.to_s, strip: f.strip, team: f.team, message: f.message, file: f.file, line: f.line }
57
+ end
58
+ )
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,39 @@
1
+ module Rumblestrip
2
+ # Evaluates a Rumblefile and collects its strips.
3
+ #
4
+ # strip "name", team: "@org/team" do ... end
5
+ # team "@org/team" do strip("name") { ... } end
6
+ class Rumblefile
7
+ attr_reader :strips, :helper_modules
8
+
9
+ def self.load(path)
10
+ raise Error, "no Rumblefile at #{path}" unless File.file?(path)
11
+ rf = new
12
+ rf.instance_eval(File.read(path), path, 1)
13
+ rf
14
+ end
15
+
16
+ def initialize
17
+ @strips = []
18
+ @helper_modules = []
19
+ @current_team = nil
20
+ end
21
+
22
+ def strip(name, team: @current_team, &block)
23
+ raise Error, "strip #{name.inspect} needs a block" unless block
24
+ @strips << Strip.new(name: name, team: team, block: block, source_line: block.source_location&.last)
25
+ end
26
+
27
+ # Methods defined here are available inside every strip.
28
+ def helpers(&block)
29
+ @helper_modules << Module.new(&block)
30
+ end
31
+
32
+ def team(name)
33
+ prev, @current_team = @current_team, name
34
+ yield
35
+ ensure
36
+ @current_team = prev
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ module Rumblestrip
2
+ Result = Struct.new(:findings, :ran, :skipped, keyword_init: true) do
3
+ def failed? = findings.any? { |f| f.severity == :fail }
4
+ end
5
+
6
+ class Runner
7
+ def initialize(rumblefile:, diff:, codeowners:, team: nil)
8
+ @rumblefile, @diff, @codeowners, @team = rumblefile, diff, codeowners, team
9
+ end
10
+
11
+ def run
12
+ findings, ran, skipped = [], [], []
13
+ @rumblefile.strips.each do |strip|
14
+ if strip.team && @codeowners.nil?
15
+ raise Error, "strip #{strip.name.inspect} is scoped to #{strip.team} but no CODEOWNERS file was found"
16
+ end
17
+ next skipped << strip if @team && strip.team != @team
18
+
19
+ ctx = Context.new(strip: strip, diff: @diff, codeowners: @codeowners)
20
+ # A team-scoped strip with nothing of theirs changed has nothing to say.
21
+ next skipped << strip if strip.team && ctx.changed_files.empty? && ctx.deleted_files.empty?
22
+
23
+ @rumblefile.helper_modules.each { |m| ctx.extend(m) }
24
+ begin
25
+ ctx.instance_exec(&strip.block)
26
+ rescue StandardError => e
27
+ ctx.fail("strip raised #{e.class}: #{e.message}")
28
+ end
29
+ ran << strip
30
+ findings.concat(ctx.findings)
31
+ end
32
+ Result.new(findings: findings, ran: ran, skipped: skipped)
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,5 @@
1
+ module Rumblestrip
2
+ Strip = Struct.new(:name, :team, :block, :source_line, keyword_init: true)
3
+
4
+ Finding = Struct.new(:severity, :message, :strip, :team, :file, :line, keyword_init: true)
5
+ end
@@ -0,0 +1,3 @@
1
+ module Rumblestrip
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,14 @@
1
+ require_relative "rumblestrip/version"
2
+ require_relative "rumblestrip/codeowners"
3
+ require_relative "rumblestrip/diff"
4
+ require_relative "rumblestrip/strip"
5
+ require_relative "rumblestrip/context"
6
+ require_relative "rumblestrip/rumblefile"
7
+ require_relative "rumblestrip/runner"
8
+ require_relative "rumblestrip/reporter"
9
+ require_relative "rumblestrip/hooks"
10
+ require_relative "rumblestrip/cli"
11
+
12
+ module Rumblestrip
13
+ class Error < StandardError; end
14
+ end
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rumblestrip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Chandler
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-12-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Write Strips in a Rumblefile that inspect what changed on your branch
14
+ and warn or fail on heuristic rules, scoped to the teams in CODEOWNERS.
15
+ email:
16
+ executables:
17
+ - rumble
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - examples/Rumblefile
24
+ - exe/rumble
25
+ - lib/rumblestrip.rb
26
+ - lib/rumblestrip/cli.rb
27
+ - lib/rumblestrip/codeowners.rb
28
+ - lib/rumblestrip/context.rb
29
+ - lib/rumblestrip/diff.rb
30
+ - lib/rumblestrip/hooks.rb
31
+ - lib/rumblestrip/reporter.rb
32
+ - lib/rumblestrip/rumblefile.rb
33
+ - lib/rumblestrip/runner.rb
34
+ - lib/rumblestrip/strip.rb
35
+ - lib/rumblestrip/version.rb
36
+ homepage: https://github.com/developingchris/rumblestrip-rb
37
+ licenses:
38
+ - MIT
39
+ metadata:
40
+ homepage_uri: https://github.com/developingchris/rumblestrip-rb
41
+ source_code_uri: https://github.com/developingchris/rumblestrip-rb
42
+ rubygems_mfa_required: 'true'
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: '3.0'
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubygems_version: 3.5.22
59
+ signing_key:
60
+ specification_version: 4
61
+ summary: Local, CODEOWNERS-aware diff linter inspired by Danger
62
+ test_files: []