Class: Gct::Command::Create::Third

Inherits:
Gct::Command::Create show all
Defined in:
lib/gct/command/create/third.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Gct::Command

#auto_add_tag, #check_branch_can_be_update, #config_gitlab, #current_branch, #file_contents, #get_project, #gitlab_error, run

Constructor Details

#initialize(argv) ⇒ Third

Returns a new instance of Third.



22
23
24
25
26
27
# File 'lib/gct/command/create/third.rb', line 22

def initialize(argv)
  @url = argv.shift_argument
  @branch = argv.shift_argument
  @skip_push_spec = argv.flag?('skip-push-spec', false)
  super
end

Class Method Details

.optionsObject



16
17
18
19
20
# File 'lib/gct/command/create/third.rb', line 16

def self.options
  [
    ['--skip-push-spec', '不上传到pod私有仓库'],
  ].concat(super)
end

Instance Method Details

#fork_third_pod_to_gitlabObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/gct/command/create/third.rb', line 43

def fork_third_pod_to_gitlab
  reg = /[a-zA-Z|\-|_|0-9]+(?=\.git)/
  dir = reg.match(@url)
  path = "#{Dir.pwd}/#{dir}"
  if File::exist?(path)
    puts "#{dir}文件夹已存在!".red
  else
    branch = @branch.to_s.empty? ? '' : "-b #{@branch}"
    push_branch = @branch.to_s.empty? ? "master" : "#{@branch}"
    puts "git命令为:<-- git clone #{branch} #{@url} -->".green
    `git clone #{branch} #{@url}`
    Dir.chdir(path) do
      git_url = "#{Constant.GitThirdURL}#{dir}"
      `git init`
      `git remote set-url origin #{git_url}.git`
      `git add .`
      `git commit -m "First commit"`
      `git push origin #{push_branch}`
      `git push --tags`
      puts "fork 第三方库成功!".green
      puts "git 地址为:#{git_url}".green
      system "open #{git_url}"
      system "pod repo push iOSCRGTPodSource --sources=#{Constant.GitURL}iOSCRGTPodSource.git --skip-import-validation --use-libraries --allow-warnings" if !@skip_push_spec
    end
  end
end

#runObject



34
35
36
37
38
39
40
41
# File 'lib/gct/command/create/third.rb', line 34

def run
  if @url.include? '.git'
    fork_third_pod_to_gitlab
  else
    puts "该链接不是一个Git仓库".red
  end
  
end

#validate!Object



29
30
31
32
# File 'lib/gct/command/create/third.rb', line 29

def validate!
  super
  help! 'A url for the Pod is required.' unless @url
end