Module: BigKeeper

Defined in:
lib/big_keeper/util/bigkeeper_parser.rb,
lib/big_keeper.rb,
lib/big_keeper/version.rb,
lib/big_keeper/util/logger.rb,
lib/big_keeper/util/git_operator.rb,
lib/big_keeper/util/pod_operator.rb,
lib/big_keeper/model/gitflow_type.rb,
lib/big_keeper/model/operate_type.rb,
lib/big_keeper/model/podfile_type.rb,
lib/big_keeper/model/podfile_model.rb,
lib/big_keeper/service/git_service.rb,
lib/big_keeper/command/release/home.rb,
lib/big_keeper/service/stash_service.rb,
lib/big_keeper/util/gitflow_operator.rb,
lib/big_keeper/util/podfile_detector.rb,
lib/big_keeper/util/podfile_operator.rb,
lib/big_keeper/command/release/module.rb,
lib/big_keeper/service/module_service.rb,
lib/big_keeper/command/pod/podfile_lock.rb,
lib/big_keeper/util/info_plist_operator.rb,
lib/big_keeper/command/feature&hotfix/pull.rb,
lib/big_keeper/command/feature&hotfix/push.rb,
lib/big_keeper/command/feature&hotfix/start.rb,
lib/big_keeper/command/feature&hotfix/delete.rb,
lib/big_keeper/command/feature&hotfix/finish.rb,
lib/big_keeper/command/feature&hotfix/switch.rb,
lib/big_keeper/command/feature&hotfix/update.rb

Overview

Bigkeeper module

Defined Under Namespace

Modules: GitType, GitflowType, ModuleType, OperateType Classes: BigkeeperParser, GitInfo, GitOperator, GitService, GitflowOperator, InfoPlistOperator, Logger, ModuleService, PodOperator, PodfileDetector, PodfileOperator, Podfile_Modle, StashService

Constant Summary collapse

VERSION =
"0.7.1"
DEFAULT_LOG =
1
HIGHLIGHT_LOG =
2
ERROR_LOG =
3
WARNING_LOG =
4

Class Method Summary collapse

Class Method Details

.delete(path, user, name, type) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/big_keeper/command/feature&hotfix/delete.rb', line 16

def self.delete(path, user, name, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    branch_name = "#{GitflowType.name(type)}/#{name}"

    modules = BigkeeperParser.module_names

    modules.each do |module_name|
      module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
      GitService.new.verify_del(module_full_path, branch_name, module_name, type)
    end

    GitService.new.verify_del(path, branch_name, 'Home', type)
  ensure
  end
end

.finish(path, user, type) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/big_keeper/command/feature&hotfix/finish.rb', line 13

def self.finish(path, user, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")

    modules = PodfileOperator.new.modules_with_type("#{path}/Podfile",
                              BigkeeperParser.module_names, ModuleType::PATH)
    branch_name = GitOperator.new.current_branch(path)

    Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

    # Rebase modules and modify podfile as git
    modules.each do |module_name|
      ModuleService.new.finish(path, user, module_name, branch_name, type)
    end

    Logger.highlight("Finish branch '#{branch_name}' for 'Home'")

    # pod install
    PodOperator.pod_install(path)

    modules.each do |module_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

    # Push home changes to remote
    GitService.new.verify_push(path, "finish branch #{branch_name}", branch_name, 'Home')

    # Rebase Home
    GitService.new.verify_rebase(path, GitflowType.base_branch(type), 'Home')

    `open #{BigkeeperParser.home_pulls()}`
  ensure
  end
end

.home(name, params) ⇒ Object



14
15
16
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 14

def self.home(name, params)
  BigkeeperParser.parse_home(name, params)
end

.modulesObject



22
23
24
25
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 22

def self.modules
  BigkeeperParser.parse_modules
  yield if block_given?
end

.pod(name, params) ⇒ Object



18
19
20
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 18

def self.pod(name, params)
  BigkeeperParser.parse_pod(name, params)
end

.podfile_detect(path) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/big_keeper/command/pod/podfile_lock.rb', line 11

def self.podfile_detect(path)
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    # Get modulars' name
    modular_list = BigkeeperParser.module_names
    # initialize PodfileDetector
    detector = PodfileDetector.new(path,modular_list)
    # Get unlocked third party pods list
    unlock_pod_list = detector.get_unlock_pod_list
    # Print out unlock pod list
    unlock_pod_list.each do |pod_name|
      Logger.default("#{pod_name} should be locked.")
    end
    Logger.separator

end

.podfile_lock(path) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/big_keeper/command/pod/podfile_lock.rb', line 28

def self.podfile_lock(path)
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    # Get modulars' name
    modular_list = BigkeeperParser.module_names
    # initialize PodfileDetector
    detector = PodfileDetector.new(path,modular_list)
    # Get unlocked third party pods list
    unlock_pod_list = detector.get_unlock_pod_list
    # Get Version
    dictionary = detector.deal_lock_file(path,unlock_pod_list)
    if dictionary.empty?
      Logger.warning("There is nothing to be locked.")
    else
      PodfileOperator.new.find_and_lock("#{path}/Podfile",dictionary)
      Logger.highlight("The Podfile has been changed.")
      Logger.separator
    end



end

.pull(path, user, type) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/big_keeper/command/feature&hotfix/pull.rb', line 4

def self.pull(path, user, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    branch_name = GitOperator.new.current_branch(path)

    Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

    modules = PodfileOperator.new.modules_with_type("#{path}/Podfile",
                                                    BigkeeperParser.module_names, ModuleType::PATH)

    modules.each do |module_name|
      ModuleService.new.pull(path, user, module_name, branch_name, type)
    end

    Logger.highlight("Pull branch '#{branch_name}' for 'Home'...")
    GitOperator.new.pull(path)
  ensure
  end
end

.push(path, user, comment, type) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/big_keeper/command/feature&hotfix/push.rb', line 5

def self.push(path, user, comment, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    branch_name = GitOperator.new.current_branch(path)

    Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

    modules = PodfileOperator.new.modules_with_type("#{path}/Podfile",
                              BigkeeperParser.module_names, ModuleType::PATH)

    modules.each do |module_name|
      ModuleService.new.push(path, user, module_name, branch_name, type, comment)
    end

    Logger.highlight("Push branch '#{branch_name}' for 'Home'...")
    GitService.new.verify_push(path, comment, branch_name, 'Home')
  ensure
  end
end

.release_home_finish(path, version) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/big_keeper/command/release/home.rb', line 14

def self.release_home_finish(path, version)
  Dir.chdir(path) do
    if GitOperator.new.has_branch(path, "release/#{version}")
      if GitOperator.new.current_branch(path) == "release/#{version}"
        GitOperator.new.commit(path, "release: V #{version}")
        GitOperator.new.push_to_remote(path, "release/#{version}")
        GitflowOperator.new.finish_release(path, version)
        if GitOperator.new.current_branch(path) == "master"
          GitOperator.new.tag(path, version)
        else
          GitOperator.new.checkout(path, "master")
          GitOperator.new.tag(path, version)
        end
      else
        raise Logger.error("Not in release branch, please check your branches.")
      end
    else
      raise Logger.error("Not has release branch, please use release start first.")
    end
  end
end

.release_home_start(path, version, user) ⇒ Object



9
10
11
12
# File 'lib/big_keeper/command/release/home.rb', line 9

def self.release_home_start(path, version, user)
  BigkeeperParser.parse("#{path}/Bigkeeper")
  start_release(path, version, BigkeeperParser::module_names, user)
end

.release_module_finish(path, version, user, module_name) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/big_keeper/command/release/module.rb', line 20

def self.release_module_finish(path, version, user, module_name)
  BigkeeperParser.parse("#{path}/Bigkeeper")
  module_path = self.get_module_path_default(path, user, module_name)

  Logger.error("current branch has changed") unless GitOperator.new.has_changes(module_path)
  # check out master
  if GitOperator.new.current_branch(module_path) != "master"
    current_name = GitOperator.new.current_branch(module_path)
    GitOperator.new.checkout(module_path, "master")
    Logger.highlight("Push branch '#{current_name}' for '#{module_name}'...")
    GitService.new.verify_push(module_path, "finish #{GitflowType.name(GitflowType::RELEASE)} #{current_name}", "master", "#{module_name}")
  end
  return

  Dir.chdir(module_path) do
    # rebase develop to master
    Logger.highlight(%Q(Rebase develop to master))

    #修改 podspec 文件
    # TO DO: - advanced to use Regular Expression
    PodfileOperator.new.podspec_change(%Q(#{module_path}/#{module_name}.podspec), version, module_name)

    GitService.new.verify_rebase(module_path, 'develop', "#{module_name}")
    GitOperator.new.verify_push(module_path, "finish rebase develop to master", "master", "#{module_name}")
    GitOperator.new.tag(module_path, version)

    Logger.highlight(%Q(Start Pod repo push #{module_name}))
    IO.popen("pod repo push #{module_name} #{module_name}.podspec --allow-warnings --sources=#{BigkeeperParser::sourcemodule_path}") do |io|
      io.each do |line|
        has_error = true if line.include? "ERROR"
      end
    end
    if has_error
      Logger.error("Pod repo push in '#{module_name}'")
      return
    end

    Logger.highlight(%Q(Success release #{module_name} V#{version}))
  end
end

.release_module_start(path, version, user, module_name) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/big_keeper/command/release/module.rb', line 10

def self.release_module_start(path, version, user, module_name)
  BigkeeperParser.parse("#{path}/Bigkeeper")

  Dir.chdir(path) do
    git_info = GitInfo.new(BigkeeperParser::home_git, GitType::TAG, version)
    module_path = self.get_module_path_default(path, user, module_name)
    start_module_release(module_path, version, module_name, git_info, user)
  end
end

.source(name) ⇒ Object



27
28
29
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 27

def self.source(name)
  BigkeeperParser.parse_source(name)
end

.start(path, version, user, name, modules, type) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/big_keeper/command/feature&hotfix/start.rb', line 16

def self.start(path, version, user, name, modules, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")

    version = BigkeeperParser.version if version == 'Version in Bigkeeper file'
    full_name = "#{version}_#{user}_#{name}"
    branch_name = "#{GitflowType.name(type)}/#{full_name}"

    GitService.new.verify_home_branch(path, branch_name, OperateType::START)

    stash_modules = PodfileOperator.new.modules_with_type("#{path}/Podfile",
                              BigkeeperParser.module_names, ModuleType::PATH)

    # Stash current branch
    StashService.new.stash_all(path, branch_name, user, stash_modules)

    # Handle modules
    if modules
      # Verify input modules
      BigkeeperParser.verify_modules(modules)
    else
      # Get all modules if not specified
      modules = BigkeeperParser.module_names
    end

    Logger.highlight("Add branch '#{branch_name}' for 'Home'...")
    # Start home feature
    GitService.new.start(path, full_name, type)

    # Modify podfile as path and Start modules feature
    modules.each do |module_name|
      ModuleService.new.add(path, user, module_name, full_name, type)
    end

    # pod install
    PodOperator.pod_install(path)

    # Push home changes to remote
    GitService.new.verify_push(path, "init #{GitflowType.name(type)} #{full_name}", branch_name, 'Home')

    # Open home workspace
    `open #{path}/*.xcworkspace`
  ensure
  end
end

.switch_to(path, version, user, name, type) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/big_keeper/command/feature&hotfix/switch.rb', line 7

def self.switch_to(path, version, user, name, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")

    version = BigkeeperParser.version if version == 'Version in Bigkeeper file'
    full_name = "#{version}_#{user}_#{name}"
    branch_name = "#{GitflowType.name(type)}/#{full_name}"

    GitService.new.verify_home_branch(path, branch_name, OperateType::SWITCH)

    stash_modules = PodfileOperator.new.modules_with_type("#{path}/Podfile",
                              BigkeeperParser.module_names, ModuleType::PATH)

    # Stash current branch
    StashService.new.stash_all(path, branch_name, user, stash_modules)

    # Switch to new feature
    GitOperator.new.checkout(path, branch_name)
    GitOperator.new.pull(path)

    # Apply home stash
    StashService.new.pop_stash(path, branch_name, 'Home')

    modules = PodfileOperator.new.modules_with_type("#{path}/Podfile",
                              BigkeeperParser.module_names, ModuleType::PATH)

    modules.each do |module_name|
      ModuleService.new.switch_to(path, user, module_name, branch_name, type)
    end

    # pod install
    PodOperator.pod_install(path)

    # Open home workspace
    `open #{path}/*.xcworkspace`
  ensure
  end
end

.update(path, user, modules, type) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/big_keeper/command/feature&hotfix/update.rb', line 16

def self.update(path, user, modules, type)
  begin
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    branch_name = GitOperator.new.current_branch(path)

    Logger.error("Not a #{GitflowType.name(type)} branch, exit.") unless branch_name.include? GitflowType.name(type)

    full_name = branch_name.gsub(/#{GitflowType.name(type)}\//, '')

    current_modules = PodfileOperator.new.modules_with_type("#{path}/Podfile",
                              BigkeeperParser.module_names, ModuleType::PATH)

    # Handle modules
    if modules
      # Verify input modules
      BigkeeperParser.verify_modules(modules)
    else
      # Get all modules if not specified
      modules = BigkeeperParser.module_names
    end

    Logger.highlight("Start to update modules for branch '#{branch_name}'...")

    add_modules = modules - current_modules
    del_modules = current_modules - modules

    if add_modules.empty? and del_modules.empty?
      Logger.default("There is nothing changed with modules #{modules}.")
    else
      # Modify podfile as path and Start modules feature
      add_modules.each do |module_name|
        ModuleService.new.add(path, user, module_name, full_name, type)
      end

      del_modules.each do |module_name|
        ModuleService.new.del(path, user, module_name, full_name, type)
      end

      # pod install
      PodOperator.pod_install(path)

      # Open home workspace
      `open #{path}/*.xcworkspace`
    end
  ensure
  end
end

.user(name) ⇒ Object



9
10
11
12
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 9

def self.user(name)
  BigkeeperParser.parse_user(name)
  yield if block_given?
end

.version(name) ⇒ Object



5
6
7
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 5

def self.version(name)
  BigkeeperParser.parse_version(name)
end