pixab 1.1.3 → 1.2.0
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/GitUtils.rb +146 -0
- data/lib/Package.rb +50 -0
- 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: ad65d5472da045a81067a41d705fea247f8458977f72aa7ba61224f3c2d155da
|
4
|
+
data.tar.gz: 7c283ff51d7166f658e72ed9afb7de9693a79889b9f6c0b4e5015c30958a2824
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3c7228c287049cf5f006559481862a67b09abe1d743628b57d4909c3c188a93f136c07c4e4fbd1f8893d5ccd3b98b4935f89d3569659d2244e6370d83b8aa391
|
7
|
+
data.tar.gz: 7b66f1118681b026bcb0e525279e00e16bf16295efd0132ba80066bb9c5de81cf799ec1c999ab7eff4864e7ce97bbf5e2c9224768b71a85b86d341506f8e375d
|
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
|
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`
|
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/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/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.
|
4
|
+
version: 1.2.0
|
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-11 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
|