pixab 1.1.3 → 1.2.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.
- checksums.yaml +4 -4
- data/exe/pixab +6 -0
- data/lib/ComponentSynchronizer.rb +7 -5
- data/lib/GitUtils.rb +146 -0
- data/lib/MergeRequest.rb +44 -24
- data/lib/Package.rb +50 -0
- data/lib/RepoManager.rb +14 -3
- data/lib/Utilities.rb +15 -1
- data/lib/pixab/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 465c3b05af7e8d11f5fd4b439052fa3dbe29f4e3bc8c16e1299d19fb7dc278e7
|
4
|
+
data.tar.gz: 4c3dd3ef7d60511a00bb9fc57df5ff35e40b9faf3686e1c4d4f131d6d6aefd34
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78ca01d716329db426c40ff7103b03ebee3cbb4b09b9c8467ccd822cc60de4a48b4b9473516cbdfcd3bee824963425b1104669fa82ed5b94d1ae991643edc5c6
|
7
|
+
data.tar.gz: cdc919b196b24c97040c8cde8118a09aeae0f27be69cc8d2e5e07ff73f5c062aea70469e82c5a288e793ba700ae5b083415c23be10354f8eff5476a5a30eec12
|
data/exe/pixab
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
#!/usr/bin/env ruby
|
3
3
|
# encoding: UTF-8
|
4
4
|
|
5
|
+
require_relative "../lib/pixab/version"
|
5
6
|
require_relative '../lib/MergeRequest.rb'
|
6
7
|
require_relative '../lib/ComponentSynchronizer.rb'
|
7
8
|
require_relative '../lib/Localization.rb'
|
9
|
+
require_relative '../lib/Package.rb'
|
8
10
|
|
9
11
|
case ARGV[0]
|
10
12
|
when 'merge'
|
@@ -29,6 +31,10 @@ when 'sync'
|
|
29
31
|
end
|
30
32
|
when 'localize'
|
31
33
|
Pixab::Localization.new.run(ARGV[1..-1])
|
34
|
+
when 'package'
|
35
|
+
Pixab::Package.new.run
|
36
|
+
when '--version'
|
37
|
+
puts Pixab::VERSION
|
32
38
|
else
|
33
39
|
puts "Invalid command".red
|
34
40
|
end
|
@@ -57,12 +57,14 @@ module Pixab
|
|
57
57
|
def replace_local_to_remote
|
58
58
|
active_repo_names = ""
|
59
59
|
repos.each do |repo|
|
60
|
-
components = repo["components"]
|
61
60
|
is_avtive = true
|
62
|
-
components
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
components = repo["components"]
|
62
|
+
if !components.nil?
|
63
|
+
components.each do |component|
|
64
|
+
if component["tool"] == "CocoaPods"
|
65
|
+
is_avtive = !component["active"].empty?
|
66
|
+
break
|
67
|
+
end
|
66
68
|
end
|
67
69
|
end
|
68
70
|
if is_avtive
|
data/lib/GitUtils.rb
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require_relative './Utilities.rb'
|
5
|
+
|
6
|
+
module Pixab
|
7
|
+
|
8
|
+
class GitUtils
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
class << GitUtils
|
13
|
+
|
14
|
+
# 判断当前是否为git仓库
|
15
|
+
def is_git_repo()
|
16
|
+
is_git_repo = `git rev-parse --is-inside-work-tree`.chomp
|
17
|
+
return is_git_repo == "true"
|
18
|
+
end
|
19
|
+
|
20
|
+
# 检查当前是否有未提交的代码
|
21
|
+
def has_uncommit_code()
|
22
|
+
git_status = `git status -s`
|
23
|
+
return !git_status.empty?
|
24
|
+
end
|
25
|
+
|
26
|
+
# 检查指定分支是否关联了远程分支
|
27
|
+
def has_remote_branch(branch="HEAD")
|
28
|
+
branch_full_name = `git rev-parse --symbolic-full-name #{branch}`
|
29
|
+
remote_branch = `git for-each-ref --format='%(upstream:short)' #{branch_full_name}`.chomp
|
30
|
+
return !remote_branch.empty?
|
31
|
+
end
|
32
|
+
|
33
|
+
# 检查指定分支的本地代码和远程代码是否已经同步
|
34
|
+
def is_local_and_remote_branch_synced(branch)
|
35
|
+
local_log = `git log #{branch} -n 1 --pretty=format:"%H"`
|
36
|
+
remote_log = `git log remotes/origin/#{branch} -n 1 --pretty=format:"%H"`
|
37
|
+
return local_log == remote_log
|
38
|
+
end
|
39
|
+
|
40
|
+
# 判断branch1的代码是否已经同步到branch2
|
41
|
+
def is_branch_synced(branch1, branch2)
|
42
|
+
if branch1.nil? || branch2.nil?
|
43
|
+
return true
|
44
|
+
end
|
45
|
+
unsynced_commit = `git cherry #{branch2} #{branch1}`
|
46
|
+
return unsynced_commit.empty?
|
47
|
+
end
|
48
|
+
|
49
|
+
# 获取指定分支的最新提交
|
50
|
+
def latest_commit_id(branch)
|
51
|
+
return `git log #{branch} -n 1 --pretty=format:"%H"`
|
52
|
+
end
|
53
|
+
|
54
|
+
# 拉取远程仓库信息
|
55
|
+
# 未指定origin分支时,拉取所有远程仓库信息
|
56
|
+
# 只指定origin分支时,拉取远程仓库指定分支信息
|
57
|
+
# 同时指定local分支时,拉取远程仓库指定分支信息后,会将远程分支合并到local分支
|
58
|
+
def fetch_origin(origin = nil, local = nil)
|
59
|
+
commad = "git fetch origin"
|
60
|
+
if origin.nil?
|
61
|
+
return Utilities.execute_shell(commad)
|
62
|
+
end
|
63
|
+
commad += " #{origin}"
|
64
|
+
if local.nil?
|
65
|
+
return Utilities.execute_shell(commad)
|
66
|
+
end
|
67
|
+
commad += ":#{local}"
|
68
|
+
return Utilities.execute_shell(commad)
|
69
|
+
end
|
70
|
+
|
71
|
+
# 检查当前分支是否有冲突内容
|
72
|
+
def is_code_conflicts_in_current_branch
|
73
|
+
`git --no-pager diff --check`
|
74
|
+
return !Utilities.is_shell_execute_success
|
75
|
+
end
|
76
|
+
|
77
|
+
# 检查两个分支是否存在冲突
|
78
|
+
def is_code_conflicts(branch1, branch2)
|
79
|
+
conflicts = `git diff --name-status #{branch1} #{branch2} | grep "^U"`
|
80
|
+
return !conflicts.empty?
|
81
|
+
end
|
82
|
+
|
83
|
+
# 获取当前分支
|
84
|
+
def current_branch
|
85
|
+
branch = `git rev-parse --abbrev-ref HEAD`.chomp
|
86
|
+
return branch
|
87
|
+
end
|
88
|
+
|
89
|
+
# 推送代码
|
90
|
+
# branch: 指定推送分支
|
91
|
+
def push(branch = nil)
|
92
|
+
commad = "git push"
|
93
|
+
if !branch.nil?
|
94
|
+
commad += " origin #{branch}"
|
95
|
+
end
|
96
|
+
return Utilities.execute_shell(commad)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
class << GitUtils
|
102
|
+
|
103
|
+
def check_git_repo(path)
|
104
|
+
if !is_git_repo
|
105
|
+
puts "Error: #{path} is not a git repository".red
|
106
|
+
exit(1)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def check_has_uncommit_code(path)
|
111
|
+
if has_uncommit_code
|
112
|
+
puts "Please commit first, project path: #{path}".red
|
113
|
+
exit(1)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def check_local_and_remote_branch_synced(branch)
|
118
|
+
if !is_local_and_remote_branch_synced
|
119
|
+
puts "Please sync remote branch, use `git pull` or `git push`".red
|
120
|
+
exit(1)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def check_is_code_conflicts_in_current_branch
|
125
|
+
is_code_conflicts = is_code_conflicts_in_current_branch()
|
126
|
+
if !is_code_conflicts
|
127
|
+
return
|
128
|
+
end
|
129
|
+
project = File.basename(Dir.pwd)
|
130
|
+
conflict_hint = "Error: code conflict!\n"
|
131
|
+
conflict_hint += "step1: Resolve project:#{project}, branch:#{current_branch} code conflicts\n"
|
132
|
+
conflict_hint += "step2: Execute this script again"
|
133
|
+
puts conflict_hint.red
|
134
|
+
exit(1)
|
135
|
+
end
|
136
|
+
|
137
|
+
def check_is_code_conflicts(branch1, branch2)
|
138
|
+
if is_code_conflicts(branch1, branch2)
|
139
|
+
puts "Error: #{branch1} and #{branch2} has code conflicts".red
|
140
|
+
exit(1)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
data/lib/MergeRequest.rb
CHANGED
@@ -5,30 +5,38 @@ require "fileutils"
|
|
5
5
|
require 'colored2'
|
6
6
|
require_relative './Utilities.rb'
|
7
7
|
require_relative './RepoManager.rb'
|
8
|
+
require_relative './GitUtils.rb'
|
8
9
|
|
9
10
|
module Pixab
|
10
11
|
|
11
12
|
class MergeRequest
|
12
13
|
|
13
|
-
attr_accessor :repo_type, :default_commit_msg
|
14
|
+
attr_accessor :repo_type, :default_commit_msg, :need_merge_origin, :need_creat_mr
|
14
15
|
attr_reader :repo_manager, :repos, :command_options
|
15
16
|
|
16
17
|
def initialize(repo_manager = RepoManager.new, commands = nil)
|
17
18
|
@repo_manager = repo_manager
|
18
19
|
@repo_type = 2
|
19
20
|
@default_commit_msg = "[Feature]"
|
21
|
+
@need_merge_origin = true
|
22
|
+
@need_creat_mr = true
|
23
|
+
|
20
24
|
if commands.nil?
|
21
25
|
return
|
22
26
|
end
|
23
27
|
commands.each_index do |index|
|
24
28
|
command = commands[index]
|
25
29
|
case command
|
26
|
-
when
|
30
|
+
when "-a"
|
27
31
|
@repo_type = 0
|
28
32
|
when "-m"
|
29
33
|
@repo_type = 1
|
30
34
|
when "--commit-m"
|
31
35
|
@default_commit_msg = commands[index + 1]
|
36
|
+
when "--no-merge-origin"
|
37
|
+
@need_merge_origin = false
|
38
|
+
when "--no-mr"
|
39
|
+
@need_creat_mr = false
|
32
40
|
else
|
33
41
|
end
|
34
42
|
end
|
@@ -85,8 +93,7 @@ module Pixab
|
|
85
93
|
|
86
94
|
# 合并代码
|
87
95
|
def merge()
|
88
|
-
|
89
|
-
if is_need_merge
|
96
|
+
if need_merge_origin
|
90
97
|
repos.each do |repo|
|
91
98
|
system "mbox merge --repo #{repo["name"]}"
|
92
99
|
end
|
@@ -95,30 +102,43 @@ module Pixab
|
|
95
102
|
|
96
103
|
# 推送MR
|
97
104
|
def push_and_create_mr()
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
105
|
+
if !need_creat_mr
|
106
|
+
return
|
107
|
+
end
|
108
|
+
|
109
|
+
feature_branch = repo_manager.feature_branch
|
110
|
+
|
111
|
+
reviewers = Utilities.display_dialog("正在创建Merge Request\n请输入审核人员ID:\n子琰(979) 丕臻(1385) 再润(1569) 思保(1922)", "979 1385").split()
|
112
|
+
mr_request_assign = ""
|
113
|
+
reviewers.each do |reviewer|
|
103
114
|
mr_request_assign += " -o merge_request.assign=#{reviewer}"
|
115
|
+
end
|
116
|
+
mr_source_branch = "-o merge_request.remove_source_branch"
|
117
|
+
|
118
|
+
repos.each do |repo|
|
119
|
+
repo_name = repo["name"]
|
120
|
+
puts "\n[#{repo_name}]"
|
121
|
+
FileUtils.cd("#{repo_manager.root_path}/#{repo_name}")
|
122
|
+
current_branch = GitUtils.current_branch
|
123
|
+
if current_branch != feature_branch
|
124
|
+
puts "\n[!] The repo #{repo_name} is not in feature branch `#{feature_branch}`. Skip it.".yellow
|
125
|
+
next
|
104
126
|
end
|
105
|
-
|
106
|
-
mr_source_branch = "-o merge_request.remove_source_branch"
|
107
|
-
repos.each do |repo|
|
108
|
-
repo_name = repo["name"]
|
109
|
-
puts repo_name
|
110
|
-
repo_target_branch = repo["target_branch"]
|
111
|
-
repo_last_branch = repo["last_branch"]
|
112
127
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
128
|
+
repo_target_branch = repo["target_branch"]
|
129
|
+
|
130
|
+
log_content = `git log origin/#{repo_target_branch}..#{current_branch} --pretty=format:"%H"`
|
131
|
+
if log_content.empty?
|
132
|
+
puts "\n[!] branch `#{current_branch}` is same as branch `origin/#{repo_target_branch}`. Skip it.".yellow
|
133
|
+
next
|
134
|
+
end
|
135
|
+
mr_target = "-o merge_request.target=#{repo_target_branch}"
|
136
|
+
# mr_title = "-o merge_request.title=#{repo_last_branch}"
|
137
|
+
commad = "git push"
|
138
|
+
if repo["last_branch"].nil?
|
139
|
+
commad += " --set-upstream origin #{current_branch}"
|
121
140
|
end
|
141
|
+
`#{commad} -o merge_request.create #{mr_target} #{mr_source_branch} #{mr_request_assign}`
|
122
142
|
end
|
123
143
|
end
|
124
144
|
|
data/lib/Package.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
require "fileutils"
|
5
|
+
require_relative './GitUtils.rb'
|
6
|
+
require_relative './RepoManager.rb'
|
7
|
+
|
8
|
+
module Pixab
|
9
|
+
|
10
|
+
class Package
|
11
|
+
|
12
|
+
attr_reader :repo_manager
|
13
|
+
|
14
|
+
def initialize(repo_manager = RepoManager.new)
|
15
|
+
@repo_manager = repo_manager
|
16
|
+
end
|
17
|
+
|
18
|
+
def run
|
19
|
+
main_repo = repo_manager.main_repo
|
20
|
+
package_branch = 'develop'
|
21
|
+
origin_package_branch = "origin/#{package_branch}"
|
22
|
+
target_branch = main_repo["target_branch"]
|
23
|
+
origin_target_branch = "origin/#{target_branch}"
|
24
|
+
main_repo_path = "#{repo_manager.root_path}/#{main_repo['name']}"
|
25
|
+
FileUtils.cd(main_repo_path)
|
26
|
+
GitUtils.check_git_repo(main_repo_path)
|
27
|
+
puts "\n》》》》》正在更新远程仓库信息》》》》》\n".green
|
28
|
+
GitUtils.fetch_origin
|
29
|
+
if !GitUtils.is_branch_synced(origin_package_branch, package_branch)
|
30
|
+
puts "\n》》》》》正在将#{origin_package_branch}代码拉取到#{package_branch}》》》》》\n".green
|
31
|
+
GitUtils.check_is_code_conflicts(origin_package_branch, package_branch)
|
32
|
+
GitUtils.fetch_origin(package_branch, package_branch)
|
33
|
+
end
|
34
|
+
if !GitUtils.is_branch_synced(origin_target_branch, package_branch)
|
35
|
+
puts "\n》》》》》正在将#{origin_target_branch}代码合并到#{package_branch}》》》》》\n".green
|
36
|
+
GitUtils.check_is_code_conflicts(origin_target_branch, package_branch)
|
37
|
+
GitUtils.fetch_origin(target_branch, package_branch)
|
38
|
+
end
|
39
|
+
if GitUtils.is_branch_synced(package_branch, origin_package_branch)
|
40
|
+
puts "Error: #{package_branch} branch has no code update and cannot be packaged.".red
|
41
|
+
exit(1)
|
42
|
+
end
|
43
|
+
GitUtils.push(package_branch)
|
44
|
+
puts "\n》》》》》已完成#{package_branch}代码推送,正在打包》》》》》".green
|
45
|
+
puts "打包平台地址:http://ios.meitu-int.com/ipa/airbrush/queue\n".green
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/lib/RepoManager.rb
CHANGED
@@ -8,7 +8,7 @@ module Pixab
|
|
8
8
|
|
9
9
|
class RepoManager
|
10
10
|
|
11
|
-
attr_reader :root_path, :
|
11
|
+
attr_reader :root_path, :feature
|
12
12
|
|
13
13
|
def initialize()
|
14
14
|
read_repo_infos
|
@@ -27,10 +27,13 @@ module Pixab
|
|
27
27
|
puts "Error: You are currently in Free Mode".red
|
28
28
|
exit(1)
|
29
29
|
end
|
30
|
-
feature = obj["features"][current_feature_name.downcase]
|
31
|
-
@repos = feature["repos"]
|
30
|
+
@feature = obj["features"][current_feature_name.downcase]
|
32
31
|
end
|
33
32
|
|
33
|
+
def repos
|
34
|
+
feature["repos"]
|
35
|
+
end
|
36
|
+
|
34
37
|
def main_repo
|
35
38
|
repos.first
|
36
39
|
end
|
@@ -43,6 +46,14 @@ module Pixab
|
|
43
46
|
end
|
44
47
|
return []
|
45
48
|
end
|
49
|
+
|
50
|
+
def feature_name
|
51
|
+
feature["name"]
|
52
|
+
end
|
53
|
+
|
54
|
+
def feature_branch
|
55
|
+
feature["branch_prefix"] + feature_name
|
56
|
+
end
|
46
57
|
|
47
58
|
end
|
48
59
|
|
data/lib/Utilities.rb
CHANGED
@@ -11,8 +11,14 @@ module Pixab
|
|
11
11
|
|
12
12
|
class << Utilities
|
13
13
|
|
14
|
-
|
14
|
+
|
15
|
+
def is_shell_execute_success(success = nil)
|
15
16
|
is_success = success.nil? ? $?.to_i == 0 : success
|
17
|
+
return is_success
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_shell_result(error_msg = nil, success = nil)
|
21
|
+
is_success = is_shell_execute_success(success)
|
16
22
|
if is_success
|
17
23
|
return
|
18
24
|
end
|
@@ -21,6 +27,14 @@ module Pixab
|
|
21
27
|
end
|
22
28
|
exit(1)
|
23
29
|
end
|
30
|
+
|
31
|
+
def execute_shell(commad)
|
32
|
+
if commad.nil?
|
33
|
+
return false
|
34
|
+
end
|
35
|
+
`#{commad}`
|
36
|
+
return is_shell_execute_success
|
37
|
+
end
|
24
38
|
|
25
39
|
def display_default_dialog(default_text)
|
26
40
|
input_msg = `osascript -e 'display dialog "#{default_text}"'`.chomp
|
data/lib/pixab/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixab
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 廖再润
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colored2
|
@@ -40,9 +40,11 @@ files:
|
|
40
40
|
- Rakefile
|
41
41
|
- exe/pixab
|
42
42
|
- lib/ComponentSynchronizer.rb
|
43
|
+
- lib/GitUtils.rb
|
43
44
|
- lib/Localization.rb
|
44
45
|
- lib/LocalizationPlatform.rb
|
45
46
|
- lib/MergeRequest.rb
|
47
|
+
- lib/Package.rb
|
46
48
|
- lib/RepoManager.rb
|
47
49
|
- lib/Utilities.rb
|
48
50
|
- lib/pixab.rb
|