safe_pusher 0.2.2 → 0.4.3

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
- SHA1:
3
- metadata.gz: 6f14a1f7069630411c76a8ec0c1a33f75f3b0d95
4
- data.tar.gz: c5b212741108b33951374c339fa888aa1215c94f
2
+ SHA256:
3
+ metadata.gz: b1d2d880ef780ab2b1ab6d8fc42f8281128383861044ae9af138ecce68cbf5d3
4
+ data.tar.gz: 211e95e60f85ed66e54976e6df94051088fbd2762ba53829d2b30344cdec6d36
5
5
  SHA512:
6
- metadata.gz: dc2fa8785c5401f0b47db636e874a4cc9a3b0ed3355633ab3c7aa89df5ddd2228e7bd76177bf85a0fdcab5a79003c956ac3099d4b255bdcd0eafde3284e6ea83
7
- data.tar.gz: '02567809eba97e24af3b0ee8fac29bc9b407696ac07896cf763d3527582e191629d1a0580e0371377166bf7bda0502d9fb9c6f3f57463bf65faf0c832db06226'
6
+ metadata.gz: 299bb588f9c935165dd133845437d834c3371ebfbc9c288370981f3050621e62b04c8604c261509302609b4900cec3cf5c4db7be7838332c13091d359e2b50bd
7
+ data.tar.gz: f15e6eebe00dd93bf08105ecf710af9d1fcadc31fb9e789ceb687329ddad6b36dea7545d6dc59ebb0bb4d1e83b154f394750862ce833e2f77cbde6dfe15a9de1
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Desktop (please complete the following information):**
27
+ - OS: [e.g. iOS]
28
+ - Browser [e.g. chrome, safari]
29
+ - Version [e.g. 22]
30
+
31
+ **Smartphone (please complete the following information):**
32
+ - Device: [e.g. iPhone6]
33
+ - OS: [e.g. iOS8.1]
34
+ - Browser [e.g. stock browser, safari]
35
+ - Version [e.g. 22]
36
+
37
+ **Additional context**
38
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -63,10 +63,11 @@ Documentation:
63
63
  # Do not verify the length of the blocks in DSLs.
64
64
  Metrics/BlockLength:
65
65
  Exclude:
66
- - "**/*/spec/**/*"
66
+ - spec/**/*
67
67
  - lib/tasks/**/*
68
68
  - app/admin/**/*
69
69
  - config/routes.rb
70
+ - safe_pusher.gemspec
70
71
  ExcludedMethods:
71
72
  - included
72
73
 
@@ -136,27 +137,3 @@ Style/FormatStringToken:
136
137
  # Prefer `->` to `lambda`.
137
138
  Style/Lambda:
138
139
  EnforcedStyle: literal
139
-
140
- # Deactivate rule that makes `lambda` mandatory in defavor of `->`
141
- # when having blocks.
142
- Style/Lambda:
143
- Enabled: false
144
-
145
- # Do not verify empty lines around blocks in specs
146
- Layout/EmptyLinesAroundBlockBody:
147
- Exclude:
148
- - spec/**/*
149
-
150
- # Allow using normal test doubles, since they are useful for mocking.
151
- # See https://github.com/KissKissBankBank/fashion_police/pull/34
152
- RSpec/VerifiedDoubles:
153
- Enabled: false
154
-
155
- # Enable long blocs for Gemspec files
156
- Metrics/BlockLength:
157
- Exclude:
158
- - safe_pusher.gemspec
159
-
160
- Metrics/BlockLength:
161
- Exclude:
162
- - spec/**/*
@@ -2,6 +2,30 @@
2
2
 
3
3
  This project adheres to [Semantic Versioning](http://semver.org)
4
4
 
5
+ ## [0.4.3] - 2021-02-01
6
+ Fix:
7
+ - Do not erase the app locales files.
8
+
9
+ ## [0.4.2] - 2020-08-28
10
+ Fix:
11
+ - Do not inject the locales files directly in the load path but add them instead.
12
+
13
+ ## [0.4.1] - 2019-12-04
14
+ Improvement:
15
+ - Generate the folder of a spec, if not already existing
16
+
17
+ ## [0.4.0] - 2019-11-29
18
+ Features:
19
+ - Add `add`, `commit` and `amend` commands to the cli
20
+
21
+ ## [0.3.0] - 2019-09-30
22
+ Improvement:
23
+ - Reduce RSpec runner verbosity
24
+ - Allow configuring the base branch
25
+
26
+ Fix:
27
+ - Add `--version` to the CLI
28
+
5
29
  ## [0.2.2] - 2019-01-05
6
30
  Improvements:
7
31
  - Removing thor
@@ -0,0 +1,33 @@
1
+ # Contributing
2
+
3
+ You can easily add a new client, or a new command.
4
+
5
+ ## To add a client
6
+ - create the client api under lib/safe_pusher/client/***.rb
7
+ - require it in lib/safe_pusher.rb
8
+ - write the specs for your client, then submit a PR
9
+
10
+ You will be able to specify in which command to use it, via the configuration !
11
+
12
+ ## To add a command
13
+ - configure your command and its client in config/commands.yml
14
+ - create your safepusher client api, as detailed above (if necessary)
15
+ - include your command's description in the help, in config/en.yml
16
+
17
+ # Guidelines
18
+
19
+ Bug reports and pull requests are welcome on GitHub at williampollet/safe_pusher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
20
+
21
+ # Development
22
+ Setup development:
23
+ `$ bin/setup`
24
+
25
+ Open a console:
26
+ `$ bin/console`
27
+
28
+ Test the CLI:
29
+ `$ ruby -Ilib exe/safepush`
30
+
31
+ Launch specs and lint:
32
+
33
+ `$ rake`
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
- source "https://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in safe_pusher.gemspec
6
6
  gemspec
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  # SafePusher
6
6
 
7
- Run your favorite linters and specs on the files you touched, before pushing your branch.
7
+ Run your favorite linters and specs on the files you touched, before committing and pushing your branch.
8
8
 
9
9
  ## Installation
10
10
 
@@ -37,36 +37,95 @@ Create the `safe_pusher.yml` file at the root of your application:
37
37
  files_to_skip:
38
38
  - file/to/skip_1
39
39
  - file/to/skip/2
40
+ base_branch: developement # default master
40
41
  app_base_directory: app
41
42
  repo_url: https://github.com/williampollet/safe_pusher
43
+ services:
44
+ test: rspec
45
+ lint: pronto
46
+ push: github
47
+ open: github
48
+ add: git
49
+ amend: git
50
+ commit: git
51
+ verbose: true
42
52
  ```
43
53
 
44
54
  ## Usage
45
-
46
55
  To see the commands available, type:
47
56
 
48
57
  $ safepush
49
58
 
50
59
  To run pronto checks before you push to GitHub run:
51
60
 
52
- $ safepush lint_push_and_open
61
+ $ safepush lint push open
53
62
 
54
63
  or
55
64
 
56
- $ safepush lpo
65
+ $ safepush l p o
57
66
 
58
67
  To run specs and pronto before you push to GitHub run:
59
68
 
60
- $ safepush test_lint_push_and_open
69
+ $ safepush test lint push open
61
70
 
62
71
  or
63
72
 
64
- $ safepush tlpo
73
+ $ safepush t l p o
74
+
75
+ ### Available commands so far
76
+ - `test` (runs the tests only on the files you touched)
77
+ - `lint` (runs a linter only on the files you touched)
78
+ - `commit` (commit your changes)
79
+ - `add` (track your changes)
80
+ - `amend` (amend your tracked changes to your last commit)
81
+ - `push` (push and set upstream your local branch on github)
82
+ - `open` (open a pull request on github)
65
83
 
66
84
  ## Contributing
67
85
 
86
+ You can easily add a new client, or a new command.
87
+
88
+ ### To add a client
89
+ - create the client api under `lib/safe_pusher/client/***.rb`
90
+ - require it in `lib/safe_pusher.rb`
91
+ - write the specs for your client, then submit a PR
92
+ - You will be able to specify in which command to use it, via the configuration !
93
+
94
+ ### To add a command
95
+ - configure your command and its client in `config/commands.yml`
96
+ - create your safepusher client api, as detailed above (if necessary)
97
+ - include your command's description in the help, in `config/en.yml`
98
+
99
+ ### Guidelines
100
+
68
101
  Bug reports and pull requests are welcome on GitHub at https://github.com/williampollet/safe_pusher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
69
102
 
103
+ ## Development
104
+
105
+ Setup development:
106
+
107
+ ```sh
108
+ $ bin/setup
109
+ ```
110
+
111
+ Open a console:
112
+
113
+ ```sh
114
+ $ bin/console
115
+ ```
116
+
117
+ Test the CLI:
118
+
119
+ ```sh
120
+ $ ruby -Ilib exe/safepush
121
+ ```
122
+
123
+ Launch specs and lint:
124
+
125
+ ```sh
126
+ $ rake
127
+ ```
128
+
70
129
  ## License
71
130
 
72
131
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -1,5 +1,5 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  # Rspec
5
5
  RSpec::Core::RakeTask.new(:spec)
@@ -8,4 +8,4 @@ RSpec::Core::RakeTask.new(:spec)
8
8
  require 'rubocop/rake_task'
9
9
  RuboCop::RakeTask.new
10
10
 
11
- task :default => %i[spec, rubocop]
11
+ task default: %i[spec rubocop]
@@ -0,0 +1,21 @@
1
+ test:
2
+ shortcut: t
3
+ default_client: rspec
4
+ lint:
5
+ shortcut: l
6
+ default_client: pronto
7
+ push:
8
+ shortcut: p
9
+ default_client: github
10
+ open:
11
+ shortcut: o
12
+ default_client: github
13
+ add:
14
+ shortcut: a
15
+ default_client: git
16
+ amend:
17
+ shortcut: m
18
+ default_client: git
19
+ commit:
20
+ shortcut: c
21
+ default_client: git
@@ -0,0 +1,37 @@
1
+ en:
2
+ help: |
3
+ Usage:
4
+ help (h) # show this usage message
5
+ --version # print SafePusher version
6
+ ##########################################################
7
+ # you can use any combination of theese commands
8
+ ##########################################################
9
+ test (t) # run the test suite
10
+ lint (l) # run the linters
11
+ amend (m) # amend your last commit
12
+ add (a) # add changes to be committed
13
+ commit (c) # commit your staged changes
14
+ push (p) # push on distant repository
15
+ open (o) # open a pull request on the distant repository
16
+ command:
17
+ add:
18
+ verbose: Testing new files...
19
+ commit:
20
+ verbose: Commiting last changes...
21
+ amend:
22
+ verbose: Amending last commit...
23
+ push:
24
+ verbose: Pushing to Github...
25
+ open:
26
+ verbose: Opening a pull request on Github...
27
+ lint:
28
+ verbose: Linting tracked changes...
29
+ test:
30
+ verbose: 'Testing new files...'
31
+ test_skipped: 'Alright, skipping the test for now!'
32
+ no_spec_found_for_file: 'No spec found for file %{file_matched}, would you like to add %{spec_path}? (Yn)'
33
+ spec_needs_to_be_written: 'A spec needs to be written!'
34
+ no_spec_analyzed: 'No spec found, going to the next step'
35
+ file_put_in_test_list: '%{file} modified, putting it in the list of specs to run'
36
+ spec_failing_or_missing: 'Oops, a spec seems to be red or empty, be sure to complete it before you push'
37
+ every_spec_operational: 'Every spec operational, going to the next step!'
@@ -1,11 +1,19 @@
1
1
  require 'safe_pusher/configuration'
2
2
  require 'thor'
3
3
  require 'colorize'
4
+ require 'English'
5
+ require 'i18n'
6
+ require 'yaml'
7
+ require 'fileutils'
4
8
  require 'safe_pusher/cli'
5
9
  require 'safe_pusher/version'
6
- require 'safe_pusher/rspec_runner'
7
- require 'safe_pusher/pronto_runner'
8
- require 'safe_pusher/github_runner'
10
+ require 'safe_pusher/client/git'
11
+ require 'safe_pusher/client/rspec'
12
+ require 'safe_pusher/client/pronto'
13
+ require 'safe_pusher/client/github'
14
+
15
+ I18n.config.available_locales_set << :en
16
+ I18n.load_path += Dir["#{File.expand_path('config/locales')}/*.yml"]
9
17
 
10
18
  module SafePusher
11
19
  # Configuration setup
@@ -1,91 +1,74 @@
1
1
  module SafePusher
2
2
  class CLI
3
- attr_reader :arguments
4
-
5
3
  def initialize(arguments:)
6
4
  @arguments = arguments
7
5
  end
8
6
 
9
7
  def start
10
- unless arguments_valid?
11
- help
8
+ return version if arguments.first == '--version'
12
9
 
13
- return
14
- end
10
+ help if commands.include?(nil)
15
11
 
16
- arguments.each do |command|
17
- execute_command(command)
18
- end
12
+ commands.compact.each { |command| execute_command(command) }
19
13
  end
20
14
 
21
15
  private
22
16
 
17
+ attr_reader :arguments
18
+
23
19
  def execute_command(command)
24
- case command
25
- when 'test', 't'
26
- test
27
- when 'lint', 'l'
28
- lint
29
- when 'open', 'o'
30
- open
31
- when 'push', 'p'
32
- push
33
- end
34
- end
20
+ explain(command) if verbose
35
21
 
36
- def test
37
- puts '##########################'.yellow
38
- puts '## Testing new files... ##'.yellow
39
- puts '##########################'.yellow
40
- results = SafePusher::RspecRunner.new.call
22
+ results = SafePusher::Client
23
+ .const_get(services[command].capitalize)
24
+ .new
25
+ .public_send(command)
41
26
 
42
27
  exit results unless results == 0
43
28
  end
44
29
 
45
- def lint
46
- puts '#######################'.yellow
47
- puts '## Running linter... ##'.yellow
48
- puts '#######################'.yellow
30
+ def commands
31
+ @commands ||= arguments.map do |arg|
32
+ next unless arg =~ valid_commands_regexp
49
33
 
50
- results = SafePusher::ProntoRunner.new.call
51
-
52
- exit results unless results == 0
34
+ shortcut_to_command[arg] || arg
35
+ end
53
36
  end
54
37
 
55
- def push
56
- puts '##########################'.yellow
57
- puts '## Pushing to Github... ##'.yellow
58
- puts '##########################'.yellow
38
+ def version
39
+ puts SafePusher::VERSION
40
+ end
59
41
 
60
- results = SafePusher::GithubRunner.new.push
42
+ def explain(command)
43
+ puts I18n.t("command.#{command}.verbose").yellow
44
+ end
61
45
 
62
- exit results unless results == 0
46
+ def help
47
+ puts I18n.t('help')
63
48
  end
64
49
 
65
- def open
66
- puts '#########################################'.yellow
67
- puts '## Opening a pull request on Github... ##'.yellow
68
- puts '#########################################'.yellow
50
+ def valid_commands_regexp
51
+ @valid_commands_regexp ||= /^(?!\s*$)(?:#{available_commands})$/
52
+ end
69
53
 
70
- results = SafePusher::GithubRunner.new.open
54
+ def available_commands
55
+ @available_commands ||= (
56
+ shortcut_to_command.keys + shortcut_to_command.values
57
+ ).join('|')
58
+ end
71
59
 
72
- exit results unless results == 0
60
+ def verbose
61
+ @verbose ||= SafePusher.configuration.verbose
73
62
  end
74
63
 
75
- def arguments_valid?
76
- arguments.join(' ') =~ /^(?!\s*$)(?:test|lint|push|open|t|l|p|o| )+$/
64
+ def services
65
+ @services ||= SafePusher.configuration.services
77
66
  end
78
67
 
79
- def help
80
- puts "Usage:\n"\
81
- " help (h) # show this usage message\n"\
82
- " ##########################################################\n"\
83
- " # you can use any combination of theese commands \n"\
84
- " ##########################################################\n"\
85
- " test (t) # run the test suite\n"\
86
- " lint (l) # run the linters\n"\
87
- " push (p) # push on distant repository\n"\
88
- ' open (o) # open a pull request on the distant repository'
68
+ def shortcut_to_command
69
+ @shortcut_to_command ||= YAML
70
+ .load_file('config/commands.yml')
71
+ .reduce({}) { |o, (k, v)| o.update(v['shortcut'] => k) }
89
72
  end
90
73
  end
91
74
  end
@@ -0,0 +1,27 @@
1
+ module SafePusher
2
+ module Client
3
+ class Git
4
+ def amend
5
+ system('git commit --amend')
6
+
7
+ $CHILD_STATUS.exitstatus
8
+ end
9
+
10
+ def add
11
+ system('git add --interactive')
12
+
13
+ $CHILD_STATUS.exitstatus
14
+ end
15
+
16
+ def commit
17
+ puts 'Enter a message for your commit:'
18
+
19
+ result = STDIN.gets.chomp
20
+
21
+ system("git commit -m '#{result}'")
22
+
23
+ $CHILD_STATUS.exitstatus
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,37 @@
1
+ module SafePusher
2
+ module Client
3
+ class Github
4
+ def push
5
+ system('git push origin')
6
+
7
+ exit_status = $CHILD_STATUS.exitstatus
8
+
9
+ if exit_status == 128
10
+ puts 'Syncing with github...'.green
11
+
12
+ push_and_set_upstream
13
+
14
+ exit_status = $CHILD_STATUS.exitstatus
15
+ end
16
+
17
+ exit_status
18
+ end
19
+
20
+ def open
21
+ system(
22
+ "open '#{SafePusher.configuration.repo_url}/pull/new/#{branch}'",
23
+ )
24
+ end
25
+
26
+ private
27
+
28
+ def push_and_set_upstream
29
+ system("git push --set-upstream origin #{branch}")
30
+ end
31
+
32
+ def branch
33
+ `git rev-parse --symbolic-full-name --abbrev-ref HEAD`.delete("\n")
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,29 @@
1
+ module SafePusher
2
+ module Client
3
+ class Pronto
4
+ def lint
5
+ run_pronto
6
+ exit_status = $CHILD_STATUS.exitstatus
7
+
8
+ if exit_status != 0
9
+ warn 'Pronto found somme errors… ' \
10
+ 'Fix them before pushing to GitHub!'.red
11
+ else
12
+ puts 'No errors found by pronto, go for next step!'.green
13
+ end
14
+
15
+ exit_status
16
+ end
17
+
18
+ private
19
+
20
+ def run_pronto
21
+ system("bin/pronto run --exit-code -c #{base_branch}")
22
+ end
23
+
24
+ def base_branch
25
+ SafePusher.configuration.base_branch
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,136 @@
1
+ module SafePusher
2
+ module Client
3
+ class Rspec
4
+ def initialize
5
+ @specs_to_execute = []
6
+ end
7
+
8
+ def test
9
+ return 1 if list_files_to_execute == 1
10
+
11
+ run_specs
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :specs_to_execute
17
+
18
+ def list_files_to_execute
19
+ modified_files.map do |f|
20
+ return 1 if analyze_file(f) == 1
21
+ end.compact
22
+ end
23
+
24
+ def modified_files
25
+ diff = 'git diff --diff-filter=A --diff-filter=M --name-only'
26
+
27
+ `#{diff} $(git merge-base #{branch} #{base_branch}) #{branch}`
28
+ .split("\n")
29
+ .uniq
30
+ end
31
+
32
+ def analyze_file(file)
33
+ if file.match(app_base_directory) &&
34
+ !file.match(files_to_skip)
35
+ search_or_create_spec(file)
36
+ elsif file.match(/spec/) &&
37
+ !specs_to_execute.include?(file) &&
38
+ !file.match(files_to_skip)
39
+ index_file(file)
40
+ end
41
+ end
42
+
43
+ def search_or_create_spec(file)
44
+ spec_path = file.gsub(
45
+ "#{SafePusher.configuration.app_base_directory}/",
46
+ 'spec/',
47
+ ).gsub('.rb', '_spec.rb')
48
+
49
+ return create_new_spec(spec_path, file) unless File.exist?(spec_path)
50
+
51
+ puts spec_path
52
+
53
+ specs_to_execute << spec_path
54
+ end
55
+
56
+ def index_file(file)
57
+ puts I18n.t('command.test.file_put_in_test_list', file: file)
58
+ specs_to_execute << file
59
+ end
60
+
61
+ def files_to_skip
62
+ Regexp.new(
63
+ SafePusher.configuration.files_to_skip.join('|').gsub('/', '\/'),
64
+ )
65
+ end
66
+
67
+ def run_specs
68
+ if specs_to_execute.empty?
69
+ puts I18n.t('command.test.no_spec_analyzed').green
70
+ return 0
71
+ end
72
+
73
+ system("bin/rspec #{specs_to_execute.join(' ')}")
74
+
75
+ exit_status = $CHILD_STATUS.exitstatus
76
+
77
+ if exit_status != 0
78
+ puts spec_failing_or_missing
79
+ else
80
+ puts every_spec_operational
81
+ end
82
+
83
+ exit_status
84
+ end
85
+
86
+ def create_new_spec(spec_path, file_matched)
87
+ puts I18n.t(
88
+ 'command.test.no_spec_found_for_file',
89
+ file_matched: file_matched,
90
+ spec_path: spec_path,
91
+ )
92
+
93
+ result = STDIN.gets.chomp
94
+
95
+ if result.casecmp('n') == 0
96
+ puts I18n.t('command.test.test_skipped')
97
+
98
+ 0
99
+ else
100
+ create_new_file(spec_path)
101
+
102
+ warn I18n.t('command.test.spec_needs_to_be_written').red
103
+
104
+ 1
105
+ end
106
+ end
107
+
108
+ def branch
109
+ `git rev-parse --abbrev-ref HEAD`.delete("\n")
110
+ end
111
+
112
+ def create_new_file(path)
113
+ parent_directory = File.dirname(path)
114
+
115
+ FileUtils.mkdir_p(parent_directory) unless File.exist?(parent_directory)
116
+ FileUtils.touch(path)
117
+ end
118
+
119
+ def app_base_directory
120
+ %r{#{SafePusher.configuration.app_base_directory}\/.*\.rb$}
121
+ end
122
+
123
+ def base_branch
124
+ SafePusher.configuration.base_branch
125
+ end
126
+
127
+ def spec_failing_or_missing
128
+ I18n.t('command.test.spec_failing_or_missing').red
129
+ end
130
+
131
+ def every_spec_operational
132
+ I18n.t('command.test.every_spec_operational').green
133
+ end
134
+ end
135
+ end
136
+ end
@@ -1,23 +1,34 @@
1
- require 'yaml'
2
- # Configuration variables and defaults
3
1
  module SafePusher
4
2
  class Configuration
5
- # The configuration singleton
6
3
  attr_accessor :files_to_skip,
7
4
  :app_base_directory,
8
- :repo_url
5
+ :repo_url,
6
+ :base_branch,
7
+ :verbose,
8
+ :services
9
9
 
10
10
  def initialize
11
- application_config =
12
- if File.exist?('safe_pusher.yml')
13
- YAML.load_file('safe_pusher.yml')
14
- else
15
- {}
16
- end
17
-
11
+ @verbose = application_config['verbose'] || true
12
+ @base_branch = application_config['base_branch'] || 'master'
18
13
  @files_to_skip = application_config['files_to_skip'] || []
19
14
  @app_base_directory = application_config['app_base_directory']
20
15
  @repo_url = application_config['repo_url']
16
+ @services = load_services
17
+ end
18
+
19
+ private
20
+
21
+ def load_services
22
+ YAML
23
+ .load_file('config/commands.yml')
24
+ .reduce({}) { |o, (k, v)| o.update(k => v['default_client']) }
25
+ .merge(application_config['services'] || {})
26
+ end
27
+
28
+ def application_config
29
+ return YAML.load_file('safe_pusher.yml') if File.exist?('safe_pusher.yml')
30
+
31
+ {}
21
32
  end
22
33
  end
23
34
  end
@@ -1,3 +1,3 @@
1
1
  module SafePusher
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.4.3'.freeze
3
3
  end
@@ -37,6 +37,7 @@ Gem::Specification.new do |spec|
37
37
  spec.require_paths = ['lib']
38
38
 
39
39
  spec.add_dependency 'colorize', '~> 0.8.1'
40
+ spec.add_dependency 'i18n', '~> 1.6.0'
40
41
 
41
42
  spec.add_development_dependency 'bundler', '>= 1.16'
42
43
  spec.add_development_dependency 'fashion_police', '~> 1.2'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safe_pusher
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Pollet
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-05 00:00:00.000000000 Z
11
+ date: 2021-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: i18n
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -164,7 +178,7 @@ dependencies:
164
178
  - - "~>"
165
179
  - !ruby/object:Gem::Version
166
180
  version: 0.16.1
167
- description:
181
+ description:
168
182
  email:
169
183
  - william.pollet@kisskissbankbank.com
170
184
  executables:
@@ -172,6 +186,8 @@ executables:
172
186
  extensions: []
173
187
  extra_rdoc_files: []
174
188
  files:
189
+ - ".github/ISSUE_TEMPLATE/bug_report.md"
190
+ - ".github/ISSUE_TEMPLATE/feature_request.md"
175
191
  - ".gitignore"
176
192
  - ".hound.yml"
177
193
  - ".rspec"
@@ -179,19 +195,23 @@ files:
179
195
  - ".travis.yml"
180
196
  - CHANGELOG.md
181
197
  - CODE_OF_CONDUCT.md
198
+ - CONTRIBUTING.md
182
199
  - Gemfile
183
200
  - LICENSE.txt
184
201
  - README.md
185
202
  - Rakefile
186
203
  - bin/console
187
204
  - bin/setup
205
+ - config/commands.yml
206
+ - config/locales/en.yml
188
207
  - exe/safepush
189
208
  - lib/safe_pusher.rb
190
209
  - lib/safe_pusher/cli.rb
210
+ - lib/safe_pusher/client/git.rb
211
+ - lib/safe_pusher/client/github.rb
212
+ - lib/safe_pusher/client/pronto.rb
213
+ - lib/safe_pusher/client/rspec.rb
191
214
  - lib/safe_pusher/configuration.rb
192
- - lib/safe_pusher/github_runner.rb
193
- - lib/safe_pusher/pronto_runner.rb
194
- - lib/safe_pusher/rspec_runner.rb
195
215
  - lib/safe_pusher/version.rb
196
216
  - safe_pusher.gemspec
197
217
  homepage: https://github.com/williampollet/safe_pusher
@@ -199,7 +219,7 @@ licenses:
199
219
  - MIT
200
220
  metadata:
201
221
  allowed_push_host: https://rubygems.org/
202
- post_install_message:
222
+ post_install_message:
203
223
  rdoc_options: []
204
224
  require_paths:
205
225
  - lib
@@ -214,9 +234,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
234
  - !ruby/object:Gem::Version
215
235
  version: '0'
216
236
  requirements: []
217
- rubyforge_project:
218
- rubygems_version: 2.6.11
219
- signing_key:
237
+ rubygems_version: 3.0.3
238
+ signing_key:
220
239
  specification_version: 4
221
240
  summary: a small CLI that lints your code and run your tests before you push
222
241
  test_files: []
@@ -1,38 +0,0 @@
1
- require 'colorize'
2
- require 'English'
3
-
4
- module SafePusher
5
- class GithubRunner
6
- def push
7
- system('git push origin')
8
-
9
- exit_status = $CHILD_STATUS.exitstatus
10
-
11
- if exit_status == 128
12
- puts 'Syncing with github...'.green
13
-
14
- push_and_set_upstream
15
-
16
- exit_status = $CHILD_STATUS.exitstatus
17
- end
18
-
19
- exit_status
20
- end
21
-
22
- def open
23
- system(
24
- "open '#{SafePusher.configuration.repo_url}/pull/new/#{branch}'",
25
- )
26
- end
27
-
28
- private
29
-
30
- def push_and_set_upstream
31
- system("git push --set-upstream origin #{branch}")
32
- end
33
-
34
- def branch
35
- `git rev-parse --symbolic-full-name --abbrev-ref HEAD`.delete("\n")
36
- end
37
- end
38
- end
@@ -1,26 +0,0 @@
1
- require 'colorize'
2
- require 'English'
3
-
4
- module SafePusher
5
- class ProntoRunner
6
- def call
7
- run_pronto
8
- exit_status = $CHILD_STATUS.exitstatus
9
-
10
- if exit_status != 0
11
- warn 'Pronto found somme errors... '\
12
- 'Fix them before pushing to master!'.red
13
- else
14
- puts 'No errors found by pronto, go for next step!'.green
15
- end
16
-
17
- exit_status
18
- end
19
-
20
- private
21
-
22
- def run_pronto
23
- system('bin/pronto run --exit-code')
24
- end
25
- end
26
- end
@@ -1,115 +0,0 @@
1
- require 'colorize'
2
- require 'English'
3
-
4
- module SafePusher
5
- class RspecRunner
6
- def initialize
7
- @specs_to_execute = []
8
- end
9
-
10
- def call
11
- return 1 if list_files_to_execute == 1
12
-
13
- run_specs
14
- end
15
-
16
- private
17
-
18
- attr_reader :specs_to_execute
19
-
20
- def list_files_to_execute
21
- modified_files.map do |f|
22
- return 1 if analyze_file(f) == 1
23
- end.compact
24
- end
25
-
26
- def modified_files
27
- diff = 'git diff --diff-filter=A --diff-filter=M --name-only'
28
-
29
- `#{diff} $(git merge-base #{branch} master) #{branch}`
30
- .split("\n")
31
- .uniq
32
- end
33
-
34
- def analyze_file(file)
35
- if file.match(app_base_directory) &&
36
- !file.match(files_to_skip)
37
- search_or_create_spec(file)
38
- elsif file.match(/spec/) &&
39
- !specs_to_execute.include?(file) &&
40
- !file.match(files_to_skip)
41
- index_file(file)
42
- end
43
- end
44
-
45
- def search_or_create_spec(file)
46
- puts "#{file} has been modified, searching for specs..."
47
-
48
- spec_path = file.gsub(
49
- "#{SafePusher.configuration.app_base_directory}/",
50
- 'spec/',
51
- ).gsub('.rb', '_spec.rb')
52
-
53
- return create_new_spec(spec_path, file) unless File.exist?(spec_path)
54
-
55
- puts "Spec found for #{file}, putting #{spec_path}"\
56
- ' in the list of specs to run'
57
- specs_to_execute << spec_path
58
- end
59
-
60
- def index_file(file)
61
- puts "#{file} modified, putting it in the list of specs to run"
62
- specs_to_execute << file
63
- end
64
-
65
- def files_to_skip
66
- Regexp.new(
67
- SafePusher.configuration.files_to_skip.join('|').gsub('/', '\/'),
68
- )
69
- end
70
-
71
- def run_specs
72
- if specs_to_execute.empty?
73
- puts 'no spec analyzed, passing to the next step'.green
74
- return 0
75
- end
76
-
77
- system("bin/rspec #{specs_to_execute.join(' ')}")
78
-
79
- exit_status = $CHILD_STATUS.exitstatus
80
-
81
- if exit_status != 0
82
- puts 'Oops, a spec seems to be red or empty, '\
83
- 'be sure to complete it before you push'.red
84
- else
85
- puts 'Every spec operational, '\
86
- 'passing to the next step!'.green
87
- end
88
-
89
- exit_status
90
- end
91
-
92
- def create_new_spec(spec_path, file_matched)
93
- puts "no spec found for file #{file_matched},"\
94
- " would you like to add #{spec_path}? (Yn)"
95
- result = STDIN.gets.chomp
96
-
97
- if result.casecmp('n') == 0
98
- puts 'Alright, skipping the test for now!'
99
- return 0
100
- else
101
- File.open(spec_path, 'w') {}
102
- warn 'A spec needs to be written!'.red
103
- return 1
104
- end
105
- end
106
-
107
- def branch
108
- `git rev-parse --abbrev-ref HEAD`.delete("\n")
109
- end
110
-
111
- def app_base_directory
112
- %r{#{SafePusher.configuration.app_base_directory}\/.*\.rb$}
113
- end
114
- end
115
- end