lg_pod_plugin 1.1.3 → 1.1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lg +2 -2
- data/lib/command/command.rb +1 -2
- data/lib/command/install.rb +7 -2
- data/lib/command/update.rb +4 -1
- data/lib/lg_pod_plugin/config/l_config.rb +59 -0
- data/lib/lg_pod_plugin/config/lockfile_model.rb +59 -0
- data/lib/lg_pod_plugin/config/podspec.rb +266 -0
- data/lib/lg_pod_plugin/config/target.rb +33 -0
- data/lib/lg_pod_plugin/{database.rb → db/database.rb} +76 -16
- data/lib/lg_pod_plugin/downloader/downloader.rb +156 -0
- data/lib/lg_pod_plugin/{l_cache.rb → downloader/l_cache.rb} +42 -23
- data/lib/lg_pod_plugin/downloader/request.rb +239 -0
- data/lib/lg_pod_plugin/git/git_clone.rb +85 -0
- data/lib/lg_pod_plugin/git/git_download.rb +53 -0
- data/lib/lg_pod_plugin/git/github_api.rb +137 -0
- data/lib/lg_pod_plugin/git/github_archive.rb +165 -0
- data/lib/lg_pod_plugin/git/gitlab_api.rb +266 -0
- data/lib/lg_pod_plugin/git/gitlab_archive.rb +180 -0
- data/lib/lg_pod_plugin/git/http_download.rb +39 -0
- data/lib/lg_pod_plugin/installer/PodDownload +0 -0
- data/lib/lg_pod_plugin/installer/concurrency.rb +21 -0
- data/lib/lg_pod_plugin/installer/install.rb +111 -0
- data/lib/lg_pod_plugin/installer/main.rb +63 -0
- data/lib/lg_pod_plugin/installer/project.rb +47 -0
- data/lib/lg_pod_plugin/net/l_uri.rb +87 -0
- data/lib/lg_pod_plugin/net/net-ping.rb +27 -0
- data/lib/lg_pod_plugin/pod/external_pod.rb +21 -0
- data/lib/lg_pod_plugin/pod/release-pod.rb +158 -0
- data/lib/lg_pod_plugin/utils/aes-crypt.rb +82 -0
- data/lib/lg_pod_plugin/{file_path.rb → utils/file_path.rb} +3 -5
- data/lib/lg_pod_plugin/utils/l_util.rb +133 -0
- data/lib/lg_pod_plugin/{log.rb → utils/log.rb} +1 -1
- data/lib/lg_pod_plugin/{string.rb → utils/string.rb} +0 -0
- data/lib/lg_pod_plugin/version.rb +1 -1
- data/lib/lg_pod_plugin.rb +24 -9
- data/lib/sqlite3-1.5.3-arm64-darwin/API_CHANGES.md +49 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/CHANGELOG.md +462 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/CONTRIBUTING.md +24 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ChangeLog.cvs +88 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/README.md +235 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/dependencies.yml +14 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/aggregator.c +274 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/aggregator.h +12 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/backup.c +168 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/backup.h +15 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/database.c +853 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/database.h +17 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/exception.c +98 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/exception.h +8 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/extconf.rb +251 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/sqlite3.c +163 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/sqlite3_ruby.h +48 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/statement.c +442 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/ext/sqlite3/statement.h +16 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/faq/faq.md +431 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/faq/faq.rb +145 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/faq/faq.yml +426 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/2.6/sqlite3_native.bundle +0 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/2.7/sqlite3_native.bundle +0 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/3.0/sqlite3_native.bundle +0 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/3.1/sqlite3_native.bundle +0 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/constants.rb +50 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/database.rb +741 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/errors.rb +35 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/pragmas.rb +595 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/resultset.rb +187 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/statement.rb +145 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/translator.rb +118 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/value.rb +57 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3/version.rb +23 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/lib/sqlite3.rb +15 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/helper.rb +27 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_backup.rb +33 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_collation.rb +82 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_database.rb +545 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_database_flags.rb +95 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_database_readonly.rb +36 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_database_readwrite.rb +41 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_deprecated.rb +44 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_encoding.rb +155 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration.rb +507 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_aggregate.rb +336 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_open_close.rb +30 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_pending.rb +115 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_resultset.rb +142 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_integration_statement.rb +194 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_result_set.rb +37 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_sqlite3.rb +30 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_statement.rb +263 -0
- data/lib/sqlite3-1.5.3-arm64-darwin/test/test_statement_execute.rb +35 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/API_CHANGES.md +49 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/CHANGELOG.md +462 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/CONTRIBUTING.md +24 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ChangeLog.cvs +88 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/README.md +235 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/dependencies.yml +14 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/aggregator.c +274 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/aggregator.h +12 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/backup.c +168 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/backup.h +15 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/database.c +853 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/database.h +17 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/exception.c +98 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/exception.h +8 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/extconf.rb +251 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/sqlite3.c +163 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/sqlite3_ruby.h +48 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/statement.c +442 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/ext/sqlite3/statement.h +16 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/faq/faq.md +431 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/faq/faq.rb +145 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/faq/faq.yml +426 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/2.6/sqlite3_native.bundle +0 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/2.7/sqlite3_native.bundle +0 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/3.0/sqlite3_native.bundle +0 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/3.1/sqlite3_native.bundle +0 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/constants.rb +50 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/database.rb +741 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/errors.rb +35 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/pragmas.rb +595 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/resultset.rb +187 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/statement.rb +145 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/translator.rb +118 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/value.rb +57 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3/version.rb +23 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/lib/sqlite3.rb +15 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/helper.rb +27 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_backup.rb +33 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_collation.rb +82 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_database.rb +545 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_database_flags.rb +95 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_database_readonly.rb +36 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_database_readwrite.rb +41 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_deprecated.rb +44 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_encoding.rb +155 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration.rb +507 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_aggregate.rb +336 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_open_close.rb +30 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_pending.rb +115 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_resultset.rb +142 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_integration_statement.rb +194 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_result_set.rb +37 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_sqlite3.rb +30 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_statement.rb +263 -0
- data/lib/sqlite3-1.5.3-x86_64-darwin/test/test_statement_execute.rb +35 -0
- metadata +146 -53
- data/lib/lg_pod_plugin/downloader.rb +0 -57
- data/lib/lg_pod_plugin/gitlab_api.rb +0 -147
- data/lib/lg_pod_plugin/gitlab_archive.rb +0 -352
- data/lib/lg_pod_plugin/gitlab_download.rb +0 -159
- data/lib/lg_pod_plugin/install.rb +0 -81
- data/lib/lg_pod_plugin/l_config.rb +0 -83
- data/lib/lg_pod_plugin/l_util.rb +0 -145
- data/lib/lg_pod_plugin/net-ping.rb +0 -41
- data/lib/lg_pod_plugin/podspec.rb +0 -156
- data/lib/lg_pod_plugin/release-pod.rb +0 -90
- data/lib/lg_pod_plugin/request.rb +0 -221
- data/lib/lg_pod_plugin/runner.rb +0 -114
- data/lib/lg_pod_plugin/specification.rb +0 -52
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require_relative '../utils/l_util'
|
3
|
+
|
4
|
+
module LgPodPlugin
|
5
|
+
|
6
|
+
class GithubAPI
|
7
|
+
|
8
|
+
#获取 gitlab最新 commit_id
|
9
|
+
def self.request_github_refs_heads(git, branch)
|
10
|
+
base_url = LUtils.get_gitlab_base_url git
|
11
|
+
if base_url.include?("https://github.com/")
|
12
|
+
repo_name = base_url.split("https://github.com/", 0).last
|
13
|
+
elsif base_url.include?("git@github.com:")
|
14
|
+
repo_name = base_url.split("git@github.com:", 0).last
|
15
|
+
else
|
16
|
+
repo_name = nil
|
17
|
+
end
|
18
|
+
return [nil, nil] unless repo_name
|
19
|
+
request_url = "https://api.github.com/repos/" + repo_name
|
20
|
+
if branch
|
21
|
+
request_url += ("/branches")
|
22
|
+
else
|
23
|
+
request_url += ("/commits/" + "HEAD")
|
24
|
+
end
|
25
|
+
begin
|
26
|
+
uri = URI(request_url)
|
27
|
+
res = Net::HTTP.get_response(uri)
|
28
|
+
case res
|
29
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
30
|
+
json = JSON.parse(res.body)
|
31
|
+
if branch
|
32
|
+
return [nil, nil] unless json.is_a?(Array)
|
33
|
+
json.each do |element|
|
34
|
+
name = element["name"]
|
35
|
+
if name == branch
|
36
|
+
commit = element["commit"]
|
37
|
+
sha = commit["sha"]
|
38
|
+
return [sha, commit]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
return [nil, branch]
|
42
|
+
else
|
43
|
+
return [nil, nil] unless json.is_a?(Hash)
|
44
|
+
sha = json["sha"]
|
45
|
+
return [sha, branch]
|
46
|
+
end
|
47
|
+
else
|
48
|
+
return [nil, nil]
|
49
|
+
end
|
50
|
+
rescue
|
51
|
+
return [nil, nil]
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
public
|
57
|
+
def self.get_gitlab_repository_tree(git, sha)
|
58
|
+
base_url = LUtils.get_gitlab_base_url git
|
59
|
+
if base_url.include?("https://github.com/")
|
60
|
+
repo_name = base_url.split("https://github.com/", 0).last
|
61
|
+
elsif base_url.include?("git@github.com:")
|
62
|
+
repo_name = base_url.split("git@github.com:", 0).last
|
63
|
+
else
|
64
|
+
repo_name = nil
|
65
|
+
end
|
66
|
+
return [] unless repo_name
|
67
|
+
begin
|
68
|
+
uri = URI("https://api.github.com/repos/#{repo_name}/git/trees/#{sha}")
|
69
|
+
res = Net::HTTP.get_response(uri)
|
70
|
+
if res.body
|
71
|
+
json = JSON.parse(res.body)
|
72
|
+
else
|
73
|
+
json = Hash.new
|
74
|
+
end
|
75
|
+
return [] unless json && json.is_a?(Hash)
|
76
|
+
trees = json["tree"]
|
77
|
+
if trees && trees.is_a?(Array)
|
78
|
+
return trees
|
79
|
+
else
|
80
|
+
return []
|
81
|
+
end
|
82
|
+
rescue
|
83
|
+
return []
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
public
|
88
|
+
|
89
|
+
def self.get_podspec_file_content(git, sha, filename)
|
90
|
+
base_url = LUtils.get_gitlab_base_url git
|
91
|
+
if base_url.include?("https://github.com/")
|
92
|
+
repo_name = base_url.split("https://github.com/", 0).last
|
93
|
+
elsif base_url.include?("git@github.com:")
|
94
|
+
repo_name = base_url.split("git@github.com:", 0).last
|
95
|
+
else
|
96
|
+
repo_name = nil
|
97
|
+
end
|
98
|
+
return nil unless repo_name
|
99
|
+
trees = self.get_gitlab_repository_tree git, sha
|
100
|
+
return nil if trees.empty?
|
101
|
+
request_url = nil
|
102
|
+
trees.each do |dict|
|
103
|
+
type = dict["type"]
|
104
|
+
next if type == "tree"
|
105
|
+
path = dict["path"]
|
106
|
+
next unless path.include?(".podspec")
|
107
|
+
if path == filename
|
108
|
+
request_url = dict["url"]
|
109
|
+
break
|
110
|
+
end
|
111
|
+
end
|
112
|
+
begin
|
113
|
+
uri = URI(request_url)
|
114
|
+
res = Net::HTTP.get_response(uri)
|
115
|
+
if res.body
|
116
|
+
json = JSON.parse(res.body)
|
117
|
+
else
|
118
|
+
json = nil
|
119
|
+
end
|
120
|
+
return nil unless json && json.is_a?(Hash)
|
121
|
+
content = json["content"]
|
122
|
+
return nil unless content && LUtils.is_a_string?(content)
|
123
|
+
encoding = json["encoding"] ||= "base64"
|
124
|
+
if encoding == "base64"
|
125
|
+
content = LUtils.base64_decode(content)
|
126
|
+
return content
|
127
|
+
else
|
128
|
+
return nil
|
129
|
+
end
|
130
|
+
rescue
|
131
|
+
return nil
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require_relative 'git_download'
|
3
|
+
require_relative '../utils/l_util'
|
4
|
+
require_relative '../config/podspec'
|
5
|
+
|
6
|
+
module LgPodPlugin
|
7
|
+
|
8
|
+
class GitHubArchive
|
9
|
+
private
|
10
|
+
attr_reader :checkout_options
|
11
|
+
public
|
12
|
+
REQUIRED_ATTRS ||= %i[git tag name commit branch config path spec].freeze
|
13
|
+
attr_accessor(*REQUIRED_ATTRS)
|
14
|
+
|
15
|
+
def initialize(checkout_options = {})
|
16
|
+
self.git = checkout_options[:git]
|
17
|
+
self.tag = checkout_options[:tag]
|
18
|
+
self.name = checkout_options[:name]
|
19
|
+
self.path = checkout_options[:path]
|
20
|
+
self.spec = checkout_options[:spec]
|
21
|
+
self.config = checkout_options[:config]
|
22
|
+
self.commit = checkout_options[:commit]
|
23
|
+
self.branch = checkout_options[:branch]
|
24
|
+
@checkout_options = checkout_options
|
25
|
+
end
|
26
|
+
|
27
|
+
def download
|
28
|
+
if self.git && self.tag
|
29
|
+
self.github_download_tag_zip self.path
|
30
|
+
elsif self.git && self.branch
|
31
|
+
self.github_download_branch_zip self.path
|
32
|
+
elsif self.git && self.commit
|
33
|
+
self.github_download_commit_zip self.path
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def github_download_tag_zip(root_path)
|
38
|
+
project_name = LUtils.get_git_project_name self.git
|
39
|
+
download_urls = self.download_archive_zip(project_name)
|
40
|
+
# unless self.spec
|
41
|
+
# podspec_filename = self.name + ".podspec"
|
42
|
+
# podspec_content = GithubAPI.get_podspec_file_content self.git, self.commit, podspec_filename
|
43
|
+
# self.spec = LgPodPlugin::PodSpec.form_string(podspec_content, root_path + "/#{podspec_filename}") if podspec_content
|
44
|
+
# end
|
45
|
+
download_params = Hash.new
|
46
|
+
download_params["name"] = self.name
|
47
|
+
download_params["type"] = "github-tag"
|
48
|
+
download_params["path"] = root_path.to_path
|
49
|
+
download_params["download_urls"] = download_urls
|
50
|
+
if self.spec
|
51
|
+
download_params["podspec"] = self.spec
|
52
|
+
download_params["source_files"] = self.spec.source_files.keys
|
53
|
+
download_params["podspec_content"] = nil
|
54
|
+
else
|
55
|
+
download_params["podspec"] = nil
|
56
|
+
download_params["source_files"] = ["All"]
|
57
|
+
# download_params["podspec_content"] = podspec_content if podspec_content
|
58
|
+
end
|
59
|
+
download_params
|
60
|
+
end
|
61
|
+
|
62
|
+
def github_download_branch_zip(root_path)
|
63
|
+
project_name = LUtils.get_git_project_name self.git
|
64
|
+
download_urls = self.download_archive_zip(project_name)
|
65
|
+
# unless self.spec
|
66
|
+
# podspec_filename = self.name + ".podspec"
|
67
|
+
# podspec_content = GithubAPI.get_podspec_file_content self.git, self.commit, podspec_filename
|
68
|
+
# self.spec = LgPodPlugin::PodSpec.form_string(podspec_content, root_path + "/#{podspec_filename}") if podspec_content
|
69
|
+
# end
|
70
|
+
download_params = Hash.new
|
71
|
+
download_params["name"] = self.name
|
72
|
+
download_params["type"] = "github-branch"
|
73
|
+
download_params["path"] = root_path.to_path
|
74
|
+
download_params["download_urls"] = download_urls
|
75
|
+
if self.spec
|
76
|
+
download_params["podspec"] = self.spec
|
77
|
+
download_params["source_files"] = self.spec.source_files.keys
|
78
|
+
else
|
79
|
+
download_params["podspec"] = nil
|
80
|
+
download_params["source_files"] = ["All"]
|
81
|
+
# download_params["podspec_content"] = podspec_content if podspec_content
|
82
|
+
end
|
83
|
+
download_params
|
84
|
+
end
|
85
|
+
|
86
|
+
def github_download_commit_zip(root_path)
|
87
|
+
project_name = LUtils.get_git_project_name self.git
|
88
|
+
download_urls = self.download_archive_zip(project_name)
|
89
|
+
# unless self.spec
|
90
|
+
# podspec_filename = self.name + ".podspec"
|
91
|
+
# podspec_content = GithubAPI.get_podspec_file_content self.git, self.commit, podspec_filename
|
92
|
+
# self.spec = LgPodPlugin::PodSpec.form_string(podspec_content, root_path + "/#{podspec_filename}") if podspec_content
|
93
|
+
# end
|
94
|
+
download_params = Hash.new
|
95
|
+
download_params["name"] = self.name
|
96
|
+
download_params["type"] = "github-commit"
|
97
|
+
download_params["path"] = root_path.to_path
|
98
|
+
download_params["download_urls"] = download_urls
|
99
|
+
if self.spec
|
100
|
+
download_params["podspec"] = self.spec
|
101
|
+
download_params["source_files"] = self.spec.source_files.keys
|
102
|
+
else
|
103
|
+
download_params["podspec"] = nil
|
104
|
+
download_params["source_files"] = ["All"]
|
105
|
+
# download_params["podspec_content"] = podspec_content if podspec_content
|
106
|
+
end
|
107
|
+
download_params
|
108
|
+
end
|
109
|
+
|
110
|
+
# 下载某个文件zip格式
|
111
|
+
def download_archive_zip(project_name)
|
112
|
+
base_url = LUtils.get_gitlab_base_url(self.git)
|
113
|
+
if base_url.include?("https://github.com/")
|
114
|
+
repo_name = base_url.split("https://github.com/", 0).last
|
115
|
+
elsif base_url.include?("git@github.com:")
|
116
|
+
repo_name = base_url.split("git@github.com:", 0).last
|
117
|
+
else
|
118
|
+
repo_name = nil
|
119
|
+
end
|
120
|
+
return nil unless repo_name
|
121
|
+
# network_ok = false
|
122
|
+
# result = %x(ping gh.api.99988866.xyz -t 1)
|
123
|
+
# if !result || result == "" || result.include?("timeout")
|
124
|
+
# network_ok = false
|
125
|
+
# else
|
126
|
+
# network_ok = true
|
127
|
+
# end
|
128
|
+
if self.git && self.tag
|
129
|
+
download_url = "https://codeload.github.com/#{repo_name}/tar.gz/refs/tags/#{self.tag}"
|
130
|
+
[{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
|
131
|
+
# if network_ok
|
132
|
+
# repo_info = GithubAPI.get_repo_info(repo_name)
|
133
|
+
# html_url = repo_info["html_url"]
|
134
|
+
# if html_url
|
135
|
+
# base_url = html_url
|
136
|
+
# end
|
137
|
+
# download_url = "https://gh.api.99988866.xyz/#{base_url}/archive/refs/tags/#{self.tag}.tar.gz"
|
138
|
+
# [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
|
139
|
+
# else
|
140
|
+
#
|
141
|
+
# end
|
142
|
+
elsif self.git && self.branch
|
143
|
+
if self.branch == "HEAD"
|
144
|
+
download_url = "https://gh.api.99988866.xyz/" + "#{base_url}" + "/archive/#{self.branch}.tar.gz"
|
145
|
+
[{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
|
146
|
+
else
|
147
|
+
download_url = "https://codeload.github.com/#{repo_name}/tar.gz/refs/heads/#{self.branch}"
|
148
|
+
[{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
|
149
|
+
end
|
150
|
+
# if network_ok
|
151
|
+
# download_url = "https://gh.api.99988866.xyz/#{base_url}/archive/#{self.branch}.tar.gz"
|
152
|
+
# [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
|
153
|
+
# else
|
154
|
+
#
|
155
|
+
# end
|
156
|
+
elsif self.git && self.commit
|
157
|
+
download_url = "https://codeload.github.com/#{repo_name}/tar.gz/#{self.commit}"
|
158
|
+
return [{ "filename" => "#{project_name}.tar.gz", "url" => download_url }]
|
159
|
+
else
|
160
|
+
nil
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,266 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'net/http'
|
3
|
+
require_relative 'github_api'
|
4
|
+
require_relative '../utils/l_util'
|
5
|
+
|
6
|
+
module LgPodPlugin
|
7
|
+
|
8
|
+
class GitLabAPI
|
9
|
+
|
10
|
+
def self.get_gitlab_access_token_input(uri, user_id, username = nil, password = nil)
|
11
|
+
unless username && password
|
12
|
+
LgPodPlugin.log_yellow "请输入 `#{uri.to_s}` 的用户名"
|
13
|
+
username = STDIN.gets.chomp
|
14
|
+
LgPodPlugin.log_yellow "请输入 `#{uri.to_s}` 的密码"
|
15
|
+
password = STDIN.noecho(&:gets).chomp
|
16
|
+
end
|
17
|
+
GitLabAPI.request_gitlab_access_token(uri.hostname, username, password)
|
18
|
+
user_info = LSqliteDb.shared.query_user_info(user_id)
|
19
|
+
return user_info
|
20
|
+
end
|
21
|
+
|
22
|
+
public
|
23
|
+
|
24
|
+
# 获取 GitLab access_token
|
25
|
+
def self.request_gitlab_access_token(host, username, password)
|
26
|
+
user_id = LUserAuthInfo.get_user_id(host)
|
27
|
+
begin
|
28
|
+
uri = URI("#{host}/oauth/token")
|
29
|
+
hash_map = { "grant_type" => "password", "username" => username, "password" => password }
|
30
|
+
LgPodPlugin.log_green "开始请求 access_token, url => #{uri.to_s} "
|
31
|
+
req = Net::HTTP::Post.new(uri)
|
32
|
+
req.set_form_data(hash_map)
|
33
|
+
res = Net::HTTP.start((uri.hostname ||= ""), uri.port) do |http|
|
34
|
+
http.open_timeout = 15
|
35
|
+
http.read_timeout = 15
|
36
|
+
http.request(req)
|
37
|
+
end
|
38
|
+
case res
|
39
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
40
|
+
json = JSON.parse(res.body)
|
41
|
+
else
|
42
|
+
json = JSON.parse(res.body)
|
43
|
+
raise json["error_description"]
|
44
|
+
end
|
45
|
+
access_token = json["access_token"]
|
46
|
+
refresh_token = json["refresh_token"]
|
47
|
+
expires_in = json["expires_in"] ||= 7200
|
48
|
+
created_at = json["created_at"] ||= Time.now.to_i
|
49
|
+
user_model = LUserAuthInfo.new(user_id, username, password, host, access_token, refresh_token, (created_at + expires_in))
|
50
|
+
LSqliteDb.shared.insert_user_info(user_model)
|
51
|
+
LgPodPlugin.log_green "请求成功: `access_token` => #{access_token}, expires_in => #{expires_in}"
|
52
|
+
rescue => exception
|
53
|
+
LSqliteDb.shared.delete_user_info(user_id)
|
54
|
+
LgPodPlugin.log_red "获取 `access_token` 失败, error => #{exception.to_s}"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# 刷新gitlab_token
|
59
|
+
def self.refresh_gitlab_access_token(host, refresh_token)
|
60
|
+
begin
|
61
|
+
hash_map = Hash.new
|
62
|
+
hash_map["scope"] = "api"
|
63
|
+
hash_map["grant_type"] = "refresh_token"
|
64
|
+
hash_map["refresh_token"] = refresh_token
|
65
|
+
uri = URI("#{host}/oauth/token")
|
66
|
+
res = Net::HTTP.post_form(uri, hash_map)
|
67
|
+
if res.body
|
68
|
+
json = JSON.parse(res.body)
|
69
|
+
else
|
70
|
+
return nil
|
71
|
+
end
|
72
|
+
return nil unless json.is_a?(Hash)
|
73
|
+
error = json["error"]
|
74
|
+
if error != nil
|
75
|
+
error_description = json["error_description"]
|
76
|
+
raise error_description
|
77
|
+
end
|
78
|
+
access_token = json["access_token"]
|
79
|
+
refresh_token = json["refresh_token"]
|
80
|
+
expires_in = json["expires_in"] ||= 7200
|
81
|
+
created_at = json["created_at"] ||= Time.now.to_i
|
82
|
+
user_id = LUserAuthInfo.get_user_id(host)
|
83
|
+
user_model = LSqliteDb.shared.query_user_info(user_id)
|
84
|
+
user_model.expires_in = (created_at + expires_in)
|
85
|
+
user_model.access_token = access_token
|
86
|
+
user_model.refresh_token = refresh_token
|
87
|
+
LSqliteDb.shared.insert_user_info(user_model)
|
88
|
+
return user_model
|
89
|
+
rescue => exception
|
90
|
+
LgPodPlugin.log_yellow "刷新 `access_token` 失败, error => #{exception.to_s}"
|
91
|
+
return nil
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# 通过名称搜索项目信息
|
96
|
+
def self.request_project_info(host, project_name, access_token, git = nil)
|
97
|
+
begin
|
98
|
+
hash_map = Hash.new
|
99
|
+
hash_map["search"] = project_name
|
100
|
+
hash_map["access_token"] = access_token
|
101
|
+
uri = URI("#{host}/api/v4/projects")
|
102
|
+
uri.query = URI.encode_www_form(hash_map)
|
103
|
+
res = Net::HTTP.get_response(uri)
|
104
|
+
if res.body
|
105
|
+
array = JSON.parse(res.body)
|
106
|
+
else
|
107
|
+
array = nil
|
108
|
+
end
|
109
|
+
return nil unless array && array.is_a?(Array)
|
110
|
+
array.each do |json|
|
111
|
+
name = json["name"] ||= ""
|
112
|
+
path = json["path"] ||= ""
|
113
|
+
path_with_namespace = json["path_with_namespace"] ||= ""
|
114
|
+
name_with_namespace = (json["name_with_namespace"] ||= "").gsub(/[ ]/, '')
|
115
|
+
if git.include?(path_with_namespace)
|
116
|
+
id = json["id"]
|
117
|
+
web_url = json["web_url"]
|
118
|
+
description = json["description"]
|
119
|
+
ssh_url_to_repo = json["ssh_url_to_repo"]
|
120
|
+
http_url_to_repo = json["http_url_to_repo"]
|
121
|
+
project = ProjectModel.new(id, name, description, path, ssh_url_to_repo, http_url_to_repo, web_url, name_with_namespace, path_with_namespace)
|
122
|
+
LSqliteDb.shared.insert_project(project)
|
123
|
+
return project
|
124
|
+
end
|
125
|
+
end
|
126
|
+
return nil
|
127
|
+
rescue
|
128
|
+
return nil
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
#请求gitlab api 获取 branch 最新的 commit
|
133
|
+
def self.request_gitlab_refs_heads(git, branch, uri)
|
134
|
+
config = LConfig.get_config(git, uri)
|
135
|
+
project = config.project
|
136
|
+
return self.use_default_refs_heads(git, branch) unless config
|
137
|
+
unless project
|
138
|
+
project_name = LUtils.get_git_project_name git
|
139
|
+
project = GitLabAPI.request_project_info(config.host, project_name, config.access_token, git)
|
140
|
+
end
|
141
|
+
return self.use_default_refs_heads(git, branch) unless project && project.id
|
142
|
+
begin
|
143
|
+
new_branch = branch ? branch : "HEAD"
|
144
|
+
api = uri.hostname + "/api/v4/projects/" + project.id + "/repository/commits/" + new_branch
|
145
|
+
req_uri = URI(api)
|
146
|
+
req_uri.query = URI.encode_www_form({ "access_token": config.access_token })
|
147
|
+
res = Net::HTTP.get_response(req_uri)
|
148
|
+
case res
|
149
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
150
|
+
json = JSON.parse(res.body)
|
151
|
+
return [nil, nil] unless json && json.is_a?(Hash)
|
152
|
+
sha = json["id"]
|
153
|
+
return [sha, nil]
|
154
|
+
else
|
155
|
+
body = JSON.parse(res.body)
|
156
|
+
message = body["message"]
|
157
|
+
if message == "404 Project Not Found"
|
158
|
+
LSqliteDb.shared.delete_project_by_id(project.id)
|
159
|
+
end
|
160
|
+
return self.use_default_refs_heads git, branch
|
161
|
+
end
|
162
|
+
rescue => exception
|
163
|
+
LgPodPlugin.log_red "request_gitlab_refs_heads => #{exception}"
|
164
|
+
return self.use_default_refs_heads git, branch
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
# 使用 git 命令获取commit信息
|
169
|
+
def self.use_default_refs_heads(git, branch)
|
170
|
+
result = LUtils.refs_from_ls_remote git, branch
|
171
|
+
unless result && !result.empty?
|
172
|
+
return [nil, nil]
|
173
|
+
end
|
174
|
+
refs = branch ? branch : "HEAD"
|
175
|
+
new_commit, new_branch = LUtils.sha_from_result(result, refs)
|
176
|
+
return [new_commit, new_branch]
|
177
|
+
end
|
178
|
+
|
179
|
+
# 通过github api 获取 git 最新commit
|
180
|
+
def self.request_github_refs_heads(git, branch, uri = nil)
|
181
|
+
return [nil, nil] unless git
|
182
|
+
unless git.include?("https://github.com/") || git.include?("git@github.com:")
|
183
|
+
if LgPodPlugin::LUtils.is_gitlab_uri(git, "")
|
184
|
+
return self.request_gitlab_refs_heads(git, branch, uri)
|
185
|
+
end
|
186
|
+
return self.use_default_refs_heads git, branch
|
187
|
+
end
|
188
|
+
commit, _ = GithubAPI.request_github_refs_heads git, branch
|
189
|
+
if commit
|
190
|
+
return [commit, branch]
|
191
|
+
else
|
192
|
+
return self.use_default_refs_heads git, branch
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
#获取项目中仓库文件和目录的列表
|
197
|
+
# def self.get_gitlab_repository_tree(host, token, project_id, sha)
|
198
|
+
# begin
|
199
|
+
# hash_map = Hash.new
|
200
|
+
# hash_map["ref"] = sha
|
201
|
+
# hash_map["access_token"] = token
|
202
|
+
# hash_map["per_page"] = 50
|
203
|
+
# uri = URI("#{host}/api/v4/projects/#{project_id}/repository/tree")
|
204
|
+
# uri.query = URI.encode_www_form(hash_map)
|
205
|
+
# res = Net::HTTP.get_response(uri)
|
206
|
+
# if res.body
|
207
|
+
# array = JSON.parse(res.body)
|
208
|
+
# else
|
209
|
+
# array = nil
|
210
|
+
# end
|
211
|
+
# return Set.new unless array && array.is_a?(Array)
|
212
|
+
# files = array.collect { |dict|
|
213
|
+
# dict["path"]
|
214
|
+
# }
|
215
|
+
# set = Set.new.merge files
|
216
|
+
# return set
|
217
|
+
# rescue
|
218
|
+
# return Set.new
|
219
|
+
# end
|
220
|
+
# end
|
221
|
+
|
222
|
+
public
|
223
|
+
|
224
|
+
def self.get_podspec_file_content(host, token, project_id, sha, filepath)
|
225
|
+
begin
|
226
|
+
hash_map = Hash.new
|
227
|
+
hash_map["ref"] = sha
|
228
|
+
hash_map["access_token"] = token
|
229
|
+
uri = URI("#{host}/api/v4/projects/#{project_id}/repository/files/#{filepath}")
|
230
|
+
uri.query = URI.encode_www_form(hash_map)
|
231
|
+
res = Net::HTTP.get_response(uri)
|
232
|
+
case res
|
233
|
+
when Net::HTTPSuccess, Net::HTTPRedirection
|
234
|
+
json = JSON.parse(res.body)
|
235
|
+
else
|
236
|
+
body = JSON.parse(res.body)
|
237
|
+
message = body["message"]
|
238
|
+
if message == "404 Project Not Found"
|
239
|
+
LSqliteDb.shared.delete_project_by_id(project_id)
|
240
|
+
end
|
241
|
+
json = nil
|
242
|
+
end
|
243
|
+
return nil unless json && json.is_a?(Hash)
|
244
|
+
content = json["content"]
|
245
|
+
return nil unless content && LUtils.is_a_string?(content)
|
246
|
+
encoding = json["encoding"] ||= "base64"
|
247
|
+
if encoding == "base64"
|
248
|
+
require 'base64'
|
249
|
+
content = Base64.decode64(content)
|
250
|
+
if content.respond_to?(:encoding) && content.encoding.name != 'UTF-8'
|
251
|
+
text = content.force_encoding("gb2312").force_encoding("utf-8")
|
252
|
+
return text
|
253
|
+
else
|
254
|
+
return content
|
255
|
+
end
|
256
|
+
else
|
257
|
+
return nil
|
258
|
+
end
|
259
|
+
rescue
|
260
|
+
return nil
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
end
|
265
|
+
|
266
|
+
end
|