Class: Jets::CLI::Git::Push

Inherits:
Base
  • Object
show all
Defined in:
lib/jets/cli/git/push.rb

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

#paginate, #paging_params, rescue_api_error

Methods included from Util::Logging

#log

Methods included from AwsServices

#apigateway, #aws_options, #cfn, #codebuild, #dynamodb, #lambda_client, #logs, #s3, #s3_resource, #sns, #sqs, #ssm, #sts, #wafv2

Methods included from AwsServices::StackStatus

#output_value, #stack_exists?

Methods included from AwsServices::GlobalMemoist

included, #reset_cache!

Methods included from Api

#api, #api_key

Constructor Details

#initialize(options = {}) ⇒ Push

Returns a new instance of Push.



5
6
7
8
# File 'lib/jets/cli/git/push.rb', line 5

def initialize(options = {})
  super
  @args = options[:args] || []
end

Instance Method Details

#env_varsObject



26
27
28
29
30
31
32
33
# File 'lib/jets/cli/git/push.rb', line 26

def env_vars
  env_vars = Jets.project.config.git.push.branch[push_branch]
  return unless env_vars
  # IE: branch_name = {JETS_ENV: "xxx", AWS_PROFILE: "xxx"}
  env_vars.map do |k, v|
    "#{k}=#{v}"
  end.sort.join(" ")
end

#localObject



60
61
62
# File 'lib/jets/cli/git/push.rb', line 60

def local
  Jets::Git::Local.new
end

#push_branchObject

man git-push git push git push origin git push origin : git push origin master git push origin HEAD git push mothership master:satellite/master dev:satellite/dev git push origin HEAD:master git push origin master:refs/heads/experimental git push origin :experimental git push origin +dev:master



46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/jets/cli/git/push.rb', line 46

def push_branch
  args = @args.reject { |arg| arg.start_with?("-") } # remove options
  case args.size
  when 0
    local.git_default_branch
  when 1
    local.git_current_branch
  when 2
    args.last
  else
    raise "ERROR: Too many arguments. Usage: jets git:push [REMOTE] [BRANCH]"
  end
end

#runObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/jets/cli/git/push.rb', line 10

def run
  args = ["push"] + @args
  puts "=> git #{args.join(" ")}"

  IO.popen(["git", *args]) do |io|
    io.each do |line|
      puts line
    end
  end

  return unless $?.success?

  command = [env_vars, "jets ci:logs"].compact.join(" ")
  Kernel.exec(command)
end