renegade 0.0.1 → 0.1.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8c09d76b3772341edb686aa03d38a52e19238dea
4
- data.tar.gz: 9e0de2e4875e0fe195b221d93f29cff4f5d627ac
3
+ metadata.gz: ade5a344f1baff35eaaaadd7d0c7145d69eae41a
4
+ data.tar.gz: a9a9d80519950b55b9ba777ea6ca8cdf50e40bee
5
5
  SHA512:
6
- metadata.gz: c46c989263eea8273c6575f74e6ae49186ecfd71ba0319a03b96807d064ac30b8aa7cf468707fd6610517ef309b4cee69a18d750fbf05cf46a3d42849ad790f6
7
- data.tar.gz: 03353292c31d715db1aed2430756c1d780ceeeed6ee4b8257ef0f2fd6c711fce6c8b3b0a0b1a4f826291b96536eb8ed9c35e016f75c6de96d1610743ba5d89d1
6
+ metadata.gz: 5ecd738fff4c3c4641e8b7247ab94abf4b03381c7a044a8b31eb362a10b34134b147f74fd766f30fc01ad8dded1e6432dfa9724536a949267e5e78f4af97be86
7
+ data.tar.gz: b85a93764724822c908c8eda2842f7840b725536541a7e9decc26b90887a8a272dc169cb366a9e1b4e8bba73ffaf9a3c026b47f0dae360f8481519d621dc0395
data/lib/renegade.rb CHANGED
@@ -1,7 +1,8 @@
1
- ##
2
- # Renegade module to run commit hooks
1
+ require 'renegade/version'
2
+
3
+ # Renegade module
3
4
  module Renegade
4
- def self.hello_world
5
- puts 'hello world'
6
- end
7
5
  end
6
+
7
+
8
+ puts 'renegade'
@@ -0,0 +1,40 @@
1
+ require 'renegade/status'
2
+
3
+ module Renegade
4
+ ##
5
+ # Verify branch name
6
+ class BranchName
7
+ attr_reader :errors, :warnings
8
+
9
+ REGEX_STORY_BRANCH = /^(?:story)-(\d{4,6})-?(.*)?$/
10
+ REGEX_BUG_BRANCH = /^(?:bug)-(\d{4,6})-?(.*)?$/
11
+
12
+ def initialize(label)
13
+ # Instance variables
14
+ @label = label
15
+ @warnings = []
16
+ @errors = []
17
+ end
18
+
19
+ def run
20
+ branch_name = `git name-rev --name-only HEAD`
21
+
22
+ Status.report(@label, check_branch_name(branch_name))
23
+ end
24
+
25
+ def check_branch_name(branch_name)
26
+ if REGEX_STORY_BRANCH.match(branch_name)
27
+ # placeholder
28
+ return true
29
+ elsif REGEX_BUG_BRANCH.match(branch_name)
30
+ # placeholder
31
+ return true
32
+ else
33
+ @warnings.push('Branches must start with bug-##### or story-#####.')
34
+ @warnings.push('You may continue to develop in this branch, but you'\
35
+ ' will not be allowed to merge unless you rename it.')
36
+ return false
37
+ end
38
+ end
39
+ end
40
+ end
@@ -1,22 +1,74 @@
1
- # require_relative 'status'
2
- #
3
- # module Renegade
4
- # ##
5
- # # Ensure commit messages meet certain requirements
6
- # class CommitMessage
7
- # def self.message_length(message)
8
- # min_length = 10
9
- # max_length = 50
10
- #
11
- # puts 'Renegade::CommitMessage.message_length'
12
- #
13
- # if message.length > min_length && message.length <= max_length
14
- # Renegade::Status.new.add_error('Commit messages should be between \
15
- # #{min_length} and #{max_length}')
16
- # false
17
- # else
18
- # true
19
- # end
20
- # end
21
- # end
22
- # end
1
+ require 'renegade/status'
2
+
3
+ module Renegade
4
+ # Check commit messages meet certain criteria
5
+ class CommitMessage
6
+ attr_reader :errors, :warnings
7
+
8
+ COMMIT_FORMAT = /^(?:(?:BugId: |Story: B+-|Epic: E-0)[1-9]\d* \| )(.*)/
9
+
10
+ def initialize(label)
11
+ # Instance variables
12
+ @label = label
13
+ @warnings = []
14
+ @errors = []
15
+
16
+ @min_length = 7
17
+ @max_length = 50
18
+ end
19
+
20
+ def run(message)
21
+ check_commit_message_format(message)
22
+ check_commit_message_non_ascii(message)
23
+ end
24
+
25
+ # Check message length
26
+ def check_commit_message_length(message)
27
+ check_label = 'Commit message length'
28
+
29
+ if message.length >= @min_length && message.length <= @max_length
30
+ Status.report(check_label, true)
31
+ else
32
+ @errors.push "Commit messages should be between #{@min_length} "\
33
+ "and #{@max_length} characters."
34
+ Status.report(check_label, false)
35
+ end
36
+ end
37
+
38
+ # Check commit message contains no non-ASCII characters
39
+ def check_commit_message_non_ascii(message)
40
+ check_label = 'Only ASCII characters'
41
+
42
+ if message.ascii_only?
43
+ Status.report(check_label, true)
44
+ else
45
+ Status.report(check_label, false)
46
+ @errors.push('Commit messages may not contain non-ASCII characters')
47
+ end
48
+ end
49
+
50
+ def check_commit_message_format_error
51
+ 'You must include a valid BugId, Story or Epic number.' + "\n"\
52
+ ' Examples:' + "\n"\
53
+ ' - BugId: 12345 | Helpful comment describing bug fix' + "\n"\
54
+ ' - Story: B-12345 | Helpful comment describing story' + "\n"\
55
+ ' - Epic: E-12345 | Epic comment'
56
+ end
57
+
58
+ # Check commit message contains no non-ASCII characters
59
+ def check_commit_message_format(message)
60
+ check_label = 'Includes a valid BugId, Story or Epic number'
61
+
62
+ matches = COMMIT_FORMAT.match(message)
63
+
64
+ if matches
65
+ Status.report(check_label, true)
66
+ check_commit_message_length(matches[1])
67
+ else
68
+ Status.report(check_label, false)
69
+ check_commit_message_length(message)
70
+ @errors.push(check_commit_message_format_error)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,33 @@
1
+ require 'open3'
2
+ require 'renegade/status'
3
+
4
+ module Renegade
5
+ ##
6
+ # Prevent merge artifacts from getting committed
7
+ class ConflictMarkers
8
+ attr_reader :errors, :warnings
9
+
10
+ def initialize(label)
11
+ # Instance variables
12
+ @label = label
13
+ @errors = []
14
+ end
15
+
16
+ def run
17
+ markers = `git diff-index --check --cached HEAD --`
18
+
19
+ check_markers(markers.chomp.strip)
20
+ end
21
+
22
+ def check_markers(markers)
23
+ check_label = 'No merge artifacts'
24
+
25
+ if markers == ''
26
+ Status.report(check_label, true)
27
+ else
28
+ Status.report(check_label, false)
29
+ @errors.push('Merge artifacts were found!' + "\n" + markers)
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,39 @@
1
+ module Renegade
2
+ ##
3
+ # Handle errors
4
+ class HandleErrors
5
+ # Handle errors if they exist
6
+ def self.handle_errors(errors)
7
+ if errors.size > 0
8
+ print_errors(errors)
9
+ exit 1
10
+ else
11
+ exit 0
12
+ end
13
+ end
14
+
15
+ def self.handle_warnings(warnings)
16
+ print_warnings(warnings) if warnings.size > 0
17
+ end
18
+
19
+ def self.print_errors(errors)
20
+ puts "\nErrors:"
21
+
22
+ errors.each do |error|
23
+ puts "- #{error}"
24
+ end
25
+
26
+ puts "\n"
27
+ end
28
+
29
+ def self.print_warnings(warnings)
30
+ puts "\nWarnings:"
31
+
32
+ warnings.each do |warning|
33
+ puts "- #{warning}"
34
+ end
35
+
36
+ puts "\n"
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,69 @@
1
+ require 'open3'
2
+ require 'renegade/status'
3
+
4
+ module Renegade
5
+ # Run linters
6
+ class Linters
7
+ attr_reader :errors
8
+
9
+ def initialize(label, extension, exec_command)
10
+ # Instance variables
11
+ @label = label
12
+ @extension = extension
13
+ @exec_command = exec_command
14
+ @errors = []
15
+ end
16
+
17
+ def run(files)
18
+ files = filter_files(files)
19
+ append_file_count(files)
20
+
21
+ # Only run check if there are relevant files being committed
22
+ if files.size == 0
23
+ Status.report(@label, true)
24
+ else
25
+ Status.report(@label, exec(files))
26
+ end
27
+ end
28
+
29
+ # Add the file count to the end of the label
30
+ def append_file_count(files)
31
+ file_size = files.size
32
+
33
+ if file_size == 0 || file_size > 1
34
+ @label = "#{@label} (#{file_size} files)"
35
+ else
36
+ @label = "#{@label} (1 file)"
37
+ end
38
+ end
39
+
40
+ def exec(files)
41
+ # http://stackoverflow.com/questions/690151/getting-output-of-system-calls-in-ruby
42
+ _stdin, stdout, stderr,
43
+ wait_thread = Open3.popen3(@exec_command, files.join(' '))
44
+
45
+ if wait_thread.value.exitstatus == 1
46
+ @errors.push(stdout.read)
47
+ end
48
+
49
+ stdout.gets(nil)
50
+ stdout.close
51
+ stderr.gets(nil)
52
+ stderr.close
53
+
54
+ wait_thread.value.exitstatus == 0
55
+ end
56
+
57
+ def filter_files(file_list)
58
+ filtered_files = []
59
+
60
+ file_list.each do |file|
61
+ if File.extname(file) == @extension
62
+ filtered_files.push(file)
63
+ end
64
+ end
65
+
66
+ filtered_files
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,36 @@
1
+ require 'renegade/handle_errors'
2
+ require 'renegade/status'
3
+ require 'renegade/linters'
4
+ require 'renegade/branch_name'
5
+ require 'renegade/conflict_markers'
6
+
7
+ module Renegade
8
+ # Run linters
9
+ class PreCommit
10
+ def initialize
11
+ Renegade::Status.hook_start('pre-commit')
12
+ # @scss_lint = Renegade::Linters.new('SCSS Lint', '.scss', 'scss-lint')
13
+ # @eslint = Renegade::Linters.new('ESLint', '.js', 'eslint')
14
+ @branch_name = Renegade::BranchName.new('Branch Name')
15
+ @conflict_markers = Renegade::ConflictMarkers.new('Conflict Markers')
16
+ # @protected_files = Renegade::ProtectedFiles.new('Protected Files')
17
+
18
+ run
19
+ end
20
+
21
+ def run
22
+ # @scss_lint.run
23
+ # @eslint.run
24
+ @branch_name.run
25
+ @conflict_markers.run
26
+ # @protected_files.run
27
+
28
+ Renegade::HandleErrors.handle_warnings(@branch_name.warnings)
29
+ Renegade::HandleErrors.handle_errors(@conflict_markers.errors)
30
+
31
+ # Renegade::HandleErrors.handle_errors(
32
+ # @scss_lint.errors + @eslint.errors +
33
+ # @branch_name.errors + @protected_files.errors)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,28 @@
1
+ require 'renegade/handle_errors'
2
+ require 'renegade/status'
3
+ require 'renegade/commit_message'
4
+
5
+ module Renegade
6
+ # Run linters
7
+ class PrepareCommitMessage
8
+ def initialize
9
+ Renegade::Status.hook_start('prepare-commit-msg')
10
+ run
11
+ end
12
+
13
+ def run
14
+ message_type = ARGV[1]
15
+
16
+ commit_message = Renegade::CommitMessage.new('Commit Message')
17
+
18
+ # Avoid checking merges
19
+ if message_type == 'message'
20
+ message_file = ARGV[0]
21
+ message = File.read(message_file)
22
+ commit_message.run(message)
23
+ end
24
+
25
+ Renegade::HandleErrors.handle_errors(commit_message.errors)
26
+ end
27
+ end
28
+ end
@@ -1,19 +1,30 @@
1
- # module Renegade
2
- # ##
3
- # # Handle errors
4
- # class Status
5
- # def initialize
6
- # @error_list = []
7
- # end
8
- #
9
- # def self.add_error(message)
10
- # @error_list.push(message)
11
- # end
12
- #
13
- # def self.print_errors
14
- # @error_list.each do |error|
15
- # puts error
16
- # end
17
- # end
18
- # end
19
- # end
1
+ # Add color options
2
+ class String
3
+ def red
4
+ "\e[31m#{self}\e[0m"
5
+ end
6
+
7
+ def green
8
+ "\e[32m#{self}\e[0m"
9
+ end
10
+ end
11
+
12
+ # Define string colors
13
+ module Renegade
14
+ ##
15
+ # Report statuses
16
+ class Status
17
+ # Report labels
18
+ def self.report(label, passed)
19
+ if passed
20
+ puts " √ #{label}".green
21
+ else
22
+ puts " × #{label}".red
23
+ end
24
+ end
25
+
26
+ def self.hook_start(hook)
27
+ puts "\nRunning #{hook} hooks…"
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,4 @@
1
+ # Renegade version
2
+ module Renegade
3
+ VERSION = '0.1.29'
4
+ end
metadata CHANGED
@@ -1,41 +1,75 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: renegade
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.29
5
5
  platform: ruby
6
6
  authors:
7
- - Rather Blue
7
+ - ratherblue
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2016-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: octokit
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '4.2'
20
- type: :runtime
19
+ version: '10.0'
20
+ type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '4.2'
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: minitest
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.35.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.35.1
27
55
  description: Gem description
28
- email: ratherblue@gmail.com
56
+ email:
57
+ - ratherblue@gmail.com
29
58
  executables: []
30
59
  extensions: []
31
60
  extra_rdoc_files: []
32
61
  files:
33
62
  - lib/renegade.rb
34
- - lib/renegade/checks/branch_names.rb
35
- - lib/renegade/checks/lint.rb
63
+ - lib/renegade/branch_name.rb
36
64
  - lib/renegade/commit_message.rb
65
+ - lib/renegade/conflict_markers.rb
66
+ - lib/renegade/handle_errors.rb
67
+ - lib/renegade/linters.rb
68
+ - lib/renegade/pre_commit.rb
69
+ - lib/renegade/prepare_commit_message.rb
37
70
  - lib/renegade/status.rb
38
- homepage: http://github.com/ratherblue/renegade
71
+ - lib/renegade/version.rb
72
+ homepage: https://github.com/ratherblue/renegade
39
73
  licenses:
40
74
  - Apache 2.0
41
75
  metadata: {}
@@ -1,20 +0,0 @@
1
- # module Renegade
2
- # ##
3
- # # Validate class names
4
- # class BranchNames
5
- # REGEX_STORY_BRANCH = /^(?:story)-(\d{4,6})?-?(.*)?$/
6
- # REGEX_BUG_BRANCH = /^(?:bug)-(\d{4,6})?-?(.*)?$/
7
- #
8
- # def self.check_branch_name(branch_name)
9
- # if REGEX_STORY_BRANCH.match(branch_name)
10
- # # placeholder
11
- # return true
12
- # elsif REGEX_BUG_BRANCH.match(branch_name)
13
- # # placeholder
14
- # return true
15
- # else
16
- # return false
17
- # end
18
- # end
19
- # end
20
- # end
@@ -1,15 +0,0 @@
1
- # module Renegade
2
- # ##
3
- # # This class handles running the various linters
4
- # class Lint
5
- # # run eslint
6
- # def self.eslint
7
- # true
8
- # end
9
- #
10
- # # run scss lint
11
- # def self.scsslint
12
- # true
13
- # end
14
- # end
15
- # end