Sha256: 1b488098c805af096a25c6b0430cc2652803516492f65099befff0d8006ace72
Contents?: true
Size: 1.97 KB
Versions: 3
Compression:
Stored size: 1.97 KB
Contents
# frozen_string_literal: true require 'git' require 'logger' module Unwrappr # Runs Git commands module GitCommandRunner class << self def create_branch! raise 'Not a git working dir' unless git_dir? raise 'failed to create branch' unless branch_created? end def commit_and_push_changes! raise 'failed to add git changes' unless git_added_changes? raise 'failed to commit changes' unless git_committed? raise 'failed to push changes' unless git_pushed? end def reset_client @git = nil end def show(revision, path) git.show(revision, path) rescue Git::GitExecuteError nil end def remote git.config('remote.origin.url') end def current_branch_name git.current_branch end def clone_repository(repo, directory) git_wrap { Git.clone(repo, directory) } end def file_exist?(filename) !git.ls_files(filename).empty? end private def git_dir? git_wrap { !current_branch_name.empty? } end def branch_created? timestamp = Time.now.strftime('%Y%d%m-%H%M').freeze git_wrap do git.checkout('origin/master') git.branch("auto_bundle_update_#{timestamp}").checkout end end def git_added_changes? git_wrap { git.add(all: true) } end def git_committed? git_wrap { git.commit('Automatic Bundle Update') } end def git_pushed? git_wrap { git.push('origin', current_branch_name) } end def git if Dir.pwd == @git&.dir&.path @git else Git.open(Dir.pwd, log_options) end end def log_options {}.tap do |opt| opt[:log] = Logger.new(STDOUT) if ENV['DEBUG'] end end def git_wrap yield true rescue Git::GitExecuteError false end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
unwrappr-0.3.4 | lib/unwrappr/git_command_runner.rb |
unwrappr-0.3.3 | lib/unwrappr/git_command_runner.rb |
unwrappr-0.3.2 | lib/unwrappr/git_command_runner.rb |