class Renuo::Cli::Commands::GithubReplace
Public Instance Methods
Source
# File lib/renuo/cli/commands/github_replace.rb, line 21 def run(args, opts) validate_arguments args validate_options opts opts.projects.split(",").each do |repo| base = clone_and_checkout opts, repo find_and_replace args, repo, opts.files.split(",") create_pr opts, repo, base end end
Private Instance Methods
Source
# File lib/renuo/cli/commands/github_replace.rb, line 46 def clone_and_checkout(opts, repo) puts `cd #{repo} || git clone --depth=1 git@github.com:renuo/#{repo}.git` puts `cd #{repo} && git checkout -b "#{opts.branch}"` `cd #{repo} && git branch -rl origin/main origin/master`.strip end
Source
# File lib/renuo/cli/commands/github_replace.rb, line 61 def create_pr(opts, repo, base) puts `cd "#{repo}" \ && git add . \ && git commit -S -m "#{opts.title}" \ && git push --set-upstream origin "#{opts.branch}" \ && gh pr create -a @me -b "#{opts.body}" -t "#{opts.title}" -B "#{base}" -H "#{opts.branch}"` end
Source
# File lib/renuo/cli/commands/github_replace.rb, line 52 def find_and_replace(args, repo, files) files.each do |file| file = "#{repo}/#{file}" puts "Replacing '#{args[0]}' with '#{args[1]}' in #{file}" content = File.read(file).gsub args[0], args[1] File.write file, content end end
Source
# File lib/renuo/cli/commands/github_replace.rb, line 34 def validate_arguments(args) abort ">> specify a search term and replace term" if args.size != 2 end
Source
# File lib/renuo/cli/commands/github_replace.rb, line 38 def validate_options(opts) abort ">> specify one or multiple comma-separated projects" unless opts.projects abort ">> specify a branch" unless opts.branch abort ">> specify a title" unless opts.title abort ">> specify a body" unless opts.body abort ">> specify comma-separated files to check" unless opts.files end