bunup 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +78 -0
- data/.travis.yml +10 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +88 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/bunup.gemspec +33 -0
- data/exe/bunup +4 -0
- data/lib/bunup.rb +4 -0
- data/lib/bunup/bundler.rb +43 -0
- data/lib/bunup/cli.rb +128 -0
- data/lib/bunup/gem.rb +42 -0
- data/lib/bunup/options.rb +38 -0
- data/lib/bunup/services/commiter.rb +39 -0
- data/lib/bunup/services/updater.rb +35 -0
- data/lib/bunup/version.rb +3 -0
- metadata +153 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aecb6c5b9952bc73f6e059f520a6ffb477869fa5c44f4855e92a0de17ab50d6f
|
4
|
+
data.tar.gz: d0d5dc8e96c0866cafb55d380ffd3cb6d9602ba7d40a20ff81ba6312ec30e680
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 85686d9b73831bf4fce8d3d5e6d42ec08011315fef82e5d0ba5eba9c7e9b9541d327e9e3f166699fc2ea4b8fd0cd7d21e17c0caea8094d9574b4e45cef37bcd1
|
7
|
+
data.tar.gz: f0568922bd09be73673b7e678427d9de957c49c2d3360fbec279c3f037ec1a5b35caf9f7189e00f261d513bdb58c9e48fba243e54874b19afaf23360c98e96ce
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
Gemspec/RequiredRubyVersion:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Layout/AlignParameters:
|
5
|
+
EnforcedStyle: with_fixed_indentation
|
6
|
+
|
7
|
+
Layout/CaseIndentation:
|
8
|
+
EnforcedStyle: end
|
9
|
+
|
10
|
+
Layout/ClosingHeredocIndentation:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
# A method chain with a trailing dot is able to be copy-and-pasted into a
|
14
|
+
# console
|
15
|
+
Layout/DotPosition:
|
16
|
+
EnforcedStyle: trailing
|
17
|
+
|
18
|
+
Layout/EmptyLinesAroundAccessModifier:
|
19
|
+
Enabled: false
|
20
|
+
|
21
|
+
# This cop has a bug in 0.52.0
|
22
|
+
# https://github.com/bbatsov/rubocop/issues/5224
|
23
|
+
Layout/EmptyLinesAroundArguments:
|
24
|
+
Enabled: false
|
25
|
+
|
26
|
+
Layout/IndentHeredoc:
|
27
|
+
Enabled: false
|
28
|
+
|
29
|
+
Layout/MultilineMethodCallIndentation:
|
30
|
+
EnforcedStyle: indented
|
31
|
+
|
32
|
+
Layout/MultilineOperationIndentation:
|
33
|
+
EnforcedStyle: indented
|
34
|
+
|
35
|
+
Layout/EndAlignment:
|
36
|
+
EnforcedStyleAlignWith: variable
|
37
|
+
|
38
|
+
Metrics/AbcSize:
|
39
|
+
Exclude:
|
40
|
+
- lib/bunup/options.rb
|
41
|
+
|
42
|
+
# Compared to metrics like `AbcSize` or `CyclomaticComplexity`, the number of
|
43
|
+
# lines in a method is not a useful metric. It's common to have very long
|
44
|
+
# methods (> 50 lines) which are quite simple. For example, a method that
|
45
|
+
# returns a long string with only a few interpolations.
|
46
|
+
Metrics/MethodLength:
|
47
|
+
Enabled: false
|
48
|
+
|
49
|
+
Metrics/BlockLength:
|
50
|
+
Enabled: false
|
51
|
+
|
52
|
+
Metrics/ClassLength:
|
53
|
+
Enabled: false
|
54
|
+
|
55
|
+
Metrics/ModuleLength:
|
56
|
+
Enabled: false
|
57
|
+
|
58
|
+
# Status codes or symbols are fine
|
59
|
+
Rails/HttpStatus:
|
60
|
+
Enabled: false
|
61
|
+
|
62
|
+
# Too subtle to lint. Recommend semantic style, but avoid `end.x`.
|
63
|
+
Style/BlockDelimiters:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
# Adding annotations to short format strings would make them less readable.
|
67
|
+
Style/FormatStringToken:
|
68
|
+
Enabled: false
|
69
|
+
|
70
|
+
# Too complicated for a linter. Should be up to the developer at implementation
|
71
|
+
# time.
|
72
|
+
Style/GuardClause:
|
73
|
+
Enabled: false
|
74
|
+
|
75
|
+
# Too subtle to lint. Avoid the "modifier" (postfix) style except on extremely
|
76
|
+
# short and simple lines.
|
77
|
+
Style/IfUnlessModifier:
|
78
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at shane@shanecav.net. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Jared Beck
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
|
2
|
+
[](https://travis-ci.org/singlebrook/bunup)
|
3
|
+
|
4
|
+
# Bunup
|
5
|
+
|
6
|
+
Update Gemfile dependencies and commit to git with one command.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'bunup'
|
14
|
+
```
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install bunup
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
### Bunup all gems
|
27
|
+
|
28
|
+
```bash
|
29
|
+
bunup
|
30
|
+
```
|
31
|
+
|
32
|
+
### Bunup a single gem
|
33
|
+
|
34
|
+
```bash
|
35
|
+
bunup rake
|
36
|
+
```
|
37
|
+
|
38
|
+
### Bunup multiple gems
|
39
|
+
|
40
|
+
```bash
|
41
|
+
bunup rake rubocop
|
42
|
+
```
|
43
|
+
|
44
|
+
### Options
|
45
|
+
|
46
|
+
* `--all`: Update all outdated gems. This is the default.
|
47
|
+
* `-y` `--yes` `--assume-yes`: Answer "yes" to major version update prompts and run non-interactively
|
48
|
+
|
49
|
+
## Development
|
50
|
+
|
51
|
+
After checking out the repo, enter the project directory and run the following:
|
52
|
+
|
53
|
+
```bash
|
54
|
+
bundle
|
55
|
+
COVERAGE=1 bundle exec rake
|
56
|
+
```
|
57
|
+
|
58
|
+
`bin/console` is an interactive prompt that will allow you to experiment.
|
59
|
+
|
60
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
61
|
+
|
62
|
+
To release a new version, update the version number in `version.rb`, and then
|
63
|
+
run `bundle exec rake release`, which will create a git tag for the version,
|
64
|
+
push git commits and tags, and push the `.gem` file to
|
65
|
+
[rubygems.org](https://rubygems.org).
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Bug reports and pull requests are welcome on GitHub at
|
70
|
+
https://github.com/singlebrook/bunup. This project is intended to be a safe,
|
71
|
+
welcoming space for collaboration, and contributors are expected to adhere to
|
72
|
+
the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
73
|
+
|
74
|
+
## Acknowledgements
|
75
|
+
|
76
|
+
Bunup was created by [Jared Beck](https://jaredbeck.com). It is developed by
|
77
|
+
[Singlebrook Technology](https://singlebrook.com).
|
78
|
+
|
79
|
+
## License
|
80
|
+
|
81
|
+
The gem is available as open source under the terms of the
|
82
|
+
[MIT License](https://opensource.org/licenses/MIT).
|
83
|
+
|
84
|
+
## Code of Conduct
|
85
|
+
|
86
|
+
Everyone interacting in the Bunup project’s codebases, issue trackers, chat
|
87
|
+
rooms and mailing lists is expected to follow the
|
88
|
+
[code of conduct](https://github.com/[USERNAME]/bunup/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'bunup'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/bunup.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'bunup/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'bunup'
|
7
|
+
spec.version = Bunup::VERSION
|
8
|
+
spec.authors = ['Jared Beck', 'Shane Cavanaugh', 'Leon Miller-Out']
|
9
|
+
spec.email = %w[jared@jaredbeck.com shane@shanecav.net leon@singlebrook.com]
|
10
|
+
spec.homepage = 'https://github.com/singlebrook/bunup'
|
11
|
+
spec.summary = 'Bundle update and commit to git with one command'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
|
14
|
+
# Specify which files should be added to the gem when it is released.
|
15
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added
|
16
|
+
# into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
19
|
+
f.match(%r{^(test|spec|features)/})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
spec.bindir = 'exe'
|
23
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
|
+
spec.require_paths = ['lib']
|
25
|
+
spec.required_ruby_version = '>= 2.1'
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
28
|
+
spec.add_development_dependency 'byebug', '~> 9.0'
|
29
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
30
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
31
|
+
spec.add_development_dependency 'rubocop', '>= 0.57.2'
|
32
|
+
spec.add_development_dependency 'simplecov', '~> 0.16.1'
|
33
|
+
end
|
data/exe/bunup
ADDED
data/lib/bunup.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'open3'
|
2
|
+
|
3
|
+
module Bunup
|
4
|
+
# Run bundler commands
|
5
|
+
class Bundler
|
6
|
+
# Expects:
|
7
|
+
# "rails (newest 5.2.1, installed 5.2.0)"
|
8
|
+
# or
|
9
|
+
# "rails (newest 5.2.1, installed 5.2.0, requested = 5.2.0)"
|
10
|
+
OUTDATED_PATTERN = /
|
11
|
+
(?<name>.*)\s
|
12
|
+
\(newest\s(?<newest>.*),\s
|
13
|
+
installed\s(?<installed>.*?)
|
14
|
+
(,\srequested.*)?
|
15
|
+
\)
|
16
|
+
/x.freeze
|
17
|
+
|
18
|
+
# Expected output format:
|
19
|
+
# "\ngem-name (newest 1.0.0, installed 2.0.0)\n"
|
20
|
+
def self.outdated(gem_names)
|
21
|
+
stdout, stderr, status = Open3.capture3(
|
22
|
+
"bundler outdated #{gem_names.join(' ')} --parseable --strict"
|
23
|
+
)
|
24
|
+
validate_output(stdout, stderr, status)
|
25
|
+
stdout.strip
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.validate_output(stdout, stderr, status)
|
29
|
+
# `bundler outdated` exits with a 0 status if the gem is up-to-date
|
30
|
+
raise ::SystemExit.new(true, 'Gem is up-to-date') if status.success?
|
31
|
+
|
32
|
+
# `bundler outdated` exits with a status of 256 if the gem is out-of-date.
|
33
|
+
# If it exits with some other status, print the error and exit with that
|
34
|
+
# status
|
35
|
+
unless status.to_i == 256
|
36
|
+
raise ::SystemExit.new(
|
37
|
+
status.to_i,
|
38
|
+
(stderr == '' ? stdout : stderr).chomp + "\n"
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
data/lib/bunup/cli.rb
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
module Bunup
|
2
|
+
# Parse args, run services, handle output, and handle exits
|
3
|
+
class CLI
|
4
|
+
COMMITING_MSG = 'Commiting Gemfile and Gemfile.lock changes'.freeze
|
5
|
+
E_DIRTY_GEMFILE = 'Gemfile and/or Gemfile.lock has changes that would ' \
|
6
|
+
'be overwritten. Please stash or commit your changes before running ' \
|
7
|
+
'bunup.'.freeze
|
8
|
+
MAJOR_VERSION_UPDATE_WARNING_FMT = 'WARNING: %<gem_name>s is being ' \
|
9
|
+
'updated from %<installed_version>s to %<newest_version>s. This is ' \
|
10
|
+
'a major version update with possible breaking changes. ' \
|
11
|
+
'Continue? [y/N] '.freeze
|
12
|
+
UPDATING_MSG_FMT = '(%<remaining>s) Updating %<gem_name>s ' \
|
13
|
+
'%<installed_version>s -> %<newest_version>s'.freeze
|
14
|
+
|
15
|
+
def initialize(args)
|
16
|
+
@options = ::Bunup::Options.parse!(args)
|
17
|
+
@args = args
|
18
|
+
@exit_status = true
|
19
|
+
end
|
20
|
+
|
21
|
+
def run
|
22
|
+
abort(E_DIRTY_GEMFILE) unless ::Bunup::Services::Commiter.clean_gemfile?
|
23
|
+
@gems = build_gems
|
24
|
+
update_and_commit_changes
|
25
|
+
exit @exit_status
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def build_gem(match_data)
|
31
|
+
::Bunup::Gem.new(
|
32
|
+
name: match_data[:name],
|
33
|
+
installed_version: match_data[:installed],
|
34
|
+
newest_version: match_data[:newest]
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_gems
|
39
|
+
bundle_outdated.split("\n").map do |line|
|
40
|
+
next unless Bundler::OUTDATED_PATTERN =~ line
|
41
|
+
|
42
|
+
match_data = Bundler::OUTDATED_PATTERN.match(line)
|
43
|
+
build_gem(match_data)
|
44
|
+
end.compact
|
45
|
+
end
|
46
|
+
|
47
|
+
def bundle_outdated
|
48
|
+
puts 'Checking for updates'
|
49
|
+
Bundler.outdated(bunup_all? ? [] : @args)
|
50
|
+
rescue ::SystemExit => e
|
51
|
+
handle_system_exit(e)
|
52
|
+
''
|
53
|
+
end
|
54
|
+
|
55
|
+
def bunup_all?
|
56
|
+
@options.all
|
57
|
+
end
|
58
|
+
|
59
|
+
def bunup_many?
|
60
|
+
@args.count > 1 || bunup_all?
|
61
|
+
end
|
62
|
+
|
63
|
+
def commit
|
64
|
+
Services::Commiter.new(@gem).perform
|
65
|
+
end
|
66
|
+
|
67
|
+
def handle_system_exit(exception)
|
68
|
+
@exit_status = exception.success?
|
69
|
+
msg = []
|
70
|
+
msg << 'ERROR:' unless exception.success?
|
71
|
+
msg << exception.message
|
72
|
+
puts msg.join(' ') + "\n"
|
73
|
+
raise exception unless bunup_many?
|
74
|
+
end
|
75
|
+
|
76
|
+
def major_version_update?
|
77
|
+
return false if @gem.newest_version.nil? || @gem.installed_version.nil?
|
78
|
+
|
79
|
+
major_version = ->(version) { version.split('.')[0].to_i }
|
80
|
+
major_version.call(@gem.newest_version) >
|
81
|
+
major_version.call(@gem.installed_version)
|
82
|
+
end
|
83
|
+
|
84
|
+
# A major version update has breaking changes, according to Semantic
|
85
|
+
# Versioning (https://semver.org/spec/v2.0.0.html). Let's make sure the
|
86
|
+
# user is aware of that.
|
87
|
+
def prompt_for_major_update
|
88
|
+
print format(
|
89
|
+
MAJOR_VERSION_UPDATE_WARNING_FMT,
|
90
|
+
gem_name: @gem.name,
|
91
|
+
installed_version: @gem.installed_version,
|
92
|
+
newest_version: @gem.newest_version
|
93
|
+
)
|
94
|
+
if @options.assume_yes
|
95
|
+
print "assuming yes\n"
|
96
|
+
else
|
97
|
+
unless STDIN.gets.chomp.casecmp('y').zero?
|
98
|
+
raise ::SystemExit.new(true, 'No update performed')
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def update
|
104
|
+
puts format(
|
105
|
+
UPDATING_MSG_FMT,
|
106
|
+
remaining: "#{@gems.find_index(@gem) + 1}/#{@gems.count}",
|
107
|
+
gem_name: @gem.name,
|
108
|
+
installed_version: @gem.installed_version,
|
109
|
+
newest_version: @gem.newest_version
|
110
|
+
)
|
111
|
+
Services::Updater.new(@gem).perform
|
112
|
+
end
|
113
|
+
|
114
|
+
def update_and_commit_changes
|
115
|
+
@gems.each do |gem|
|
116
|
+
@gem = gem
|
117
|
+
begin
|
118
|
+
prompt_for_major_update if major_version_update?
|
119
|
+
update
|
120
|
+
commit
|
121
|
+
rescue ::SystemExit => e
|
122
|
+
handle_system_exit(e)
|
123
|
+
next
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
data/lib/bunup/gem.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
module Bunup
|
4
|
+
# Easily access gem attributes
|
5
|
+
class Gem
|
6
|
+
# Gem name patterns taken from
|
7
|
+
# https://github.com/rubygems/rubygems.org/blob/master/lib/patterns.rb
|
8
|
+
SPECIAL_CHARACTERS = '.-_'.freeze
|
9
|
+
ALLOWED_CHARACTERS = '[A-Za-z0-9' \
|
10
|
+
"#{Regexp.escape(SPECIAL_CHARACTERS)}]+".freeze
|
11
|
+
NAME_PATTERN = /\A#{ALLOWED_CHARACTERS}\Z/.freeze
|
12
|
+
|
13
|
+
attr_accessor :name, :installed_version, :newest_version
|
14
|
+
|
15
|
+
def initialize(name: nil, installed_version: nil, newest_version: nil)
|
16
|
+
@name = name
|
17
|
+
@installed_version = installed_version
|
18
|
+
@newest_version = newest_version
|
19
|
+
validate
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def validate
|
25
|
+
abort "Invalid gem name: #{name}" unless valid_name?
|
26
|
+
unless valid_version?(installed_version)
|
27
|
+
abort "Invalid version for #{name}: #{installed_version}"
|
28
|
+
end
|
29
|
+
unless valid_version?(newest_version)
|
30
|
+
abort "Invalid version for #{name}: #{newest_version}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def valid_name?
|
35
|
+
name =~ NAME_PATTERN
|
36
|
+
end
|
37
|
+
|
38
|
+
def valid_version?(version_string)
|
39
|
+
::Gem::Version.correct?(version_string)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'optionparser'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Bunup
|
5
|
+
# Handle command-line switches
|
6
|
+
class Options < ::OpenStruct
|
7
|
+
def self.parse!(args)
|
8
|
+
args = ['--all'] if args.empty?
|
9
|
+
options = new
|
10
|
+
opt_parser = ::OptionParser.new do |opts|
|
11
|
+
opts.banner = 'Usage: bunup [options] | <gem_name> [<gem_name>...]'
|
12
|
+
opts.program_name = 'bunup'
|
13
|
+
opts.version = ::Bunup::VERSION
|
14
|
+
|
15
|
+
opts.on('--all', 'Update all outdated gems (default)') do
|
16
|
+
options.all = true
|
17
|
+
end
|
18
|
+
|
19
|
+
assume_yes_msg = 'Answer "yes" to major version update prompts ' \
|
20
|
+
'and run non-interactively'
|
21
|
+
opts.on('-y', '--yes', '--assume-yes', assume_yes_msg) do
|
22
|
+
options.assume_yes = true
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on('-h', '--help', 'Prints this help') do
|
26
|
+
puts opts
|
27
|
+
exit
|
28
|
+
end
|
29
|
+
end
|
30
|
+
opt_parser.parse!(args)
|
31
|
+
options
|
32
|
+
rescue OptionParser::InvalidOption => e
|
33
|
+
puts e
|
34
|
+
puts opt_parser
|
35
|
+
abort
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Bunup
|
2
|
+
module Services
|
3
|
+
# Commit changes to Gemfile and Gemfile.lock to git
|
4
|
+
class Commiter
|
5
|
+
COMMIT_MESSAGE_FMT = '%<gem_name>s %<newest_version>s ' \
|
6
|
+
'(was %<installed_version>s)'.freeze
|
7
|
+
|
8
|
+
def self.clean_gemfile?
|
9
|
+
`git status -s Gemfile Gemfile.lock` == ''
|
10
|
+
end
|
11
|
+
|
12
|
+
def initialize(gem)
|
13
|
+
@gem = gem
|
14
|
+
end
|
15
|
+
|
16
|
+
def perform
|
17
|
+
add
|
18
|
+
commit
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def add
|
24
|
+
`git add Gemfile Gemfile.lock`
|
25
|
+
end
|
26
|
+
|
27
|
+
def commit
|
28
|
+
`git commit -m "#{message}"`
|
29
|
+
end
|
30
|
+
|
31
|
+
def message
|
32
|
+
format COMMIT_MESSAGE_FMT,
|
33
|
+
gem_name: @gem.name,
|
34
|
+
newest_version: @gem.newest_version,
|
35
|
+
installed_version: @gem.installed_version
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Bunup
|
2
|
+
module Services
|
3
|
+
# Use bundler to update the gem and the Gemfile
|
4
|
+
class Updater
|
5
|
+
USING_PATTERN = /^Using (?<gem_name>.*) (?<installed>.*)$/.freeze
|
6
|
+
|
7
|
+
def initialize(gem)
|
8
|
+
@gem = gem
|
9
|
+
end
|
10
|
+
|
11
|
+
def perform
|
12
|
+
update
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def bundle_update
|
18
|
+
::Open3.capture3("bundle update #{@gem.name}")
|
19
|
+
end
|
20
|
+
|
21
|
+
def update
|
22
|
+
stdout, _stderr, _status = bundle_update
|
23
|
+
|
24
|
+
# Bundler might be unable to update the gem, and won't say why.
|
25
|
+
if stdout =~ /its version stayed the same/
|
26
|
+
raise ::SystemExit.new(
|
27
|
+
false,
|
28
|
+
"Bundler tried to update #{@gem.name} " \
|
29
|
+
'but its version stayed the same'
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bunup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jared Beck
|
8
|
+
- Shane Cavanaugh
|
9
|
+
- Leon Miller-Out
|
10
|
+
autorequire:
|
11
|
+
bindir: exe
|
12
|
+
cert_chain: []
|
13
|
+
date: 2018-11-02 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: bundler
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - "~>"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.16'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - "~>"
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '1.16'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: byebug
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - "~>"
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '9.0'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - "~>"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '9.0'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rake
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '10.0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - "~>"
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '10.0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - "~>"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '3.0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - "~>"
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '3.0'
|
71
|
+
- !ruby/object:Gem::Dependency
|
72
|
+
name: rubocop
|
73
|
+
requirement: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 0.57.2
|
78
|
+
type: :development
|
79
|
+
prerelease: false
|
80
|
+
version_requirements: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: 0.57.2
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: simplecov
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - "~>"
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: 0.16.1
|
92
|
+
type: :development
|
93
|
+
prerelease: false
|
94
|
+
version_requirements: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - "~>"
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: 0.16.1
|
99
|
+
description:
|
100
|
+
email:
|
101
|
+
- jared@jaredbeck.com
|
102
|
+
- shane@shanecav.net
|
103
|
+
- leon@singlebrook.com
|
104
|
+
executables:
|
105
|
+
- bunup
|
106
|
+
extensions: []
|
107
|
+
extra_rdoc_files: []
|
108
|
+
files:
|
109
|
+
- ".gitignore"
|
110
|
+
- ".rubocop.yml"
|
111
|
+
- ".travis.yml"
|
112
|
+
- CODE_OF_CONDUCT.md
|
113
|
+
- Gemfile
|
114
|
+
- LICENSE.txt
|
115
|
+
- README.md
|
116
|
+
- Rakefile
|
117
|
+
- bin/console
|
118
|
+
- bin/setup
|
119
|
+
- bunup.gemspec
|
120
|
+
- exe/bunup
|
121
|
+
- lib/bunup.rb
|
122
|
+
- lib/bunup/bundler.rb
|
123
|
+
- lib/bunup/cli.rb
|
124
|
+
- lib/bunup/gem.rb
|
125
|
+
- lib/bunup/options.rb
|
126
|
+
- lib/bunup/services/commiter.rb
|
127
|
+
- lib/bunup/services/updater.rb
|
128
|
+
- lib/bunup/version.rb
|
129
|
+
homepage: https://github.com/singlebrook/bunup
|
130
|
+
licenses:
|
131
|
+
- MIT
|
132
|
+
metadata: {}
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
requirements:
|
139
|
+
- - ">="
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: '2.1'
|
142
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ">="
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
requirements: []
|
148
|
+
rubyforge_project:
|
149
|
+
rubygems_version: 2.7.6
|
150
|
+
signing_key:
|
151
|
+
specification_version: 4
|
152
|
+
summary: Bundle update and commit to git with one command
|
153
|
+
test_files: []
|