module BigKeeper

Bigkeeper module

Constants

DEFAULT_LOG
ERROR_LOG
HIGHLIGHT_LOG
VERSION
WARNING_LOG

Public Class Methods

delete(path, user, name, type) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 14
def self.home(name, params)
  BigkeeperParser.parse_home(name, params)
end
modules() { || ... } click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 22
def self.modules
  BigkeeperParser.parse_modules
  yield if block_given?
end
pod(name, params) click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 18
def self.pod(name, params)
  BigkeeperParser.parse_pod(name, params)
end
podfile_detect(path) click to toggle source
# File lib/big_keeper/command/pod/podfile.rb, line 11
def self.podfile_detect(path)
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    # Get modules' name
    module_list = BigkeeperParser.module_names
    # initialize PodfileDetector
    detector = PodfileDetector.new(path,module_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) click to toggle source
# File lib/big_keeper/command/pod/podfile.rb, line 28
def self.podfile_lock(path)
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    # Get modules' name
    module_list = BigkeeperParser.module_names
    # initialize PodfileDetector
    detector = PodfileDetector.new(path,module_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
podfile_modules_update(path) click to toggle source
# File lib/big_keeper/command/pod/podfile.rb, line 51
def self.podfile_modules_update(path)
    # Parse Bigkeeper file
    BigkeeperParser.parse("#{path}/Bigkeeper")
    # Get modules' name
    module_list = BigkeeperParser.module_names
    # initialize PodfileDetector
    detector = PodfileModuleDetector.new(path)
    # Get module latest version
    module_dictionary = detector.check_version_list
    # Check if anything should be upgrade
    if module_dictionary.empty?
      Logger.warning("There is nothing to be upgrade.")
    else
      PodfileOperator.new.find_and_upgrade("#{path}/Podfile",module_dictionary)
      Logger.highlight("The Podfile has been changed.")
    end
end
pull(path, user, type) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) { || ... } click to toggle source
# 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) click to toggle source
# File lib/big_keeper/util/bigkeeper_parser.rb, line 5
def self.version(name)
  BigkeeperParser.parse_version(name)
end

Private Class Methods

get_module_path_default(path, user, module_name) click to toggle source
# File lib/big_keeper/command/release/module.rb, line 97
def self.get_module_path_default(path, user, module_name)
  module_path = BigkeeperParser::module_path(user, module_name)
  if module_path == "../#{module_name}"
    path_array = path.split('/')
    path_array.pop()
    module_path = path_array.join('/') + "/#{module_name}"
  end
  module_path
end
start_module_release(module_path, version, module_name, source, user) click to toggle source
# File lib/big_keeper/command/release/module.rb, line 62
def self.start_module_release(module_path, version, module_name, source, user)
  if GitOperator.new.has_changes(module_path)
    StashService.new.stash_all(module_path, GitOperator.new.current_branch(module_path), user, module_name.split())
  end

  # step 1 checkout to develop branch
  Logger.highlight(%Q(Start checkout #{module_name} to Branch develop))
  if GitOperator.new.current_branch(module_path) != "develop"
    if GitOperator.new.has_branch(module_path, "develop")
      GitOperator.new.checkout(module_path, "develop")
    else
      Logger.error("Cann't find develop branch, please check.")
    end
  end

  Dir.chdir(module_path) do
    # Pod lib lint
    Logger.highlight(%Q(Start Pod lib lint #{module_name}))
    has_error = false
    IO.popen("pod lib lint --allow-warnings --verbose --use-libraries --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 lib error in '#{module_name}'")
      return
    end
  end

  GitOperator.new.commit(module_path, "update podspec")
  GitOperator.new.first_push(module_path, GitOperator.new.current_branch(module_path))
  Logger.highlight(%Q(Pod lib lint success))
end
start_release(project_path, version, modules, user) click to toggle source
# File lib/big_keeper/command/release/home.rb, line 37
def self.start_release(project_path, version, modules, user)
  Dir.chdir(project_path) do
    # step 0 Stash current branch
    StashService.new.stash_all(project_path, GitOperator.new.current_branch(project_path), user, modules)

    Logger.highlight(%Q(Start to checkout Branch release/#{version}))
    # step 1 checkout release
    if GitOperator.new.current_branch(project_path) != "release/#{version}"
      if GitOperator.new.has_branch(project_path, "release/#{version}")
        GitOperator.new.checkout(project_path, "release/#{version}")
      else
        GitflowOperator.new.start(project_path, version, GitflowType::RELEASE)
        GitOperator.new.push_to_remote(project_path, "release/#{version}")
      end
    end

    Logger.highlight(%Q(Start to release/#{version}))
    # step 2 replace_modules
    PodfileOperator.new.replace_all_module_release(%Q(#{project_path}/Podfile),
                                                    modules,
                                                    version)

    # step 3 change Info.plist value
    InfoPlistOperator.new.change_version_build(project_path, version)

    PodOperator.pod_install(project_path)
    `open #{project_path}/*.xcworkspace`
  end
end