Class: KCommercial::KCPipeline::InstallGitHook

Inherits:
Object
  • Object
show all
Defined in:
lib/KCommercialPipeline/core/git_hook/install_git_hook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(platform) ⇒ InstallGitHook

Returns a new instance of InstallGitHook.



13
14
15
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 13

def initialize(platform)
  @platform = platform
end

Instance Attribute Details

#ad_githook_pathObject (readonly)

Returns the value of attribute ad_githook_path.



12
13
14
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 12

def ad_githook_path
  @ad_githook_path
end

#ad_githook_source_pathObject (readonly)

Returns the value of attribute ad_githook_source_path.



11
12
13
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 11

def ad_githook_source_path
  @ad_githook_source_path
end

#platformObject (readonly)

Returns the value of attribute platform.



10
11
12
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 10

def platform
  @platform
end

Instance Method Details

#finall_installObject



78
79
80
81
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 78

def finall_install
  FileUtils.rm_rf(ad_githook_source_path) if File.exist?(ad_githook_source_path)
  KCommercial::UI.success("钩子安装成功")
end

#install!Object



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 33

def install!
  KCommercial::UI.info("开始安装钩子......")
  prepare
  install_common
  if @platform == 'iOS'
    installiOS()
  else
    installAndroid()
  end
  finall_install
end

#install_commonObject

安装通用



62
63
64
65
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 62

def install_common
  common_path= "#{ad_githook_source_path}/common"
  install_hook(common_path)
end

#install_hook(path) ⇒ Object



67
68
69
70
71
72
73
74
75
76
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 67

def  install_hook(path)
  if File.exist?(path)
    Find.find(path).each do |f|
      unless File.directory?(f)
        FileUtils.cp_r(f,ad_githook_path)
        KCommercial::UI.info("成功安装#{f}!")
      end
    end
  end
end

#installAndroidObject

android特有



56
57
58
59
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 56

def installAndroid
  android_path = "#{ad_githook_source_path}/Android"
  install_hook(android_path)
end

#installiOSObject

iOS特有



50
51
52
53
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 50

def installiOS
  iOS_path = "#{ad_githook_source_path}/iOS"
  install_hook(iOS_path)
end

#prepareObject



25
26
27
28
29
30
31
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 25

def prepare
  FileUtils.rm_rf(ad_githook_source_path) if File.exist?(ad_githook_source_path)
  `git clone [email protected]:exploration-client/adiosgithook.git  #{ad_githook_source_path}`
  exitstatus = $?.exitstatus
  KCommercial::UI.error("git clone templete出错!") unless exitstatus == 0
  FileUtils.mkdir(ad_githook_path) unless File.exist?(ad_githook_path)
end

#root_pathObject



45
46
47
# File 'lib/KCommercialPipeline/core/git_hook/install_git_hook.rb', line 45

def root_path
  KCGit.find_git_path
end