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



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/big_keeper/service/module_service.rb', line 58

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

  p "Add branch #{branch_name} for module #{module_name}..."

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

  # clone module if not exist
  if !File.exist? module_full_path
    module_git = BigkeeperParser.module_git(module_name)
    GitOperator.new.clone(File.expand_path("#{module_full_path}/../"), module_git)
  end

  # stash current branch
  current_branch_name = GitOperator.new.current_branch(module_full_path)
  BigStash::StashOperator.new(module_full_path).stash(current_branch_name)

  # start new feature/hotfix
  GitService.new.start(module_full_path, name, type)

  # apply stash
  BigStash::StashOperator.new(module_full_path).apply_stash(branch_name)

  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)
  branch_name = "#{GitflowType.name(type)}/#{name}"

  p "del branch #{branch_name} for module #{module_name}..."

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

  BigStash::StashOperator.new(module_full_path).stash(branch_name)

  GitOperator.new.git_checkout(module_full_path, 'develop')
  GitOperator.new.del(module_full_path, 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, 'develop'))
end

#finish(path, user, module_name) ⇒ Object



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

def finish(path, user, module_name)
  module_git = BigkeeperParser.module_git(module_name)
  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
  branch_name = GitOperator.new.current_branch(module_full_path)

  p "Finish branch #{branch_name} for module #{module_name}..."

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

  GitService.new.verify_rebase(module_full_path, 'develop', module_name)

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

#pull(path, user, module_name, branch_name) ⇒ Object



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

def pull(path, user, module_name, branch_name)
  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)

  if !File.exist? module_full_path
    module_git = BigkeeperParser.module_git(module_name)
    GitOperator.new.clone(File.expand_path("#{module_full_path}/../"), module_git)
    GitOperator.new.git_checkout(module_full_path, branch_name)
  else
    current_branch_name = GitOperator.new.current_branch(module_full_path)
    if current_branch_name != branch_name
      p "Current branch of #{module_name} is #{current_branch_name},\
        stash it and checkout #{branch_name}..."
      BigStash::StashOperator.new(module_full_path).stash(current_branch_name)
      GitOperator.new.git_checkout(module_full_path, branch_name)
    end
    p "Pull branch #{branch_name} for module #{module_name}..."
    GitOperator.new.pull(module_full_path)
  end
end

#switch(path, user, module_name, branch_name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/big_keeper/service/module_service.rb', line 26

def switch(path, user, module_name, branch_name)
  module_full_path = BigkeeperParser.module_full_path(path, user, module_name)

  p "Switch to branch #{branch_name} for module #{module_name}..."

  if !File.exist? module_full_path
    module_git = BigkeeperParser.module_git(module_name)
    GitOperator.new.clone(File.expand_path("#{module_full_path}/../"), module_git)
    GitOperator.new.git_checkout(module_full_path, branch_name)
  else
    GitOperator.new.git_checkout(module_full_path, branch_name)
    GitOperator.new.pull(module_full_path)
  end
end