Class: Pindo::TaskSystem::GitTask

Inherits:
PindoTask
  • Object
show all
Defined in:
lib/pindo/module/task/model/git_task.rb

Overview

Git 任务基类所有 Git 相关任务的父类,提供通用的 Git 操作和配置

Direct Known Subclasses

GitCommitTask, GitTagTask

Instance Attribute Summary collapse

Attributes inherited from PindoTask

#callbacks_setup, #context, #created_at, #dependencies, #error, #finished_at, #id, #max_retry_count, #metadata, #name, #priority, #result, #retry_count, #retry_delay, #retry_mode, #skip_count, #started_at, #status, #task_key, #task_manager, #type

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PindoTask

#before_retry, #cancel, #cancelled?, #check_cancelled!, #data_param, #do_task, #execution_time, #finished?, #get_all_data_params, #get_all_data_params_by_key, #get_all_dependencies_results, #get_data_param, #get_data_param_by_key, #get_dependency_result, #get_dependency_task, #on, #primary_data_param, #release_resource, #release_resources, #reset_for_retry, #retryable?, #running?, #should_retry?, task_key, #with_resource, #with_resources

Constructor Details

#initialize(name, options = {}) ⇒ GitTask

Returns a new instance of GitTask.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pindo/module/task/model/git_task.rb', line 14

def initialize(name, options = {})
  @project_path = options[:project_path] ? File.expand_path(options[:project_path]) : nil

  # Git 版本管理相关属性(子类可以覆盖默认值)
  @release_branch = options[:release_branch] || 'master'
  @ver_inc = options[:ver_inc] || Pindo::VersionIncreaseType::MINI
  @tag_type = options[:tag_type] || Pindo::CreateTagType::NEW
  @tag_pre = options[:tag_pre] || 'v'

  # 版本信息(由子类在 do_work 中赋值)
  @build_version = nil
  @build_number = nil
  @commit_hash = nil

  # 通过 project_path 获取 git_root_path
  @git_root_path = @project_path ? Pindo::GitHandler.git_root_directory(local_repo_dir: @project_path) : nil

  super(name, options)
end

Instance Attribute Details

#build_numberObject (readonly)

Returns the value of attribute build_number.



12
13
14
# File 'lib/pindo/module/task/model/git_task.rb', line 12

def build_number
  @build_number
end

#build_versionObject (readonly)

Returns the value of attribute build_version.



12
13
14
# File 'lib/pindo/module/task/model/git_task.rb', line 12

def build_version
  @build_version
end

#commit_hashObject (readonly)

Returns the value of attribute commit_hash.



12
13
14
# File 'lib/pindo/module/task/model/git_task.rb', line 12

def commit_hash
  @commit_hash
end

#git_root_pathObject (readonly)

Returns the value of attribute git_root_path.



10
11
12
# File 'lib/pindo/module/task/model/git_task.rb', line 10

def git_root_path
  @git_root_path
end

#project_pathObject (readonly)

Returns the value of attribute project_path.



10
11
12
# File 'lib/pindo/module/task/model/git_task.rb', line 10

def project_path
  @project_path
end

#release_branchObject (readonly)

Returns the value of attribute release_branch.



11
12
13
# File 'lib/pindo/module/task/model/git_task.rb', line 11

def release_branch
  @release_branch
end

#tag_preObject (readonly)

Returns the value of attribute tag_pre.



11
12
13
# File 'lib/pindo/module/task/model/git_task.rb', line 11

def tag_pre
  @tag_pre
end

#tag_typeObject (readonly)

Returns the value of attribute tag_type.



11
12
13
# File 'lib/pindo/module/task/model/git_task.rb', line 11

def tag_type
  @tag_type
end

#ver_incObject (readonly)

Returns the value of attribute ver_inc.



11
12
13
# File 'lib/pindo/module/task/model/git_task.rb', line 11

def ver_inc
  @ver_inc
end

Class Method Details

.default_retry_countObject



49
50
51
# File 'lib/pindo/module/task/model/git_task.rb', line 49

def self.default_retry_count
  0  # 默认不重试
end

.default_retry_delayObject



53
54
55
# File 'lib/pindo/module/task/model/git_task.rb', line 53

def self.default_retry_delay
  5  # 默认延迟 5 秒
end

.default_retry_modeObject

Git 任务默认重试配置



45
46
47
# File 'lib/pindo/module/task/model/git_task.rb', line 45

def self.default_retry_mode
  RetryMode::IMMEDIATE  # 立即重试
end

.task_typeObject

Git 任务类型



35
36
37
# File 'lib/pindo/module/task/model/git_task.rb', line 35

def self.task_type
  :git
end

.task_type_nameObject

Git 任务类型显示名称



40
41
42
# File 'lib/pindo/module/task/model/git_task.rb', line 40

def self.task_type_name
  "Git操作"
end

Instance Method Details

#required_resourcesObject

声明所需资源 - 基于仓库路径锁定 Git 操作确保同一仓库的 Git 任务串行执行,避免并发冲突



71
72
73
# File 'lib/pindo/module/task/model/git_task.rb', line 71

def required_resources
  (super || []) + [{ type: :git, directory: @git_root_path }]
end

#validateObject

验证项目路径



58
59
60
61
62
63
64
65
66
67
# File 'lib/pindo/module/task/model/git_task.rb', line 58

def validate
  super

  unless @project_path && Dir.exist?(@project_path)
    @error = "项目路径不存在:#{@project_path}"
    return false
  end

  true
end