Class: LgPodPlugin::GitHubArchive

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

Instance Method Summary collapse

Constructor Details

#initialize(checkout_options = {}) ⇒ GitHubArchive

Returns a new instance of GitHubArchive.



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/lg_pod_plugin/git/github_archive.rb', line 15

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



27
28
29
30
31
32
33
34
35
# File 'lib/lg_pod_plugin/git/github_archive.rb', line 27

def download
  if self.git && self.tag
    self.github_download_tag_zip self.path
  elsif self.git && self.branch
    self.github_download_branch_zip self.path
  elsif self.git && self.commit
    self.github_download_commit_zip self.path
  end
end

#download_archive_zip(project_name) ⇒ Object

下载某个文件zip格式



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/lg_pod_plugin/git/github_archive.rb', line 111

def download_archive_zip(project_name)
  base_url = LUtils.get_gitlab_base_url(self.git)
  if base_url.include?("https://github.com/")
    repo_name = base_url.split("https://github.com/", 0).last
  elsif base_url.include?("[email protected]:")
    repo_name = base_url.split("[email protected]:", 0).last
  else
    repo_name = nil
  end
  return nil unless repo_name
  # network_ok = false
  # result = %x(ping gh.api.99988866.xyz -t 1)
  # if !result || result == "" || result.include?("timeout")
  #   network_ok = false
  # else
  #   network_ok = true
  # end
  if self.git && self.tag
    download_url = "https://codeload.github.com/#{repo_name}/tar.gz/refs/tags/#{self.tag}"
    [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
    # if network_ok
    #   repo_info = GithubAPI.get_repo_info(repo_name)
    #   html_url = repo_info["html_url"]
    #   if html_url
    #     base_url = html_url
    #   end
    #   download_url = "https://gh.api.99988866.xyz/#{base_url}/archive/refs/tags/#{self.tag}.tar.gz"
    #   [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
    # else
    #
    # end
  elsif self.git && self.branch
    if self.branch == "HEAD"
      download_url = "https://gh.api.99988866.xyz/" + "#{base_url}" + "/archive/#{self.branch}.tar.gz"
      [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
    else
      download_url = "https://codeload.github.com/#{repo_name}/tar.gz/refs/heads/#{self.branch}"
      [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
    end
    # if network_ok
    #   download_url = "https://gh.api.99988866.xyz/#{base_url}/archive/#{self.branch}.tar.gz"
    #   [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
    # else
    #
    # end
  elsif self.git && self.commit
    download_url = "https://codeload.github.com/#{repo_name}/tar.gz/#{self.commit}"
    return [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
  else
    nil
  end
end

#github_download_branch_zip(root_path) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/lg_pod_plugin/git/github_archive.rb', line 62

def github_download_branch_zip(root_path)
  project_name = LUtils.get_git_project_name self.git
  download_urls = self.download_archive_zip(project_name)
  # unless self.spec
  #   podspec_filename = self.name + ".podspec"
  #   podspec_content = GithubAPI.get_podspec_file_content self.git, self.commit, podspec_filename
  #   self.spec = LgPodPlugin::PodSpec.form_string(podspec_content, root_path + "/#{podspec_filename}") if podspec_content
  # end
  download_params = Hash.new
  download_params["name"] = self.name
  download_params["type"] = "github-branch"
  download_params["path"] = root_path.to_path
  download_params["download_urls"] = download_urls
  if self.spec
    download_params["podspec"] = self.spec
    download_params["source_files"] = self.spec.source_files.keys
  else
    download_params["podspec"] = nil
    download_params["source_files"] = ["All"]
    # download_params["podspec_content"] = podspec_content if podspec_content
  end
  download_params
end

#github_download_commit_zip(root_path) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/lg_pod_plugin/git/github_archive.rb', line 86

def github_download_commit_zip(root_path)
  project_name = LUtils.get_git_project_name self.git
  download_urls = self.download_archive_zip(project_name)
  # unless self.spec
  #   podspec_filename = self.name + ".podspec"
  #   podspec_content = GithubAPI.get_podspec_file_content self.git, self.commit, podspec_filename
  #   self.spec = LgPodPlugin::PodSpec.form_string(podspec_content, root_path + "/#{podspec_filename}") if podspec_content
  # end
  download_params = Hash.new
  download_params["name"] = self.name
  download_params["type"] = "github-commit"
  download_params["path"] = root_path.to_path
  download_params["download_urls"] = download_urls
  if self.spec
    download_params["podspec"] = self.spec
    download_params["source_files"] = self.spec.source_files.keys
  else
    download_params["podspec"] = nil
    download_params["source_files"] = ["All"]
    # download_params["podspec_content"] = podspec_content if podspec_content
  end
  download_params
end

#github_download_tag_zip(root_path) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/lg_pod_plugin/git/github_archive.rb', line 37

def github_download_tag_zip(root_path)
  project_name = LUtils.get_git_project_name self.git
  download_urls = self.download_archive_zip(project_name)
  # unless self.spec
  #   podspec_filename = self.name + ".podspec"
  #   podspec_content = GithubAPI.get_podspec_file_content self.git, self.commit, podspec_filename
  #   self.spec = LgPodPlugin::PodSpec.form_string(podspec_content, root_path + "/#{podspec_filename}") if podspec_content
  # end
  download_params = Hash.new
  download_params["name"] = self.name
  download_params["type"] = "github-tag"
  download_params["path"] = root_path.to_path
  download_params["download_urls"] = download_urls
  if self.spec
    download_params["podspec"] = self.spec
    download_params["source_files"] = self.spec.source_files.keys
    download_params["podspec_content"] = nil
  else
    download_params["podspec"] = nil
    download_params["source_files"] = ["All"]
    # download_params["podspec_content"] = podspec_content if podspec_content
  end
  download_params
end