rbtils 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/command.rb +179 -0
- data/lib/config.rb +52 -0
- data/lib/configs/coffeelint.json +116 -0
- data/lib/constants.rb +15 -0
- data/lib/controller.rb +127 -0
- data/lib/controllers/branch.rb +14 -0
- data/lib/controllers/clean.rb +10 -0
- data/lib/controllers/hound.rb +72 -0
- data/lib/controllers/minify.rb +40 -0
- data/lib/controllers/open.rb +58 -0
- data/lib/controllers/update.rb +41 -0
- data/lib/helper.rb +19 -0
- data/lib/helpers/time.rb +28 -0
- data/lib/log.rb +111 -0
- data/lib/logs.rb +34 -0
- data/lib/model.rb +26 -0
- data/lib/model_data.rb +97 -0
- data/lib/models/hound.rb +232 -0
- data/lib/request.rb +20 -0
- data/lib/router.rb +73 -0
- data/lib/utils.rb +123 -0
- metadata +64 -0
@@ -0,0 +1,14 @@
|
|
1
|
+
module Granify
|
2
|
+
module Controller
|
3
|
+
class Branch < Controller::Base
|
4
|
+
def current
|
5
|
+
Notify.info("Current branch: #{Command::Exec.git_current_branch}")
|
6
|
+
end
|
7
|
+
|
8
|
+
def recent
|
9
|
+
# TODO: format this
|
10
|
+
Notify.spit Command::Exec.global("git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname)' refs/heads refs/remotes --count=10")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module Granify
|
2
|
+
module Controller
|
3
|
+
class Hound < Controller::Base
|
4
|
+
def coffee
|
5
|
+
m = @model.data
|
6
|
+
|
7
|
+
if m.below_acceptable_limit?
|
8
|
+
Notify.info("Linting #{m.status[:total]} coffeescript files\nPrinting files with errors")
|
9
|
+
|
10
|
+
m.files_with_errors.each do |file|
|
11
|
+
Notify.spit(file)
|
12
|
+
end
|
13
|
+
|
14
|
+
success_message(m)
|
15
|
+
else
|
16
|
+
if m.log.exists?
|
17
|
+
@model.command.open_editor(m.log)
|
18
|
+
end
|
19
|
+
|
20
|
+
error_message(m, :coffeescript)
|
21
|
+
end
|
22
|
+
|
23
|
+
Notify.bubble("Running coffeescript files through coffeelint", "Linting...")
|
24
|
+
end
|
25
|
+
|
26
|
+
def widgets
|
27
|
+
m = @model.data
|
28
|
+
|
29
|
+
if m.below_acceptable_limit?
|
30
|
+
Notify.info("Linting #{m.status[:total]} coffeescript files\nPrinting files with errors")
|
31
|
+
|
32
|
+
m.files_with_errors.each do |file|
|
33
|
+
Notify.spit(file)
|
34
|
+
end
|
35
|
+
|
36
|
+
success_message(m)
|
37
|
+
else
|
38
|
+
if m.log.exists?
|
39
|
+
@model.command.open_editor(m.log)
|
40
|
+
end
|
41
|
+
|
42
|
+
error_message(m, :coffeescript)
|
43
|
+
end
|
44
|
+
|
45
|
+
Notify.bubble("Running coffeescript files through coffeelint", "Linting...")
|
46
|
+
end
|
47
|
+
|
48
|
+
def ruby
|
49
|
+
m = @model.data
|
50
|
+
|
51
|
+
if m.below_acceptable_limit?
|
52
|
+
Notify.info("Pass rate is above the acceptable limit, proceeding to next step")
|
53
|
+
else
|
54
|
+
error_message(m, :ruby)
|
55
|
+
end
|
56
|
+
|
57
|
+
Notify.bubble("Running ruby files through rubocop.", "Linting...")
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
def error_message(m, type)
|
62
|
+
post_exec
|
63
|
+
Notify.warning("#{m.issues[:errors]} error(s), #{m.status[:errors_per_file]} EPF - EPF must be less than 5\n#{m.success_rate[:str]} success rate - 90% required")
|
64
|
+
Notify.error("Too many #{type} errors to continue. Errors logged to:\n#{m.log}")
|
65
|
+
end
|
66
|
+
|
67
|
+
def success_message(m)
|
68
|
+
Notify.spit("\nResults:\n - #{Style.format(m.status[:success].to_s + " passed", :green)}\n - #{Style.format(m.status[:error].to_s + " failed", :red)}\nSuccess rate: #{Style.format(m.success_rate[:str], :green)}\nErrors logged to #{Style.format(m.log, :green)}")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Granify
|
2
|
+
module Controller
|
3
|
+
class Minify < Controller::Base
|
4
|
+
# Purpose: minify all JS files in the current directory, move them to a
|
5
|
+
# min directory and rename them file.min.js
|
6
|
+
@@folder = :min
|
7
|
+
|
8
|
+
# We don't need to clean logs here
|
9
|
+
def post_exec
|
10
|
+
false
|
11
|
+
end
|
12
|
+
|
13
|
+
def all
|
14
|
+
# future method
|
15
|
+
Notify.warning("Method not implemented")
|
16
|
+
end
|
17
|
+
|
18
|
+
def js
|
19
|
+
min_folder = Utils.mklocaldir(@@folder)
|
20
|
+
files = Utils.get_files(:js)
|
21
|
+
command = Command::Exec.new
|
22
|
+
|
23
|
+
if files.size > 0
|
24
|
+
files.each do |file|
|
25
|
+
command.minify(file, min_folder)
|
26
|
+
end
|
27
|
+
|
28
|
+
Notify.bubble("Minified #{files.size} files.", "Success")
|
29
|
+
else
|
30
|
+
Notify.warning("No JS files detected in this directory")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def cs
|
35
|
+
# future method
|
36
|
+
Notify.warning("Method not implemented")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module Granify
|
2
|
+
module Controller
|
3
|
+
class Open < Controller::Base
|
4
|
+
def files
|
5
|
+
begin
|
6
|
+
files = []
|
7
|
+
|
8
|
+
if !$request.custom.nil? && $request.custom.size > 0
|
9
|
+
# pull file list from CLI args
|
10
|
+
$request.custom.each do |requested_file|
|
11
|
+
files.push(requested_file) if File.exists? requested_file.to_s
|
12
|
+
end
|
13
|
+
else
|
14
|
+
raise ::ArgumentError, "Command requires a list of files to open\ni.e. #{Granify::PACKAGE_NAME} open files file1.ext file2.ext file3.ext"
|
15
|
+
end
|
16
|
+
|
17
|
+
# we have some files, lets open them
|
18
|
+
if files.size > 0
|
19
|
+
`$EDITOR -n #{files.join(' ')}`
|
20
|
+
|
21
|
+
Notify.success("Opened #{files.size} file(s) in sublime text")
|
22
|
+
else
|
23
|
+
Notify.warning("The requested files (#{$request.custom.join(', ')}) could not be opened")
|
24
|
+
end
|
25
|
+
|
26
|
+
rescue => e
|
27
|
+
Notify.error(e.message)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def files_from_log
|
32
|
+
begin
|
33
|
+
files = []
|
34
|
+
|
35
|
+
if File.exists? $request.custom[0].to_s
|
36
|
+
# pull file list from a log file
|
37
|
+
files = IO.readlines($request.custom[0].to_s)
|
38
|
+
files.each do |l|
|
39
|
+
l.gsub!(/\r\n?/, "")
|
40
|
+
end
|
41
|
+
else
|
42
|
+
raise ::ArgumentError, "Command requires a log file\ni.e. #{Granify::PACKAGE_NAME} open files_from_log file1.log"
|
43
|
+
end
|
44
|
+
|
45
|
+
if files.size > 0
|
46
|
+
`$EDITOR -n #{files.join(' ')}`
|
47
|
+
|
48
|
+
Notify.success("Opened #{files.size} file(s) in sublime text")
|
49
|
+
else
|
50
|
+
Notify.warning("The requested files (#{$request.custom.join(', ')}) could not be opened")
|
51
|
+
end
|
52
|
+
rescue => e
|
53
|
+
Notify.error(e.message)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Granify
|
2
|
+
module Controller
|
3
|
+
class Update < Controller::Base
|
4
|
+
# Setup all flags supported by this command
|
5
|
+
def pre_exec
|
6
|
+
# flag methods that require internet access
|
7
|
+
@methods_require_internet.push(:rbtils)
|
8
|
+
|
9
|
+
super
|
10
|
+
end
|
11
|
+
|
12
|
+
def rbtils
|
13
|
+
Notify.info("Checking for updates")
|
14
|
+
|
15
|
+
status = Command::Exec.global("(cd #{Granify::INSTALLED_DIR} && git checkout master && git pull) 2>&1").split("\n")
|
16
|
+
|
17
|
+
if status.include? "Your branch is up-to-date with 'origin/master'."
|
18
|
+
Notify.warning("You are running the current version of #{Granify::PACKAGE_NAME}")
|
19
|
+
else
|
20
|
+
# TODO: run on a different machine, currently this just assumes it worked..
|
21
|
+
Notify.success("Successfully updated to the latest version")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def granify
|
26
|
+
Notify.info("Checking for updates")
|
27
|
+
|
28
|
+
status = @model.command.arbitrary("git checkout master && git pull")
|
29
|
+
puts status.inspect
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
|
33
|
+
def goliath
|
34
|
+
Notify.info("Checking for updates")
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
module Granify
|
2
|
+
module Helper
|
3
|
+
def self.load(klass, args = nil)
|
4
|
+
begin
|
5
|
+
klass_instance = Granify::Helper.const_get(klass.capitalize)
|
6
|
+
|
7
|
+
if klass_instance
|
8
|
+
if args.nil?
|
9
|
+
klass_instance.new
|
10
|
+
else
|
11
|
+
klass_instance.new(args)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
rescue => e
|
15
|
+
Notify.error(e.message)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
data/lib/helpers/time.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
module Granify
|
2
|
+
module Helper
|
3
|
+
class Time
|
4
|
+
def self.human_readable(start, finish)
|
5
|
+
seconds = finish.to_f - start.to_f
|
6
|
+
|
7
|
+
if seconds < 60
|
8
|
+
"No time at all!"
|
9
|
+
else
|
10
|
+
minutes = (seconds / 60).round(1)
|
11
|
+
if minutes < 1
|
12
|
+
"#{minutes} minute"
|
13
|
+
else
|
14
|
+
"#{minutes} minutes"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.formatted(time = nil)
|
20
|
+
if time.nil?
|
21
|
+
time = ::Time.now
|
22
|
+
end
|
23
|
+
|
24
|
+
time.strftime("%e/%-m/%Y @ %I:%M:%S%P")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/log.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
module Granify
|
2
|
+
class Log
|
3
|
+
attr_accessor :path, :total_files_processed
|
4
|
+
attr_reader :template
|
5
|
+
|
6
|
+
def initialize(*args)
|
7
|
+
if args.length == 0
|
8
|
+
# default log
|
9
|
+
@template = "#{Granify::LOG_DIR}/%s"
|
10
|
+
@path = sprintf(@template, "default.log")
|
11
|
+
else
|
12
|
+
@template = "#{Granify::LOG_DIR}/%s/%s-%s.log"
|
13
|
+
|
14
|
+
format(args)
|
15
|
+
end
|
16
|
+
|
17
|
+
@path
|
18
|
+
end
|
19
|
+
|
20
|
+
def stale?
|
21
|
+
Time.now - last_write > 60
|
22
|
+
end
|
23
|
+
|
24
|
+
def exists?
|
25
|
+
File.exist? @path
|
26
|
+
end
|
27
|
+
|
28
|
+
def delete
|
29
|
+
if exists?
|
30
|
+
File.delete @path
|
31
|
+
end
|
32
|
+
|
33
|
+
Notify.sinfo("Deleting truncated log file #{@path}")
|
34
|
+
@path = nil
|
35
|
+
end
|
36
|
+
|
37
|
+
def num_lines
|
38
|
+
File.foreach(@path).inject(0) {|c, line| c+1}
|
39
|
+
end
|
40
|
+
|
41
|
+
def faults
|
42
|
+
matchdata = { :errors => 0, :warnings => 0, :total => 0 }
|
43
|
+
|
44
|
+
begin
|
45
|
+
case @log_type
|
46
|
+
when :js
|
47
|
+
last_line = IO.readlines(@path)[-5].chomp
|
48
|
+
matches = last_line.match(/(\d+) example, (\d+) failure/)
|
49
|
+
|
50
|
+
if matches
|
51
|
+
matchdata[:errors] += matches[2].to_i
|
52
|
+
end
|
53
|
+
when :coffeelint
|
54
|
+
total = 0
|
55
|
+
File.foreach(@path) do |line|
|
56
|
+
matches = line.match(/Lint\! » (\d+) errors and (\d+)/)
|
57
|
+
|
58
|
+
if matches
|
59
|
+
matchdata[:errors] += matches[1].to_i
|
60
|
+
matchdata[:warnings] += matches[2].to_i
|
61
|
+
end
|
62
|
+
end
|
63
|
+
when :ruby
|
64
|
+
last_line = IO.readlines(@path)[-1].chomp
|
65
|
+
matches = last_line.match(/(\d+) files inspected\, (\d+)/)
|
66
|
+
|
67
|
+
if matches
|
68
|
+
matchdata[:errors] += matches[2].to_i
|
69
|
+
matchdata[:total] += matches[1].to_i
|
70
|
+
end
|
71
|
+
when :goliath
|
72
|
+
|
73
|
+
else
|
74
|
+
raise ArgumentError, "Unknown log type - #{log_type}"
|
75
|
+
end
|
76
|
+
rescue => e
|
77
|
+
Notify.error(e.message)
|
78
|
+
end
|
79
|
+
|
80
|
+
matchdata
|
81
|
+
end
|
82
|
+
|
83
|
+
def to_s
|
84
|
+
@path
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
def format(args)
|
89
|
+
@identifier = args[2]
|
90
|
+
|
91
|
+
@path = sprintf(@template,
|
92
|
+
@identifier,
|
93
|
+
args[0],
|
94
|
+
args[1].strftime('%Y-%m-%d-%T')
|
95
|
+
)
|
96
|
+
|
97
|
+
if !File.exists? @path
|
98
|
+
Utils.generate_path(args[0], args[1].strftime('%Y-%m-%d-%T'), @identifier)
|
99
|
+
end
|
100
|
+
|
101
|
+
# create the log file, populate it with temporary data
|
102
|
+
File.open(@path, 'w+') do |f|
|
103
|
+
f.write("Command output will be logged below when it finishes running\n")
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def last_write
|
108
|
+
File.mtime(@path)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
data/lib/logs.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module Granify
|
2
|
+
class Logs
|
3
|
+
MAX_LOGS_TO_STORE = 30
|
4
|
+
|
5
|
+
@files = Dir["#{Granify::LOG_DIR}/*/*.log"]
|
6
|
+
|
7
|
+
def self.clean
|
8
|
+
if @files.size > 0
|
9
|
+
@files.each do |file|
|
10
|
+
File.delete file if File.exist? file
|
11
|
+
end
|
12
|
+
Notify.info("Removed #{@files.size} old log files")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.dirty?
|
17
|
+
@files.size >= MAX_LOGS_TO_STORE
|
18
|
+
end
|
19
|
+
|
20
|
+
# Create a directory if required
|
21
|
+
def self.mkdir(name)
|
22
|
+
dir = "#{Granify::LOG_DIR}/#{name.downcase}"
|
23
|
+
|
24
|
+
if !Dir.exist? dir
|
25
|
+
Dir.mkdir dir
|
26
|
+
end
|
27
|
+
|
28
|
+
# Create the default .gitignore
|
29
|
+
File.open("#{dir}/.gitignore", "w+") do |file|
|
30
|
+
file.write "# Ignore everything in this directory\n*\n# Except this file\n!.gitignore"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/model.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Granify
|
2
|
+
module Model
|
3
|
+
class Base
|
4
|
+
attr_accessor :data, :branch, :browser, :command, :start
|
5
|
+
|
6
|
+
def initialize(hash = nil)
|
7
|
+
@data = hash || Granify::Model::Data.new
|
8
|
+
|
9
|
+
# Current time
|
10
|
+
#@time = @data.start
|
11
|
+
# Time the command was executed
|
12
|
+
@start = Time.now
|
13
|
+
# Current working branch
|
14
|
+
@branch = @data.branch
|
15
|
+
# Browser to execute tests in
|
16
|
+
@browser = @data.browser
|
17
|
+
# Instantiate the command execution class
|
18
|
+
@command = Command::Exec.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def bind(hash)
|
22
|
+
initialize(hash)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|