Skip to content

Commit

Permalink
Merge pull request #90 from envato/paj/handle-lockfiles-in-subdirecto…
Browse files Browse the repository at this point in the history
…ries

Handle lockfiles in subdirectories
  • Loading branch information
johnsyweb authored Jul 21, 2021
2 parents 8dbeb2a + 6dfaa52 commit be7c010
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 17 deletions.
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

[Unreleased]: https://github.com/envato/unwrappr/compare/v0.7.0...HEAD
[Unreleased]: https://github.com/envato/unwrappr/compare/v0.8.0...HEAD

## [0.8.0] 2021-07-22

### Add

- Ability to perform a `bundle update` in subdirectories with the `-R` /
`--recursive` flag. ([#90])

[0.8.0]: https://github.com/envato/unwrappr/compare/v0.7.0...v0.8.0
[#90]: https://github.com/envato/unwrappr/pull/90

## [0.7.0] 2021-07-15

Expand Down
55 changes: 40 additions & 15 deletions lib/unwrappr/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ class CLI < Clamp::Command
exit(0)
end

subcommand 'all', 'run bundle update, push to github, '\
subcommand 'all', 'run bundle update, push to GitHub, '\
'create a pr and annotate changes' do
option ['-R', '--recursive'],
:flag,
'Recurse into subdirectories',
attribute_name: :recursive

def execute
Unwrappr.run_unwapper_in_pwd(base_branch: base_branch, lock_files: lock_files)
Unwrappr.run_unwrappr_in_pwd(base_branch: base_branch, lock_files: lock_files, recursive: recursive?)
end
end

Expand All @@ -43,7 +48,7 @@ def execute
required: true

option ['-p', '--pr'], 'PR',
'The github PR number',
'The GitHub PR number',
required: true

def execute
Expand All @@ -62,38 +67,58 @@ def execute
option(['-r', '--repo'],
'REPO',
<<~DESCRIPTION,
a repo in github <owner/project>, may be specified multiple times
a repo in GitHub <owner/project>, may be specified multiple times
DESCRIPTION
required: true,
multivalued: true)

option ['-R', '--recursive'],
:flag,
'Recurse into subdirectories',
attribute_name: :recursive

def execute
repo_list.each do |repo|
unless Dir.exist?(repo)
GitCommandRunner.clone_repository(
"https://github.com/#{repo}",
repo
)
end
GitCommandRunner.clone_repository("https://github.com/#{repo}", repo) unless Dir.exist?(repo)

Dir.chdir(repo) { Unwrappr.run_unwapper_in_pwd(base_branch: base_branch, lock_files: lock_files) }
Dir.chdir(repo) do
Unwrappr.run_unwrappr_in_pwd(base_branch: base_branch, lock_files: lock_files, recursive: recursive?)
end
end
end
end
end

def self.run_unwapper_in_pwd(base_branch:, lock_files:)
def self.run_unwrappr_in_pwd(base_branch:, lock_files:, recursive:)
return unless any_lockfile_present?(lock_files)

puts "Doing the unwrappr thing in #{Dir.pwd}"

GitCommandRunner.create_branch!(base_branch: base_branch)
BundlerCommandRunner.bundle_update!
bundle_update!(lock_files: lock_files, recursive: recursive)
GitCommandRunner.commit_and_push_changes!
GitHub::Client.make_pull_request!(lock_files)
end

def self.any_lockfile_present?(lock_files)
lock_files.any? { |lock_file| GitCommandRunner.file_exist?(lock_file) }
end

def self.bundle_update!(lock_files:, recursive:)
directories(lock_files: lock_files, recursive: recursive).each do |dir|
Dir.chdir(dir) do
puts "Doing the unwrappr thing in #{Dir.pwd}"
BundlerCommandRunner.bundle_update!
end
end
end

def self.directories(lock_files:, recursive:)
if recursive
lock_files
.flat_map { |f| Dir.glob("**/#{f}") }
.map { |f| File.dirname(f) }
.uniq
else
%w[.]
end
end
end
2 changes: 1 addition & 1 deletion lib/unwrappr/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Unwrappr
VERSION = '0.7.0'
VERSION = '0.8.0'
end

0 comments on commit be7c010

Please sign in to comment.