21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
106
107
108
109
110
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
# File 'lib/fastlane/plugin/rocket/ref/ref_main.rb', line 21
def self.run(params,available_options)
Tools.formatLog(params,available_options);
pod_author = Tools.return_shell("git config user.name")
user_id = Tools.return_shell("git config user.id")
if user_id.nil? ||user_id.empty?
raise "请设置:git config user.id。user.id为gitlab的User ID,在用户设置里查看"
end
git = ENV["R_REF_GIT"]
branch = ENV["R_REF_BRANCH"]
all = false
pods = []
if ENV["R_REF_PODS"] != "ALL"
pods = ENV["R_REF_PODS"].split(",");
else
all = true
end
Tools.title("拉取工程仓库")
Tools.log("缓存地址 => #{REF_PATH}")
Tools.clone(git,branch,XCODEPROJ_PATH)
Tools.title("拉取HDSourceSpecs")
Tools.clone(Tools::SOURCESPECS,"master",SOURCESPECS_PATH)
Tools.title("pod update")
project_path = update()
Tools.title("生成pod对象集合")
lock_path = "#{project_path}/Podfile.lock"
pods_path = "#{project_path}/Pods"
pods_hash = RefPodInfo.analysis(lock_path,pods_path,SOURCESPECS_PATH)
Tools.title("生成被引用的库集合")
inspect_pods = inspect(all,pods,pods_hash)
Tools.title("开始检查...")
files_hash = RefPodInfo.files(pods_hash)
files = files_hash.values
files_str = files.join("\" \"")
Tools.shell("sed -i '' \"s/ //g\" \"#{files_str}\"")
git_paths = RefPodInfo.git_paths(pods_hash)
git_paths_str = git_paths.join("\" \"")
count = inspect_pods.keys.size
for i in 0..count-1
inspect_key = inspect_pods.keys[i]
inspect_info = inspect_pods[inspect_key]
name = inspect_info.name
Tools.title("检查#{name}中,进度#{i+1}/#{count}")
podsepc_rule = "\"#{name}\":"
podspec_shell = "fgrep '#{podsepc_rule}' \"#{git_paths_str}\""
tmp_hash = files_hash.clone
tmp_hash.delete(name)
select_files_str = tmp_hash.values.join("\" \"")
rules = []
rules << "import#{name}"
rules << "import<#{name}/"
rules << "import\"#{name}/"
if inspect_info.files_h_name.size != 0
rules << "#import\"" + inspect_info.files_h_name.join("' -e '#import\"")
end
rule_str = "-e '" + rules.join("' -e '") + "'"
note = Tools.return_shell("fgrep #{rule_str} \"#{select_files_str}\"&&#{podspec_shell}")
if note != -1
analysis(note,inspect_info,pods_path,pods_hash)
end
Tools.log("#{name}检查完成")
end
Tools.title("生成 #{LOCK_PATH}中...")
lock_file(inspect_pods,all)
Tools.log("使用命令打开查看详情:open #{LOCK_PATH}")
Tools.title("修复问题")
Tools.delete_path(PODS_PATH)
update_pods = Hash.new
branch_pods = Hash.new
inspect_pods.values.each do |inspect_info|
if inspect_info.deps.keys.size == 0 && inspect_info.reference_errors.keys.size == 0
next
end
Tools.title("修正#{inspect_info.name}引用问题...")
inspect_info.deps.keys.each do |key|
dep_info = inspect_info.deps[key].first
pod = pods_hash[key]
if dep_info.podspec_quote == true && !inspect_info.reference_errors.has_key?(key)
next
end
tmp_file = Dir.glob("#{PODS_PATH}/**/#{key}.podspec").first
if tmp_file.nil?
pod_path = "#{PODS_PATH}/#{key}"
unless File.directory?(pod_path)
Tools.clone(pod.git,branch,pod_path)
unless File.directory?(pod_path)
Tools.clone(pod.git,pod.version,pod_path)
branch_pods[key] = "master"
else
Tools.clone(pod.git,pod.version,pod_path)
branch_pods[key] = branch
end
end
else
pod_path = tmp_file.gsub("/#{key}.podspec","")
end
if dep_info.podspec_quote == false
podsepc_file = Dir.glob("#{pod_path}/**/#{key}.podspec").first
spec_n = Tools.return_shell("fgrep \"spec.name\" \"#{podsepc_file}\"")
Tools.shell("sed -i '' '$s/end//' '#{podsepc_file}'")
if spec_n == -1
str = " s.dependency '#{inspect_info.name}'\nend"
else
str = " spec.dependency '#{inspect_info.name}'\nend"
end
f = open("#{podsepc_file}","a")
f.puts(str)
f.close
end
if inspect_info.reference_errors.has_key?(key)
errors = inspect_info.reference_errors[key]
errors.each do |error|
file = Dir.glob("#{pod_path}/**/#{error.file_name}").first
notes = error.notes
old = "\"#{notes.split("\"")[1]}\""
str = "<#{inspect_info.name}/#{notes.split("\"")[1]}>"
tmp_notes = Tools.return_shell("grep '#{str}' \"#{file}\"")
if tmp_notes == -1
Tools.shell("sed -i '' 's##{old}##{str}#g' \"#{file}\"")
Tools.log("#{error.file_name}:#{old} => #{str}")
else
Tools.return_shell("sed -i '' '/#{old}/d' \"#{file}\"")
Tools.log("#{error.file_name}:#{old} => Delete")
end
end
end
update_pods[key] = pod_path
end
end
tmp_branch = "reocket_ref_fix"
web_urls = []
update_pods.keys.each do |key|
Tools.title("批量提交修改记录:#{key}")
path = update_pods[key]
branch_pod = branch_pods[key]
Tools.shell_list([
"cd #{path}",
"git status",
"if [ `git branch --list #{tmp_branch}` ];then git branch -D #{tmp_branch};fi",
"git checkout -b #{tmp_branch}",
"git add --all",
"git commit -m '[rocket][fix]修复使用库的类,却没有在podsepc引用的问题 提交人:#{pod_author}'",
"git push -f origin #{tmp_branch}"
])
pod = pods_hash[key]
name = pod.git.split("/")[-1].split(".git").first
projects = Tools.net_get("http://gitlab.dushuclub.io/api/v4/projects",{"search":"#{name}"})
if projects.size == 0
next
end
project_id = projects.first["id"]
params = {"id":"#{project_id}","source_branch":"#{tmp_branch}","target_branch":"#{branch_pod}","title":"[rocket][fix]修复使用库的类,却没有在podsepc引用的问题","remove_source_branch":"true","assignee_id":"#{user_id}"}
merge_requests = Tools.net_post("http://gitlab.dushuclub.io/api/v4/projects/#{project_id}/merge_requests",params)
web_url = merge_requests["web_url"]
web_urls << web_url
end
Tools.log("修正完成...")
web_urls = web_urls.uniq
Tools.logs("合并请求",web_urls)
end
|