Class: BigKeeper::ModuleService

Inherits:
Object
  • Object
show all
Defined in:
lib/big_keeper/service/module_service.rb

Overview

Operator for got

Instance Method Summary collapse

Instance Method Details

#add(path, user, module_name, name, type) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/big_keeper/service/module_service.rb', line 109

def add(path, user, module_name, name, type)
  home_branch_name = "#{GitflowType.name(type)}/#{name}"
  Logger.highlight("Add branch '#{home_branch_name}' for module '#{module_name}'...")

  verify_module(path, user, module_name, home_branch_name, type)

  DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::ADD)

  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
  GitService.new.verify_push(module_full_path, "init #{GitflowType.name(type)} #{name}", home_branch_name, module_name)

  ModuleCacheOperator.new(path).add_path_module(module_name)
end

#del(path, user, module_name, name, type) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/big_keeper/service/module_service.rb', line 123

def del(path, user, module_name, name, type)
  home_branch_name = "#{GitflowType.name(type)}/#{name}"

  Logger.highlight("Delete branch '#{home_branch_name}' for module '#{module_name}'...")

  module_git = BigkeeperParser.module_git(module_name)
  DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::DELETE)

  # Stash module current branch
  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
  current_branch_name = GitOperator.new.current_branch(module_full_path)
  StashService.new.stash(module_full_path, current_branch_name, module_name)
  GitOperator.new.checkout(module_full_path, GitflowType.base_branch(type))

  ModuleCacheOperator.new(path).del_path_module(module_name)
end

#finish(path, user, module_name, home_branch_name, type) ⇒ Object



95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/big_keeper/service/module_service.rb', line 95

def finish(path, user, module_name, home_branch_name, type)
  Logger.highlight("Finish branch '#{home_branch_name}' for module '#{module_name}'...")

  verify_module(path, user, module_name, home_branch_name, type)

  DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::FINISH)

  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
  GitService.new.verify_push(module_full_path, "finish branch #{home_branch_name}", home_branch_name, module_name)

  ModuleCacheOperator.new(path).add_git_module(module_name)
  ModuleCacheOperator.new(path).del_path_module(module_name)
end

#module_info(module_path, home_branch_name, user, type, module_name, version) ⇒ Object



140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/big_keeper/service/module_service.rb', line 140

def module_info(module_path, home_branch_name, user, type, module_name, version)
  result_dic = {}
  matched_branches = []
  branches = GitService.new.branchs_with_type(module_path, type)
  if version == 'all versions'
    matched_branches = branches
  else
    branches.each do | branch |
      matched_branches << branch if branch.include?(version)
    end
  end
  result_dic[:module_name] = module_name
  result_dic[:current_branch] = GitOperator.new.current_branch(module_path)
  result_dic[:branches] = matched_branches
  result_dic
end

#pre_publish(path, user, module_name, home_branch_name, type) ⇒ Object



72
73
74
75
76
77
78
79
80
# File 'lib/big_keeper/service/module_service.rb', line 72

def pre_publish(path, user, module_name, home_branch_name, type)
  Logger.highlight("Prepare to publish branch '#{home_branch_name}' for module '#{module_name}'...")

  verify_module(path, user, module_name, home_branch_name, type)

  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
  GitService.new.verify_push(module_full_path, "prepare to rebase '#{GitflowType.base_branch(type)}'", home_branch_name, module_name)
  GitService.new.verify_rebase(module_full_path, GitflowType.base_branch(type), module_name)
end

#publish(path, user, module_name, home_branch_name, type) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/big_keeper/service/module_service.rb', line 82

def publish(path, user, module_name, home_branch_name, type)
  Logger.highlight("Publish branch '#{home_branch_name}' for module '#{module_name}'...")

  DepService.dep_operator(path, user).update_module_config(module_name, ModuleOperateType::PUBLISH)

  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
  GitService.new.verify_push(module_full_path, "publish branch #{home_branch_name}", home_branch_name, module_name)

  `open #{BigkeeperParser.module_pulls(module_name)}`

  ModuleCacheOperator.new(path).del_git_module(module_name)
end

#pull(path, user, module_name, home_branch_name, type) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/big_keeper/service/module_service.rb', line 57

def pull(path, user, module_name, home_branch_name, type)
  Logger.highlight("Pull branch '#{home_branch_name}' for module '#{module_name}'...")

  verify_module(path, user, module_name, home_branch_name, type)

  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
  GitOperator.new.pull(module_full_path)
end

#push(path, user, module_name, home_branch_name, type, comment) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/big_keeper/service/module_service.rb', line 32

def push(path, user, module_name, home_branch_name, type, comment)
  Logger.highlight("Push branch '#{home_branch_name}' for module '#{module_name}'...")

  verify_module(path, user, module_name, home_branch_name, type)

  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
  GitService.new.verify_push(module_full_path, comment, home_branch_name, module_name)
end

#rebase(path, user, module_name, home_branch_name, type) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/big_keeper/service/module_service.rb', line 41

def rebase(path, user, module_name, home_branch_name, type)
  Logger.highlight("Rebase '#{GitflowType.base_branch(type)}' "\
    "to branch '#{home_branch_name}' for module "\
    "'#{module_name}'...")

  verify_module(path, user, module_name, home_branch_name, type)

  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)

  Logger.error("You have some changes in branch "\
    "'#{home_branch_name}' for module '#{module_name}'. "\
    "Use 'push' first please") if GitOperator.new.has_changes(module_full_path)

  GitService.new.verify_rebase(module_full_path, GitflowType.base_branch(type), module_name)
end

#switch_to(path, user, module_name, home_branch_name, type) ⇒ Object



66
67
68
69
70
# File 'lib/big_keeper/service/module_service.rb', line 66

def switch_to(path, user, module_name, home_branch_name, type)
  Logger.highlight("Switch to branch '#{home_branch_name}' for module '#{module_name}'...")

  verify_module(path, user, module_name, home_branch_name, type)
end