pixab 2.0.0 → 2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6e343b6bb118ca7dea7ba7a5f1a09f925c662b60104c3cc1cec9f0903e257857
4
- data.tar.gz: d05148fe7149a47ae7c06eeec57de5276c2f2ded8148a2bb675a72cc4d216eda
3
+ metadata.gz: 7c2253162bf9e37eaaaa541ca25d978ee6ced4fdeda468101b90fc0758ecc805
4
+ data.tar.gz: 42237eb540beb23065e0ccc03f267cdaa03f82f27122b1f8e51c6d7f1ff247e2
5
5
  SHA512:
6
- metadata.gz: bd5d261253f3b36eb5b5f7b4f7123ddfd922e36b8dfc5bab1afceebda3ea0ceec81a9f86a566f3ba7def345263b147b9dd9a0676d7fcfdbd9b38337a370f827c
7
- data.tar.gz: c71932134caaa9fc477f1a8e4186ddd6758905b27970af104b3aef0e4f44d8e704c6e3507a896f6dd87d7e571f5db8563048b39a4abaec05a8320ec63cd0746a
6
+ metadata.gz: d1a0f1839ea57b8e810a4ef2c019566b1b2b20d7c9923f160edf1a055f04af2d65d97e4c72d7a71c0482a688d2fb31b029a1cba0501b09164f7a98e3db5957d9
7
+ data.tar.gz: 76c95d7addbd2ce3425e3b5c975d775e4e87ea645e53e82d40bd7d08266f17abfe7fb3bc2488e74166d971a88381f9bc6eb24ac636f6b3def7323d9750b9b939
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
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.0"
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.0
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