-
Notifications
You must be signed in to change notification settings - Fork 11
/
runner.rb
44 lines (36 loc) · 895 Bytes
/
runner.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
require 'ostruct'
module Poper
class Runner
def initialize(commit, repo_path = '.')
@repo = Rugged::Repository.new(repo_path)
oid = @repo.rev_parse_oid(commit)
@commit = @repo.lookup(oid)
end
def run
commits.flat_map { |c| check(c) }.compact
end
private
def check(commit)
rules.map do |rule|
result = rule.check(commit.message)
OpenStruct.new(commit: commit.oid, message: result) if result
end
end
def rules
Rule::Rule.all.map do |rule_klass|
rule = rule_klass.new
rule if rule.enabled?
end.compact
end
def commits
@commits ||= begin
walker.reset
walker.push(@repo.last_commit.oid)
walker.take_while { |c| c.oid != @commit.oid } << @commit
end
end
def walker
@walker ||= Rugged::Walker.new(@repo)
end
end
end