Class: LgPodPlugin::GitLabArchive

Inherits:
Object
  • Object
show all
Defined in:
lib/lg_pod_plugin/git/gitlab_archive.rb

Instance Method Summary collapse

Constructor Details

#initialize(checkout_options = {}) ⇒ GitLabArchive

Returns a new instance of GitLabArchive.



18
19
20
21
22
23
24
25
26
27
28
# File 'lib/lg_pod_plugin/git/gitlab_archive.rb', line 18

def initialize(checkout_options = {})
  self.git = checkout_options[:git]
  self.tag = checkout_options[:tag]
  self.name = checkout_options[:name]
  self.path = checkout_options[:path]
  self.spec = checkout_options[:spec]
  self.config = checkout_options[:config]
  self.commit = checkout_options[:commit]
  self.branch = checkout_options[:branch]
  @checkout_options = checkout_options
end

Instance Method Details

#downloadObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lg_pod_plugin/git/gitlab_archive.rb', line 30

def download
  if self.git && self.tag
    self.gitlab_download_tag_zip self.path
  elsif self.git && self.branch
    self.gitlab_download_branch_zip self.path
  elsif self.git && self.commit
    self.gitlab_download_commit_zip self.path
  else
    nil
  end
end

#download_archive_zip(sandbox_path) ⇒ Object

下载某个文件zip格式



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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/lg_pod_plugin/git/gitlab_archive.rb', line 43

def download_archive_zip(sandbox_path)
  host = self.config.host
  project = self.config.project
  token = self.config.access_token
  unless host
    http = Ping.new(project.web_url)
    host = http.uri.scheme + "://" + http.uri.hostname
  end
  if self.git && self.tag
    sha = self.tag
  elsif self.git && self.branch
    sha = self.branch
  elsif self.git && self.commit
    sha = self.commit
  else
    return nil
  end
  lg_spec = self.spec
  unless lg_spec
    podspec_filename = self.name + ".podspec"
    podspec_content = GitLabAPI.get_podspec_file_content(host, token, project.id, sha, podspec_filename)
    unless podspec_content && LUtils.is_a_string?(podspec_content)
      download_url = host + "/api/v4/projects/" + "#{project.id}" + "/repository/archive.tar.bz2\\?" + "sha\\=#{sha}"
      download_url += "\\&access_token\\=#{token}" if token
      return [{ "filename" => "#{self.name}.tar.bz2", "url" => download_url }]
    end
    pod_spec_file_path = sandbox_path.join("#{podspec_filename}")
    lg_spec = LgPodPlugin::PodSpec.form_string(podspec_content, pod_spec_file_path)
    unless lg_spec
      if podspec_content
        begin
          File.open(pod_spec_file_path, "w+") do |f|
            f.write podspec_content
          end
        rescue => exception
          LgPodPlugin.log_red "#{exception}"
        end
        @podspec_content = podspec_content
      end
      download_url = host + "/api/v4/projects/" + "#{project.id}" + "/repository/archive.tar.bz2\\?" + "sha\\=#{sha}"
      download_url += "\\&access_token\\=#{token}" if token
      return [{ "filename" => "#{self.name}.tar.bz2", "url" => download_url }]
    end
    self.spec = lg_spec
  end
  download_params = Array.new
  @source_files = lg_spec.source_files.keys
  lg_spec.source_files.each_key do |key|
    next if key == "All" || key == "LICENSE" || key == "License"
    path = LUtils.url_encode(key)
    # download_url = host + "/api/v4/projects/" + "#{project.id}" + "/repository/archive.tar.bz2#{"\\?"}" + "sha#{"\\="}#{sha}"
    download_url = host + "/api/v4/projects/" + "#{project.id}" + "/repository/archive.tar.bz2#{"\\?"}" + "path#{"\\="}#{path}#{"\\&"}sha#{"\\="}#{sha}"
    download_url += "\\&access_token\\=#{token}" if token
    download_params.append({ "filename" => "#{path}.tar.bz2", "url" => download_url })
  end
  if download_params.empty?
    download_url = host + "/api/v4/projects/" + "#{project.id}" + "/repository/archive.tar.bz2\\?" + "sha\\=#{sha}"
    download_url += "\\&access_token\\=#{token}" if token
    [{ "filename" => "#{self.name}.tar.bz2", "url" => download_url }]
  else
    download_params
  end
end

#gitlab_download_branch_zip(root_path) ⇒ Object

根据branch 下载 zip 包



108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/lg_pod_plugin/git/gitlab_archive.rb', line 108

def gitlab_download_branch_zip(root_path)
  token = self.config.access_token
  download_urls = self.download_archive_zip(root_path)
  return nil unless download_urls
  download_params = Hash.new
  download_params["token"] = token
  download_params["name"] = self.name
  download_params["type"] = "gitlab-branch"
  if self.spec
    download_params["podspec"] = self.spec
  else
    download_params["podspec_content"] = @podspec_content
  end
  download_params["path"] = root_path.to_path
  if @source_files
    download_params["source_files"] = @source_files
  else
    download_params["source_files"] = "All"
  end
  download_params["download_urls"] = download_urls
  download_params
end

#gitlab_download_commit_zip(root_path) ⇒ Object

通过 commit 下载zip包



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/lg_pod_plugin/git/gitlab_archive.rb', line 156

def gitlab_download_commit_zip(root_path)
  token = self.config.access_token
  download_urls = self.download_archive_zip(root_path)
  return nil unless download_urls
  download_params = Hash.new
  download_params["token"] = token
  download_params["name"] = self.name
  if self.spec
    download_params["podspec"] = self.spec
  else
    download_params["podspec_content"] = @podspec_content
  end
  download_params["type"] = "gitlab-commit"
  download_params["path"] = root_path.to_path
  if @source_files
    download_params["source_files"] = @source_files
  else
    download_params["source_files"] = "All"
  end
  download_params["download_urls"] = download_urls
  download_params
end

#gitlab_download_tag_zip(root_path) ⇒ Object

通过tag下载zip包



132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/lg_pod_plugin/git/gitlab_archive.rb', line 132

def gitlab_download_tag_zip(root_path)
  token = self.config.access_token
  download_urls = self.download_archive_zip(root_path)
  return nil unless download_urls
  download_params = Hash.new
  download_params["token"] = token
  download_params["name"] = self.name
  download_params["type"] = "gitlab-tag"
  if self.spec
    download_params["podspec"] = self.spec
  else
    download_params["podspec_content"] = @podspec_content
  end
  download_params["path"] = root_path.to_path
  if @source_files
    download_params["source_files"] = @source_files
  else
    download_params["source_files"] = "All"
  end
  download_params["download_urls"] = download_urls
  download_params
end