podsorz 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,195 @@
1
+ require "podsorz/util/logger"
2
+ require 'open3'
3
+
4
+ module PodsOrz
5
+ class PodsRepo
6
+ attr_accessor :repo_name, :repo_url
7
+
8
+ def check_repo_exist
9
+ command = Thread.new do
10
+ @repo_name = "kuxiu_specs"
11
+ @repo_url = "git@gitlab.91banban.com:ios_pods/Specs.git"
12
+
13
+ has_repo = false
14
+ Open3.popen3("pod repo list") do |stdin , stdout , stderr, wait_thr|
15
+ while line = stdout.gets
16
+ has_repo = true if line.include? @repo_name
17
+ end
18
+ end
19
+
20
+ unless has_repo
21
+ Open3.popen3("pod repo add #{@repo_name} #{@repo_url}") do |stdin , stdout , stderr, wait_thr|
22
+ while line = stdout.gets
23
+ puts line
24
+ end
25
+ end
26
+ end
27
+
28
+ Open3.popen3("pod repo update #{@repo_name}") do |stdin , stdout , stderr, wait_thr|
29
+ while line = stdout.gets
30
+ puts line
31
+ end
32
+ end
33
+
34
+ Logger.default("#{@repo_name} is update to latest.")
35
+ end
36
+
37
+ command.join
38
+ end
39
+
40
+ def ensure_local_pod_version_tag(pod, pod_version, git_tag)
41
+ #-1 => error or pod_version less than git_tag, 0 => same version, 1 => need add new tag
42
+ compare_result = compare_version(pod_version, git_tag)
43
+
44
+ case compare_result
45
+ when 0
46
+ #same
47
+ Logger.default("#{pod}:#{pod_version} same with local git_tag:#{git_tag}")
48
+ when -1
49
+ #less than git_tag
50
+ Logger.error("#{pod}:#{pod_version} is less than git tag:#{git_tag} \n please checkout manual,make sure latest_pod_version = (previous_git_tag +1).It would be great if you could also remove the invalid tag:#{pod_version} this time. It doesn't matter if you don't delete it")
51
+ when 1
52
+ #large than git_tag
53
+ Logger.warning("#{pod}:#{pod_version} large than git_tag:#{git_tag}")
54
+ end
55
+
56
+ compare_result;
57
+
58
+ end
59
+
60
+ def ensure_remote_pod_version(pod, pod_version)
61
+ remote_version = "0.0.0"
62
+ remote_version = fetch_remote_pod_version(pod)
63
+
64
+ #-1 => error or pod_version less than git_tag, 0 => same version, 1 => publish new version
65
+ compare_result = compare_version(pod_version, remote_version)
66
+
67
+ case compare_result
68
+ when 0
69
+ #same
70
+ Logger.default("#{pod}:#{pod_version} has nothing to update remote kuxiu_specs")
71
+ when -1
72
+ #less than remote version
73
+ Logger.error("#{pod}:#{pod_version} is less than remote:#{remote_version} \n please checkout manual,make sure local_pod_version = (remote_version +1).It would be great if you could also remove the invalid tag:#{pod_version} this time. It doesn't matter if you don't delete it")
74
+ when 1
75
+ #large than remote version
76
+ Logger.warning("#{pod}:#{pod_version} large than remote:#{remote_version}, will start update remote")
77
+ end
78
+
79
+ compare_result;
80
+ end
81
+
82
+ def fetch_remote_pod_version(pod)
83
+ version = "0.0.0"
84
+
85
+ dir_kuxiu_specs = "#{Dir.home}/.cocoapods/repos/kuxiu_specs"
86
+ dir_pod_path = File.expand_path("#{pod}", dir_kuxiu_specs)
87
+ is_dir_exit = File.directory?(dir_pod_path)
88
+
89
+ unless is_dir_exit
90
+ Logger.warning("#{pod} remote spec do not exist, default version: 0.0.0")
91
+ return version
92
+ end
93
+
94
+ filter_list = []
95
+ files_list = Dir.entries(dir_pod_path)
96
+ files_list.each { |e|
97
+ if /^\d{1,3}\.\d{1,3}/ =~ e.to_s
98
+ filter_list << e
99
+ end
100
+ }
101
+
102
+ if filter_list.empty?
103
+ Logger.warning("#{pod} remote spec do not exist available version, default version: 0.0.0")
104
+ return version
105
+ end
106
+
107
+ sort_array = filter_list.sort { |a, b|
108
+ compare_version(a,b)
109
+ }
110
+ version = sort_array.pop
111
+
112
+ return version
113
+ end
114
+
115
+ def compare_version(pod_version, git_tag)
116
+ #0 => same , -1 => less , 1 => more
117
+ result = 0
118
+
119
+ pod_version = pod_version.strip.chomp
120
+ git_tag = git_tag.strip.chomp
121
+
122
+ version_parts = pod_version.split('.')
123
+ tag_parts = git_tag.split('.')
124
+
125
+ loop_count = 0
126
+ if version_parts.size >= tag_parts.size
127
+ loop_count = version_parts.size - tag_parts.size
128
+ while loop_count > 0 do
129
+ tag_parts << "0"
130
+ loop_count = loop_count - 1
131
+ end
132
+ else
133
+ loop_count = tag_parts.size - version_parts.size
134
+ while loop_count > 0 do
135
+ version_parts << "0"
136
+ loop_count = loop_count - 1
137
+ end
138
+ end
139
+
140
+ loop_count = tag_parts.size
141
+ while loop_count > 0 do
142
+ v = version_parts.shift
143
+ t = tag_parts.shift
144
+
145
+ if v.to_i > t.to_i
146
+ result = 1
147
+ return result
148
+ elsif v.to_i < t.to_i
149
+ result = -1
150
+ return result
151
+ else
152
+ loop_count = loop_count -1
153
+ end
154
+ end
155
+
156
+ return result
157
+
158
+ end
159
+
160
+ def push_pod_remote(pod, file_path, pod_version)
161
+ is_push_success = false
162
+
163
+ command = Thread.new do
164
+ repo_push_cmd = []
165
+ repo_push_cmd << "cd #{file_path}"
166
+ repo_push_cmd << "pod repo push #{@repo_name} #{pod}.podspec --allow-warnings --use-libraries --skip-import-validation --sources=#{@repo_url}"
167
+
168
+ error_info = []
169
+
170
+ Logger.default("【#{pod}】:#{pod_version} start push repo remote...")
171
+
172
+ IO.popen(repo_push_cmd.join(";")) do |io|
173
+ io.each do |line|
174
+ error_info.push(line)
175
+ is_push_success = true if line.include? "Pushing the `#{@repo_name}' repo"
176
+ end
177
+ end
178
+
179
+ unless is_push_success
180
+ puts error_info
181
+ Logger.error("Fail: \'#{pod}\':#{pod_version} push repo remote fail")
182
+ return is_push_success
183
+ end
184
+
185
+ Logger.highlight(%Q(#{pod}:#{pod_version} push repo success))
186
+ end
187
+
188
+ command.join
189
+
190
+ is_push_success
191
+ end
192
+
193
+ end
194
+
195
+ end
@@ -0,0 +1,138 @@
1
+ require "podsorz/util/logger"
2
+
3
+
4
+ module PodsOrz
5
+ class PodsVersion
6
+ attr_accessor :kx_pods_path
7
+
8
+ def initialize(main_path)
9
+ @kx_pods_path = File.expand_path("../kx_pods", main_path)
10
+ end
11
+
12
+ def increase_pod_version(pod)
13
+ latest_version = ""
14
+
15
+ is_increase_success = true
16
+ is_increase_success = detect_pod_version_file(pod)
17
+ return latest_version unless is_increase_success
18
+
19
+ #increase
20
+ file_path = File.expand_path("#{pod}/#{pod}.podspec", @kx_pods_path)
21
+
22
+ update_lines = []
23
+ edite_line = ""
24
+
25
+ File.open(file_path, "r") do |file|
26
+ file.readlines.each do |line|
27
+ l = line.strip.chomp
28
+ next if l.start_with?("#")
29
+
30
+ if /\.(version)(.*) =/ =~ line
31
+ version_num = $~.post_match.strip.chomp.to_s
32
+ version_num = version_num.gsub(/[\'\"]/, "")
33
+
34
+ unless /\d{1,}\.\d{1,}/ =~ version_num
35
+ update_lines << line
36
+ next
37
+ end
38
+
39
+ part_nums = version_num.split('.')
40
+ last_num = part_nums.pop
41
+
42
+ if last_num.to_i >= 99
43
+ pre_num = part_nums.pop
44
+
45
+ if pre_num.to_i >= 99
46
+ pre_pre_num = part_nums.pop
47
+ pre_pre_num = (pre_num.to_i + 1).to_s
48
+ pre_num = "0"
49
+
50
+ part_nums << pre_pre_num
51
+ part_nums << pre_num
52
+ part_nums << last_num
53
+ else
54
+ pre_num = (pre_num.to_i + 1).to_s
55
+ last_num = "0"
56
+
57
+ part_nums << pre_num
58
+ part_nums << last_num
59
+ end
60
+ else
61
+ last_num = (last_num.to_i + 1).to_s
62
+ part_nums << last_num
63
+ end
64
+
65
+ latest_version = part_nums.join('.')
66
+
67
+ parts_line = line.split('=')
68
+ edite_line = parts_line[0] + "= " + "\'#{latest_version}\'" + "\n"
69
+
70
+ update_lines << edite_line
71
+ else
72
+ update_lines << line
73
+ end
74
+
75
+ end
76
+ end
77
+
78
+ if edite_line.empty?
79
+ Logger.error("#{pod}.podspec can not find \'.version = \', increase failure")
80
+ return latest_version
81
+ end
82
+
83
+
84
+ File.open(file_path, "w+") {|file|
85
+ Logger.highlight("#{pod}.podspec version inscrease completed!")
86
+ update_lines.each do |line|
87
+ file.write(line)
88
+ end
89
+ }
90
+
91
+ latest_version
92
+ end
93
+
94
+ def detect_pod_version_file(pod)
95
+ detect_result = true
96
+ file_path = File.expand_path("#{pod}/#{pod}.podspec", @kx_pods_path)
97
+ detect_result = File.exist?(file_path)
98
+
99
+ unless detect_result
100
+ Logger.error("【#{pod}】not exist .podspec file at file path: #{file_path}")
101
+ end
102
+
103
+ detect_result
104
+ end
105
+
106
+ def get_podspec_version(pod)
107
+ result_version_num = ""
108
+
109
+ return result_version_num unless detect_pod_version_file(pod)
110
+
111
+ file_path = File.expand_path("#{pod}/#{pod}.podspec", @kx_pods_path)
112
+
113
+ File.open(file_path, "r") do |file|
114
+ file.readlines.each do |line|
115
+ l = line.strip.chomp
116
+ next if l.start_with?("#")
117
+
118
+ if /\.(version)(.*) =/ =~ line
119
+ version_num = $~.post_match.strip.chomp.to_s
120
+ version_num = version_num.gsub(/[\'\"]/, "")
121
+
122
+ unless /\d{1,}\.\d{1,}/ =~ version_num
123
+ next
124
+ end
125
+
126
+ result_version_num = version_num
127
+ end
128
+
129
+ end
130
+ end
131
+
132
+ Logger.error("#{pod}.podspec can not find \'.version = \'") if result_version_num.empty?
133
+
134
+ result_version_num
135
+ end
136
+ end
137
+
138
+ end
@@ -0,0 +1,208 @@
1
+ require File.expand_path("../util/logger.rb", File.dirname(__FILE__))
2
+
3
+ module PodsOrz
4
+ class GitOperator
5
+ def current_branch(path)
6
+ Dir.chdir(path) do
7
+ `git rev-parse --abbrev-ref HEAD`.chop
8
+ end
9
+ end
10
+
11
+ def has_remote_branch(path, branch_name)
12
+ has_branch = false
13
+ IO.popen("cd '#{path}';git fetch --all;git branch -r") do |io|
14
+ io.each do |line|
15
+ has_branch = true if line.include? branch_name
16
+ end
17
+ end
18
+ has_branch
19
+ end
20
+
21
+ def has_local_branch(path, branch_name)
22
+ has_branch = false
23
+ IO.popen("cd '#{path}';git branch") do |io|
24
+ io.each do |line|
25
+ has_branch = true if line.include? branch_name
26
+ end
27
+ end
28
+ has_branch
29
+ end
30
+
31
+ def has_branch(path, branch_name)
32
+ has_branch = false
33
+ IO.popen("cd '#{path}';git fetch --all;git branch -a") do |io|
34
+ io.each do |line|
35
+ has_branch = true if line.include? branch_name
36
+ end
37
+ end
38
+ has_branch
39
+ end
40
+
41
+ def checkout(path, branch_name)
42
+ Dir.chdir(path) do
43
+ IO.popen("git checkout #{branch_name}") do |io|
44
+ io.each do |line|
45
+ Logger.error("Checkout #{branch_name} failed.") if line.include? 'error'
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ def fetch(path)
52
+ Dir.chdir(path) do
53
+ `git fetch origin`
54
+ end
55
+ end
56
+
57
+ def rebase(path, branch_name)
58
+ Dir.chdir(path) do
59
+ `git rebase origin/#{branch_name}`
60
+ end
61
+ end
62
+
63
+ def clone(path, git_base)
64
+ Dir.chdir(path) do
65
+ `git clone #{git_base}`
66
+ end
67
+ end
68
+
69
+ def commit(path, message)
70
+ Dir.chdir(path) do
71
+ `git add .`
72
+ `git commit -m "#{message}"`
73
+ end
74
+ end
75
+
76
+ def push_to_remote(path, branch_name)
77
+ Dir.chdir(path) do
78
+ `git push -u origin #{branch_name}`
79
+ end
80
+ end
81
+
82
+ def pull(path)
83
+ Dir.chdir(path) do
84
+ `git pull`
85
+ end
86
+ end
87
+
88
+ def has_commits(path, branch_name)
89
+ has_commits = false
90
+ IO.popen("cd '#{path}'; git log --branches --not --remotes") do |io|
91
+ io.each do |line|
92
+ has_commits = true if line.include? "commit"
93
+ end
94
+ end
95
+ has_commits
96
+ end
97
+
98
+ def has_changes(path)
99
+ has_changes = true
100
+ clear_flag = 'nothing to commit, working tree clean'
101
+ IO.popen("cd '#{path}'; git status") do |io|
102
+ io.each do |line|
103
+ has_changes = false if line.include? clear_flag
104
+ end
105
+ end
106
+ has_changes
107
+ end
108
+
109
+ def discard(path)
110
+ Dir.chdir(path) do
111
+ `git checkout . && git clean -df`
112
+ end
113
+ end
114
+
115
+ def del_local(path, branch_name)
116
+ Dir.chdir(path) do
117
+ `git branch -D #{branch_name}`
118
+ end
119
+ end
120
+
121
+ def del_remote(path, branch_name)
122
+ Dir.chdir(path) do
123
+ `git push origin --delete #{branch_name}`
124
+ end
125
+ end
126
+
127
+ def user
128
+ name = `git config user.name`.chop
129
+ cn_reg = /[\u4e00-\u9fa5]{1}/
130
+ cn_arr = name.scan(cn_reg)
131
+ if cn_arr.count > 0
132
+ Logger.error("git config user.name has Chinese character")
133
+ else
134
+ name.gsub(/[^0-9A-Za-z]/, '').downcase
135
+ end
136
+ end
137
+
138
+ def tag(path, version)
139
+ tags = Array.new
140
+ IO.popen("cd '#{path}'; git tag") do |io|
141
+ io.each do |line|
142
+ tags << line
143
+ end
144
+ end
145
+ unless tags.include? "#{version}\n"
146
+ Dir.chdir(path) do
147
+ `git tag -a #{version} -m "release: V #{version}" master;`
148
+ `git push --tags`
149
+ end
150
+ return
151
+ end
152
+ Logger.highlight("tag already exists in the remote, skip this step")
153
+ end
154
+
155
+ def tag_list(path)
156
+ tag_list = Array.new
157
+ IO.popen("cd '#{path}'; git tag -l --sort=-version:refname") do |io|
158
+ io.each do |line|
159
+ tag_list << line
160
+ end
161
+ end
162
+ tag_list
163
+ end
164
+
165
+ def check_merge(path, condition)
166
+ unmerged_branch = Array.new
167
+ IO.popen("cd '#{path}'; git branch --no-merged") do |io|
168
+ io.each do |line|
169
+ unmerged_branch.push(line) if line.include? "#{condition}"
170
+ end
171
+ end
172
+ if (unmerged_branch.size > 0)
173
+ unmerged_branch.map { |item|
174
+ Logger.default(item)
175
+ }
176
+ Logger.error("Still has unmerged feature branch, please check")
177
+ end
178
+ end
179
+
180
+ def merge(path, branch_name)
181
+ IO.popen("cd '#{path}'; git merge #{branch_name}") do |line|
182
+ Logger.error("Merge conflict in #{branch_name}") if line.include? 'Merge conflict'
183
+ end
184
+ end
185
+
186
+ def compare_branch(path, branch, compare_branch)
187
+ diff_commit_list = []
188
+
189
+ compare_cmd_list = []
190
+ compare_cmd_list << "cd #{path}"
191
+ compare_cmd_list << "git log --left-right #{branch}...#{compare_branch} --pretty=oneline"
192
+
193
+ IO.popen(compare_cmd_list.join(";")) do |io|
194
+ io.each do |line|
195
+ diff_commit_list << line unless line.strip.chomp.empty?
196
+ end
197
+
198
+ end
199
+
200
+ diff_commit_list
201
+ end
202
+
203
+
204
+
205
+
206
+ end
207
+
208
+ end