# frozen_string_literal: true require 'clamp' # Welcome to unwrappr... module Unwrappr # Entry point for the app class CLI < Clamp::Command self.default_subcommand = 'all' option(['-b', '--base'], 'BRANCH', <<~DESCRIPTION, the branch upon which to base the pull-request. Omit this option to use the current branch, or repository's default branch (typically 'origin/main') on clone. DESCRIPTION attribute_name: :base_branch) option ['-v', '--version'], :flag, 'Show version' do puts "unwrappr v#{Unwrappr::VERSION}" exit(0) end subcommand 'all', 'run bundle update, push to github, '\ 'create a pr and annotate changes' do def execute Unwrappr.run_unwapper_in_pwd(base_branch: base_branch) end end subcommand 'annotate-pull-request', 'Annotate Gemfile.lock changes in a Github pull request' do option ['-r', '--repo'], 'REPO', 'The repo in github ', required: true option ['-p', '--pr'], 'PR', 'The github PR number', required: true def execute LockFileAnnotator.annotate_github_pull_request( repo: repo, pr_number: pr.to_i ) end end subcommand('clone', <<~DESCRIPTION) do Clone one git repository or more and create an annotated bundle update PR for each. DESCRIPTION option(['-r', '--repo'], 'REPO', <<~DESCRIPTION, a repo in github , may be specified multiple times DESCRIPTION required: true, multivalued: true) def execute repo_list.each do |repo| unless Dir.exist?(repo) GitCommandRunner.clone_repository( "https://github.com/#{repo}", repo ) end Dir.chdir(repo) { Unwrappr.run_unwapper_in_pwd(base_branch: base_branch) } end end end end def self.run_unwapper_in_pwd(base_branch:) return unless lockfile_present? puts "Doing the unwrappr thing in #{Dir.pwd}" GitCommandRunner.create_branch!(base_branch: base_branch) BundlerCommandRunner.bundle_update! GitCommandRunner.commit_and_push_changes! GitHub::Client.make_pull_request! end def self.lockfile_present? GitCommandRunner.file_exist?('Gemfile.lock') end end