pixab 1.8.1 → 1.9.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f7a1aa87941f9dd40ce7081271a52f5766433522e97d2fef66bbd65a5fdf0c6
4
- data.tar.gz: b81b6f80cbce8298e1c94186a5a527dba99873f950084b79784e1aac765a88ae
3
+ metadata.gz: f50adcb68e83e75958401c6f4702e41953c420ea796c305f2bad239f8b627ff1
4
+ data.tar.gz: d77dca3ff3842a8bc9952d222906066fd018ab51bc0ec8eaf9dfe6f2f576c6ac
5
5
  SHA512:
6
- metadata.gz: e75b6835902ada48dbeaec2e064ba509726d144cf7004d18841d6f268c08f6ad4e80194813f7bf7401b650fe10d1406347234877604a85791ae6b4c7cfaec556
7
- data.tar.gz: f3e495b4c839a8d87e3d6210a26172368d1eb5dc951083364a97cd2e970e5e55eeb8c72a3dad832493edaabf4603b94abae3f380012b7e658517979867683ef3
6
+ metadata.gz: cd5b9cac308d3ffaf426c09906f43e83052acc48911bfed30aa8383de440ee62102a70c59c98562acbafbd87e70561330b608cffa611776efd394ace9a057930
7
+ data.tar.gz: 71b6e1105640c2c94f0542fc63ed4f0f21ce9e0e6015b975fa497a6aae7198e1963dd2b581dc9f2e963ca8b7e82b31ab283df7318783dddddbf30854f5fe5a23
data/exe/pixab CHANGED
@@ -10,6 +10,7 @@ require_relative '../lib/Package.rb'
10
10
  require_relative '../lib/LocalizationSmartcat.rb'
11
11
  require_relative '../lib/LocalizationSmartcatImport.rb'
12
12
  require_relative '../lib/LocalizationSmartcatMerge.rb'
13
+ require_relative '../lib/mbox/Mbox.rb'
13
14
 
14
15
  case ARGV[0]
15
16
  when '--version'
@@ -52,6 +53,8 @@ when 'localize'
52
53
  else
53
54
  Pixab::LocalizationSmartcat.new.run(ARGV[1..-1])
54
55
  end
56
+ when 'mbox'
57
+ Pixab::Mbox.new.run(ARGV[1..-1])
55
58
  else
56
59
  puts "Invalid command".red
57
60
  end
@@ -4,14 +4,14 @@
4
4
  require "fileutils"
5
5
  require 'colored2'
6
6
  require 'open3'
7
- require_relative './Utilities.rb'
7
+ require_relative './GitUtils.rb'
8
8
  require_relative './RepoManager.rb'
9
9
 
10
10
  module Pixab
11
11
 
12
12
  class ComponentSynchronizer
13
13
 
14
- attr_accessor :is_need_build, :is_need_remote_repo, :is_need_pod_install
14
+ attr_accessor :is_need_build, :is_need_remote_repo, :is_need_pod_install, :is_use__target_branch
15
15
  attr_reader :repo_manager, :repos, :main_repo_name, :updated_repo_names
16
16
 
17
17
  def initialize(repo_manager = RepoManager.new, commands = nil)
@@ -19,6 +19,8 @@ module Pixab
19
19
  @is_need_build = false
20
20
  @is_need_remote_repo = false
21
21
  @is_need_pod_install = true
22
+ @is_use__target_branch = true
23
+
22
24
  if commands.nil?
23
25
  return
24
26
  end
@@ -31,9 +33,12 @@ module Pixab
31
33
  @is_need_remote_repo = true
32
34
  when "--no-pod-install"
33
35
  @is_need_pod_install = false
36
+ when "--current-branch"
37
+ @is_use__target_branch = false
34
38
  else
35
39
  end
36
40
  end
41
+
37
42
  end
38
43
 
39
44
  def run
@@ -121,9 +126,14 @@ module Pixab
121
126
  repo_commite_id = {}
122
127
  repos.each do |repo|
123
128
  repo_name = repo["name"]
124
- repo_target_branch = repo["target_branch"]
129
+
125
130
  FileUtils.cd("#{repo_manager.root_path}/#{repo_name}")
126
- `git fetch origin #{repo_target_branch}`
131
+ repo_target_branch = @is_use__target_branch ? repo_target_branch = repo["target_branch"] : GitUtils.current_branch
132
+ next unless GitUtils.check_remote_branch_exists_fast("origin/#{repo_target_branch}")
133
+
134
+ stdout, status = Open3.capture2("git fetch origin #{repo_target_branch}")
135
+ next unless status.success?
136
+
127
137
  commit_id = `git log origin/#{repo_target_branch} -n 1 --pretty=format:"%H"`
128
138
  if !commit_id.nil?
129
139
  repo_commite_id[repo_name] = commit_id
@@ -199,5 +209,4 @@ module Pixab
199
209
 
200
210
  end
201
211
 
202
- end
203
-
212
+ end
data/lib/GitUtils.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
+ require 'open3'
4
5
  require_relative './Utilities.rb'
5
6
 
6
7
  module Pixab
@@ -96,6 +97,39 @@ module Pixab
96
97
  return Utilities.execute_shell(commad)
97
98
  end
98
99
 
100
+ # 获取当前分支的远程分支
101
+ def current_remote_branch
102
+ local_branch = current_branch
103
+ return nil if local_branch.nil?
104
+
105
+ remote_branch, status = Open3.capture2("git for-each-ref --format='%(upstream:short)' refs/heads/#{local_branch}")
106
+ remote_branch.strip!
107
+ return nil if !status.success? || remote_branch.empty?
108
+
109
+ return nil unless check_remote_branch_exists_fast(remote_branch)
110
+ return remote_branch
111
+ rescue => e
112
+ puts "Error: get current remote branch failed, #{e.message}".red
113
+ return nil
114
+ end
115
+
116
+ # 在远程仓库检查远程分支是否存在
117
+ # remote_branch: 远程分支名称,不需要remote前缀,使用origin作为remote
118
+ def check_remote_branch_exists(remote_branch)
119
+ exisit_remote_branch, status= Open3.capture2("git ls-remote --heads origin #{remote_branch}")
120
+ return status.success? && !exisit_remote_branch.strip.empty?
121
+ rescue => e
122
+ puts "Error: check remote branch exists failed, #{e.message}".red
123
+ return false
124
+ end
125
+
126
+ # 在本地仓库检查远程分支是否存在
127
+ # remote_branch: 远程分支名称
128
+ def check_remote_branch_exists_fast(remote_branch)
129
+ exisit_remote_branch, status = Open3.capture2("git branch -r --list #{remote_branch}")
130
+ status.success? && !exisit_remote_branch.strip.empty?
131
+ end
132
+
99
133
  end
100
134
 
101
135
  class << GitUtils
data/lib/RepoManager.rb CHANGED
@@ -37,6 +37,10 @@ module Pixab
37
37
  def main_repo
38
38
  repos.first
39
39
  end
40
+
41
+ def main_repo_name
42
+ main_repo["name"]
43
+ end
40
44
 
41
45
  def sub_repos
42
46
  if repos.length > 1
@@ -47,6 +51,12 @@ module Pixab
47
51
  return []
48
52
  end
49
53
 
54
+ def sub_repo_names
55
+ sub_repos.map do |sub_repo|
56
+ sub_repo["name"]
57
+ end
58
+ end
59
+
50
60
  def feature_name
51
61
  feature["name"]
52
62
  end
@@ -0,0 +1,11 @@
1
+ module Pixab
2
+
3
+ class AirBrushProjectInfo
4
+
5
+ COMPONENT_FILE_PATH = 'AirBrushPodfiles/pix_ab_component.rb'
6
+
7
+ DEFAULT_BRANCH = 'develop'
8
+
9
+ end
10
+
11
+ end
data/lib/mbox/Mbox.rb ADDED
@@ -0,0 +1,33 @@
1
+ require_relative './MboxAdd.rb'
2
+ require_relative './MboxRemove.rb'
3
+
4
+ module Pixab
5
+
6
+ class Mbox
7
+
8
+ attr_reader :repo_manager
9
+
10
+ def initialize
11
+ @repo_manager = RepoManager.new
12
+ end
13
+
14
+ def run(commands)
15
+ if commands.empty?
16
+ puts "请输入命令".red
17
+ return
18
+ end
19
+
20
+ command = commands[0]
21
+ case command
22
+ when "add"
23
+ MboxAdd.new(repo_manager).run(commands[1..-1])
24
+ when "remove"
25
+ MboxRemove.new(repo_manager).run(commands[1..-1])
26
+ else
27
+ `mbox #{commands.join(" ")}`
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,93 @@
1
+ require 'open3'
2
+ require_relative './AirBrushProjectInfo.rb'
3
+ require_relative '../Utilities.rb'
4
+ require_relative '../RepoManager.rb'
5
+
6
+ module Pixab
7
+
8
+ class MboxAdd
9
+
10
+ attr_reader :repo_manager, :default_branch
11
+
12
+ def initialize(repo_manager)
13
+ @repo_manager = repo_manager
14
+ @default_branch = AirBrushProjectInfo::DEFAULT_BRANCH
15
+ end
16
+
17
+ def run(commands)
18
+ commands.each_index do |index|
19
+ command = commands[index]
20
+ case command
21
+ when "--default-branch"
22
+ @default_branch = commands[index + 1]
23
+ end
24
+ end
25
+
26
+ if commands.empty?
27
+ repo_names = get_all_sub_repo_names
28
+ if !repo_names.empty?
29
+ selected_item_names = Utilities.display_choose_list(repo_names, nil, "仓库", "请选择需要添加的仓库:", nil, nil, true)
30
+ selected_item_names.each do |repo_name|
31
+ add_repo([repo_name.strip, @default_branch])
32
+ end
33
+ end
34
+ elsif commands[0] == "--all"
35
+ repo_names = get_all_sub_repo_names
36
+ repo_names.each do |repo_name|
37
+ add_repo([repo_name, @default_branch])
38
+ end
39
+ else
40
+ add_repo(commands)
41
+ end
42
+
43
+ system("mbox status")
44
+
45
+ end
46
+
47
+ def add_repo(commands)
48
+ return if commands.empty?
49
+
50
+ execute_commad = "mbox add"
51
+ commands.each do |command|
52
+ execute_commad += " #{command}"
53
+ end
54
+
55
+ stdout, status = Open3.capture2(execute_commad)
56
+ if status.success?
57
+ pull_lfs_files_if_needed(commands[0])
58
+ end
59
+ end
60
+
61
+ # 获取所有的子仓名
62
+ def get_all_sub_repo_names
63
+ podfile_path = "#{@repo_manager.root_path}/#{@repo_manager.main_repo_name}/#{AirBrushProjectInfo::COMPONENT_FILE_PATH}"
64
+ podfile_content = File.read(podfile_path)
65
+ matches = podfile_content.match(/def pix_ab_component(.*?)end/m)
66
+ return [] if matches.nil?
67
+ podfile_content = matches[0]
68
+ reg = /'([^']+).+:commit => '(.+)'/
69
+ matches = podfile_content.scan(reg)
70
+ repo_names = matches.map do |match|
71
+ match[0]
72
+ end
73
+ repo_names - @repo_manager.sub_repo_names
74
+ end
75
+
76
+ # 如果使用了lfs,则拉取lfs文件
77
+ def pull_lfs_files_if_needed(repo_name)
78
+ # 使用此方法切换路径时可以避免在控制台打印路径,并在执行完成后会切换回原路径
79
+ FileUtils.cd("#{@repo_manager.root_path}/#{repo_name}") do
80
+ break unless File.exist?(".gitattributes")
81
+
82
+ file_content = File.read(".gitattributes")
83
+ break unless file_content.include?("filter=lfs")
84
+
85
+ Open3.capture3("mbox git hooks --disable")
86
+ `git lfs pull`
87
+ Open3.capture3("mbox git hooks --enable")
88
+ end
89
+ end
90
+
91
+ end
92
+
93
+ end
@@ -0,0 +1,46 @@
1
+ module Pixab
2
+
3
+ class MboxRemove
4
+
5
+ attr_reader :repo_manager
6
+
7
+ def initialize(repo_manager)
8
+ @repo_manager = repo_manager
9
+ end
10
+
11
+ def run(commands)
12
+ if commands.empty?
13
+ repo_names = @repo_manager.sub_repo_names
14
+ if !repo_names.empty?
15
+ selected_item_names = Utilities.display_choose_list(repo_names, nil, "仓库", "请选择需要移除的仓库:", nil, nil, true)
16
+ selected_item_names.each do |repo_name|
17
+ remove_repo([repo_name.strip])
18
+ end
19
+ end
20
+ elsif commands[0] == "--all"
21
+ repo_names = @repo_manager.sub_repo_names
22
+ repo_names.each do |repo_name|
23
+ remove_repo([repo_name])
24
+ end
25
+ else
26
+ remove_repo(commands)
27
+ end
28
+
29
+ system("mbox status")
30
+
31
+ end
32
+
33
+ def remove_repo(commands)
34
+ return if commands.empty?
35
+
36
+ execute_commad = "mbox remove"
37
+ commands.each do |command|
38
+ execute_commad += " #{command}"
39
+ end
40
+
41
+ `#{execute_commad}`
42
+ end
43
+
44
+ end
45
+
46
+ end
data/lib/pixab/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pixab
4
- VERSION = "1.8.1"
4
+ VERSION = "1.9.1"
5
5
  end
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.8.1
4
+ version: 1.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - 廖再润
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-11 00:00:00.000000000 Z
11
+ date: 2024-08-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -93,6 +93,10 @@ files:
93
93
  - lib/Package.rb
94
94
  - lib/RepoManager.rb
95
95
  - lib/Utilities.rb
96
+ - lib/mbox/AirBrushProjectInfo.rb
97
+ - lib/mbox/Mbox.rb
98
+ - lib/mbox/MboxAdd.rb
99
+ - lib/mbox/MboxRemove.rb
96
100
  - lib/pixab.rb
97
101
  - lib/pixab/version.rb
98
102
  - pixab.gemspec