Class: Gct::Command::Update::Podfile

Inherits:
Gct::Command::Update show all
Defined in:
lib/gct/command/update/podfile.rb

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, options, run

Constructor Details

#initialize(argv) ⇒ Podfile

Returns a new instance of Podfile.



14
15
16
17
18
# File 'lib/gct/command/update/podfile.rb', line 14

def initialize(argv)
  config_gitlab
  @version = argv.shift_argument
  super
end

Instance Method Details

#edit_file(content) ⇒ Object



92
93
94
# File 'lib/gct/command/update/podfile.rb', line 92

def edit_file(content)
  Gitlab.edit_file(@name, @file, @branch, content, "@config #{@version}版本 podfile更新")
end

#initParamsObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gct/command/update/podfile.rb', line 29

def initParams
  db = Database::Data.new
  sql = "select * from project where is_done = 0 order by 'create_time' desc"
  result = db.query(sql)
  result.each do |row|
    @name = "ios/#{row["name"]}"
    @branch = row["branch"]
    @version = row["version"]
    @file = "Podfile"
    break
  end
end

#runObject



24
25
26
27
# File 'lib/gct/command/update/podfile.rb', line 24

def run
  initParams
  update_podfile
end

#skip_modular_headers_podsObject



42
43
44
45
46
47
# File 'lib/gct/command/update/podfile.rb', line 42

def skip_modular_headers_pods
  db = Database::Data.new
  sql = "select * from modular_headers"
  result = db.query(sql)
  return result
end

#update_podfileObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gct/command/update/podfile.rb', line 49

def update_podfile
  podspec_content = file_contents(@name, @file, @branch)
  remove_regex = /dev_pod .*/
  podspec_content = podspec_content.gsub!(remove_regex, "")

  db = Database::Data.new
  sql = "select * from tag where project_version = '#{@version}'"
  result = db.query(sql)
  if result.count == 0
    puts "ERROR: 没有tag库".red
    return
  end

  skip_pods = Array.new()
  skip_modular_headers_pods.each do |row| 
    skip_pods.push(row["pod_name"])
  end

  result.each do |row|
    name = row["pod_name"]
    tag = row["tag_version"]
    is_skip_modular_headers = skip_pods.include?(name)
    modular_headers = is_skip_modular_headers ? ", :modular_headers => false" : ""
    update_regex = /.*#{name}.*/
    update_match = update_regex.match(podspec_content).to_s
    update_str = "  pod '#{name}', '#{tag}'#{modular_headers}"
    if update_match.empty?
      empty_match = "# Pods for iLife"
      podspec_content = podspec_content.gsub!(empty_match, "#{empty_match} \n#{update_str}")  # Pods for iLife
    else 
      podspec_content = podspec_content.gsub!(update_match, update_str)
    end
  end

  edit_file(podspec_content)

  u_db = Database::Data.new
  u_sql = "update project set is_done = 1 where version = '#{@version}'"
  u_db.query(u_sql)

  system "gct robot podfile"
end

#validate!Object



20
21
22
# File 'lib/gct/command/update/podfile.rb', line 20

def validate!
    super
end