pixab 2.0.0 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e343b6bb118ca7dea7ba7a5f1a09f925c662b60104c3cc1cec9f0903e257857
4
- data.tar.gz: d05148fe7149a47ae7c06eeec57de5276c2f2ded8148a2bb675a72cc4d216eda
3
+ metadata.gz: 40bdedbf96ae1aad98cea6889c0cd32dafc9d9d6634ed181ea5d3aad9fc50c53
4
+ data.tar.gz: f097ad80dcff665eb3f0e6a77f7717fbed41bc7e7503e6819a09e0591e5b43f2
5
5
  SHA512:
6
- metadata.gz: bd5d261253f3b36eb5b5f7b4f7123ddfd922e36b8dfc5bab1afceebda3ea0ceec81a9f86a566f3ba7def345263b147b9dd9a0676d7fcfdbd9b38337a370f827c
7
- data.tar.gz: c71932134caaa9fc477f1a8e4186ddd6758905b27970af104b3aef0e4f44d8e704c6e3507a896f6dd87d7e571f5db8563048b39a4abaec05a8320ec63cd0746a
6
+ metadata.gz: 74c4e32db81e84edf7d54c6a7bf719290bf458978440435e231113ba1e08eefb6dc659934742f295a1660733887c4adbb24f00f408adc303c22e050a57264d4f
7
+ data.tar.gz: fec66d4eac0ed930fa2052a3d02d77e8a482b1da15edf8f068e6fdbb5c98f81bf25649b0bdf0d707115fa54b15b69639dd192a3ce3ec7313040a622f59ccf705
data/exe/pixab CHANGED
@@ -12,6 +12,8 @@ require_relative '../lib/LocalizationSmartcatImport.rb'
12
12
  require_relative '../lib/LocalizationSmartcatMerge.rb'
13
13
  require_relative '../lib/mbox/Mbox.rb'
14
14
  require_relative '../lib/gitlab/GitlabMRManager.rb'
15
+ require_relative '../lib/feature/Feature.rb'
16
+ require_relative '../lib/git/Git.rb'
15
17
 
16
18
  case ARGV[0]
17
19
  when '--version'
@@ -58,6 +60,10 @@ when 'mbox'
58
60
  Pixab::Mbox.new.run(ARGV[1..-1])
59
61
  when 'mr'
60
62
  Pixab::GitlabMRManager.new.run(ARGV[1..-1])
63
+ when 'feature'
64
+ Pixab::Feature.new.run(ARGV[1..-1])
65
+ when 'git'
66
+ Pixab::Git.new.run(ARGV[0..-1])
61
67
  else
62
68
  puts "Invalid command".red
63
69
  end
data/lib/GitUtils.rb CHANGED
@@ -134,6 +134,19 @@ module Pixab
134
134
  status.success? && !exisit_remote_branch.strip.empty?
135
135
  end
136
136
 
137
+ # 获取远程分支名的方法
138
+ def get_remote_branch_name(branch, remote = 'origin')
139
+ remote_branches = `git branch -r`.split("\n").map(&:strip)
140
+ remote_branch = remote_branches.find { |b| b == "#{remote}/#{branch}" }
141
+ return remote_branch
142
+ end
143
+
144
+ # 查找包含 Git 仓库的目录
145
+ def find_git_repos(root_dir)
146
+ # 使用 Dir.glob 匹配所有包含 .git 子目录的目录
147
+ Dir.glob("#{root_dir}/**/.git").map { |git_dir| File.dirname(File.expand_path(git_dir)) }
148
+ end
149
+
137
150
  end
138
151
 
139
152
  class << GitUtils
@@ -0,0 +1,49 @@
1
+ require_relative './FeatureStart.rb'
2
+
3
+ module Pixab
4
+
5
+ class Feature
6
+
7
+ def run(commands = nil)
8
+ git_repos = GitUtils.find_git_repos(Dir.pwd)
9
+ if git_repos.empty?
10
+ puts "No Git repositories found.".red
11
+ return
12
+ end
13
+
14
+ isNeedPush = true
15
+ commands.each_index do |index|
16
+ command = commands[index]
17
+ case command
18
+ when '--no-push'
19
+ isNeedPush = false
20
+ end
21
+ end
22
+
23
+ commands.each_index do |index|
24
+ command = commands[index]
25
+ case command
26
+ when 'start'
27
+ feature_name = commands[index + 1]
28
+ if feature_name.nil?
29
+ puts "请输入要创建的分支名称".red
30
+ return
31
+ end
32
+ feature_name = ensure_feature_prefix(feature_name)
33
+
34
+ feature_start = FeatureStart.new(isNeedPush)
35
+ git_repos.each do |repo|
36
+ feature_start.run(repo, feature_name)
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ def ensure_feature_prefix(feature_name)
44
+ feature_name.start_with?('feature') ? feature_name : "feature/#{feature_name}"
45
+ end
46
+
47
+ end
48
+
49
+ end
@@ -0,0 +1,50 @@
1
+ require 'colored2'
2
+ require_relative '../GitUtils.rb'
3
+
4
+ module Pixab
5
+
6
+ class FeatureStart
7
+
8
+ def initialize(isNeedPush)
9
+ @isNeedPush = isNeedPush
10
+ end
11
+
12
+ def run(path, feature_name)
13
+ unless Dir.exist?(path)
14
+ puts "当前目录不存在: #{path}".red
15
+ return
16
+ end
17
+
18
+ puts "\n#{File.basename(path)} 开始创建分支: #{feature_name}\n".green
19
+
20
+ Dir.chdir(path) do
21
+ create_feature_branch(feature_name)
22
+ end
23
+ end
24
+
25
+ def create_feature_branch(feature_name)
26
+ if !GitUtils.is_git_repo
27
+ puts "当前目录不是 Git 仓库!, path: #{Dir.pwd}".red
28
+ return
29
+ end
30
+
31
+ remote_develop_branch = GitUtils.get_remote_branch_name('develop')
32
+ if remote_develop_branch.nil?
33
+ puts "远程仓库不存在 develop 分支!".red
34
+ return
35
+ end
36
+
37
+ GitUtils.fetch_origin('develop')
38
+
39
+ `git checkout -b #{feature_name} #{remote_develop_branch}`
40
+
41
+ # 是否需要推送到远程仓库
42
+ if @isNeedPush
43
+ `git push -u origin #{feature_name}`
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
data/lib/git/Git.rb ADDED
@@ -0,0 +1,26 @@
1
+ require_relative '../GitUtils.rb'
2
+
3
+ module Pixab
4
+
5
+ class Git
6
+
7
+ def run(commands)
8
+ git_repos = GitUtils.find_git_repos(Dir.pwd)
9
+ if git_repos.empty?
10
+ puts "No Git repositories found.".red
11
+ return
12
+ end
13
+
14
+ command = commands.join(' ')
15
+ git_repos.each do |repo|
16
+ puts "\n[#{File.basename(repo)}]".green
17
+ Dir.chdir(repo) do
18
+ system command
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -16,9 +16,17 @@ module Pixab
16
16
  `git fetch origin`
17
17
 
18
18
  @branch = GitUtils.current_branch
19
+ if @branch.nil?
20
+ puts "无法获取当前分支".red
21
+ end
22
+
19
23
  @target_branch = get_target_branch(@branch)
20
- @remote_branch = GitUtils.remote_branch(@branch)
21
- @remote_target_branch = GitUtils.remote_branch(@target_branch)
24
+ if @target_branch.nil?
25
+ puts "无法获取目标分支,当前分支:#{@branch}".red
26
+ end
27
+
28
+ @remote_branch = "origin/#{@branch}"
29
+ @remote_target_branch = "origin/#{@target_branch}"
22
30
  end
23
31
 
24
32
  def get_target_branch(branch)
@@ -39,13 +47,22 @@ module Pixab
39
47
  end
40
48
 
41
49
  def get_version(feature_name)
50
+ # 用 '_' 分割字符串
42
51
  parts = feature_name.split('_')
43
- parts.map do |part|
44
- is_numeric = part.match?(/^\d+$/) # 检查是否为纯数字
45
- if is_numeric
52
+
53
+ # 遍历分割的部分
54
+ parts.each do |part|
55
+ # 判断是否为纯数字
56
+ if part.match?(/^\d+$/)
57
+ return part
58
+ # 判断是否为类似 7.5.0 的格式
59
+ elsif part.match?(/^\d+(\.\d+)*$/)
46
60
  return part
47
61
  end
48
62
  end
63
+
64
+ # 如果没有满足条件的字符串,返回 nil
65
+ nil
49
66
  end
50
67
 
51
68
  # 判断远程分支是否代码是否同步到远程目标分支
data/lib/pixab/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pixab
4
- VERSION = "2.0.0"
4
+ VERSION = "2.2.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: 2.0.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - 廖再润
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-12-26 00:00:00.000000000 Z
11
+ date: 2024-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -94,6 +94,9 @@ files:
94
94
  - lib/Platform.rb
95
95
  - lib/RepoManager.rb
96
96
  - lib/Utilities.rb
97
+ - lib/feature/Feature.rb
98
+ - lib/feature/FeatureStart.rb
99
+ - lib/git/Git.rb
97
100
  - lib/gitlab/GitRepoInfo.rb
98
101
  - lib/gitlab/GitlabInfo.rb
99
102
  - lib/gitlab/GitlabMR.rb