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



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/big_keeper/service/module_service.rb', line 74

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)

  module_path = BigkeeperParser.module_path(user, module_name)
  PodfileOperator.new.find_and_replace("#{path}/Podfile",
                                       module_name,
                                       ModuleType::PATH,
                                       module_path)
end

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



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/big_keeper/service/module_service.rb', line 88

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_full_path = BigkeeperParser.module_full_path(path, user, module_name)

  StashService.new.stash(module_full_path, home_branch_name, module_name)

  GitOperator.new.checkout(module_full_path, GitflowType.base_branch(type))
  # GitOperator.new.del(module_full_path, home_branch_name)

  module_git = BigkeeperParser.module_git(module_name)

  PodfileOperator.new.find_and_replace("#{path}/Podfile",
                                       module_name,
                                       ModuleType::GIT,
                                       GitInfo.new(module_git, GitType::BRANCH, GitflowType.base_branch(type)))
end

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



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/big_keeper/service/module_service.rb', line 54

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)

  module_git = BigkeeperParser.module_git(module_name)
  PodfileOperator.new.find_and_replace("#{path}/Podfile",
                                       module_name,
                                       ModuleType::GIT,
                                       GitInfo.new(module_git, GitType::BRANCH, home_branch_name))

  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)

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

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

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



39
40
41
42
43
44
45
46
# File 'lib/big_keeper/service/module_service.rb', line 39

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



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

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

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



48
49
50
51
52
# File 'lib/big_keeper/service/module_service.rb', line 48

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

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



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/big_keeper/service/module_service.rb', line 8

def verify_module(path, user, module_name, home_branch_name, type)
  name = home_branch_name.gsub(/#{GitflowType.name(type)}\//, '')
  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)

  git = GitOperator.new
  if !File.exist? module_full_path
    Logger.default("No local repository for module '#{module_name}', clone it...")
    module_git = BigkeeperParser.module_git(module_name)
    git.new.clone(File.expand_path("#{module_full_path}/../"), module_git)
  end

  current_branch_name = git.current_branch(module_full_path)
  if current_branch_name != home_branch_name
    # stash current branch
    StashService.new.stash(module_full_path, current_branch_name, module_name)

    GitService.new.start(module_full_path, name, type)

    StashService.new.pop_stash(module_full_path, home_branch_name, module_name)
  end
end