-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcu~
executable file
·97 lines (73 loc) · 1.82 KB
/
cu~
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/usr/bin/env ruby
# "Checked upload" - run validations before uploading branch to git
require 'rainbow'
module Plugins
def self.rubocop
rubies = Cu.changes.select { |x| x.end_with? ".rb" }
return unless !rubies.empty?
system("bundle exec rubocop -D --auto-correct #{rubies.join(' ')}")
end
def self.consolidate_lines
system("filter_lines.py #{Cu.changes.join(' ')}")
true
end
def self.run_all_tests
system("cd #{Cu.gitroot} && RAILS_ENV=test bundle exec rspec")
end
end
def enable(plugin)
Cu.plugins_enabled[plugin] = true
end
def disable(plugin)
Cu.plugins_enabled[plugin] = false
end
module Cu
def self.plugins_enabled
@plugins_enabled ||= {
rubocop: true,
consolidate_lines: true
}
end
def self.has_diff
!`git diff HEAD`.strip.empty?
end
def self.changes
@changes ||= `changed-not-deleted`.split.map(&:strip).reject { |x| x.include? '.-jooq/' }.reject { |x| x.begin_with? 'doc/' }
end
def self.actually_push
system("git push -uf")
end
def self.branch
`branch`.strip
end
def self.bad(s)
puts Rainbow(s).bright.red
exit 1
end
def self.gitroot
`git rev-parse --show-toplevel`.strip
end
def self.rcfile
gitroot + "/curc.rb"
end
def self.main
load rcfile if File.exist?(rcfile)
if branch == "master"
bad "Don't push on master"
end
if has_diff
bad "Please commit your changes before pushing."
end
plugins_enabled.each do |plugin, enabled|
next unless enabled
puts Rainbow("Running #{plugin}").bright.blue
bad "Plugin failed: #{plugin}" unless Plugins.send(plugin)
end
if has_diff
bad "Plugins have made changes. Please commit or amend accordingly."
end
puts Rainbow("Uploading to git").bright.green
actually_push
end
end
Cu.main