Module: BigKeeper

Defined in:
lib/big_keeper/util/bigkeeper_parser.rb,
lib/big_keeper.rb,
lib/big_keeper/version.rb,
lib/big_keeper/util/log_util.rb,
lib/big_keeper/util/git_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/feature_pull.rb,
lib/big_keeper/command/feature_push.rb,
lib/big_keeper/command/podfile_lock.rb,
lib/big_keeper/command/release_home.rb,
lib/big_keeper/command/feature_start.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/feature_finish.rb,
lib/big_keeper/command/feature_switch.rb,
lib/big_keeper/command/feature_update.rb,
lib/big_keeper/command/release_module.rb,
lib/big_keeper/service/module_service.rb,
lib/big_keeper/util/info_plist_operator.rb

Overview

Bigkeeper module

Defined Under Namespace

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

Constant Summary collapse

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

Class Method Summary collapse

Class Method Details

.feature_finish(path, user) ⇒ Object



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
46
# File 'lib/big_keeper/command/feature_finish.rb', line 10

def self.feature_finish(path, user)
  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)
    raise "Not a feature branch, exit." unless branch_name.include? 'feature'

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

    BigkeeperParser.module_names.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, 'develop'))
    end

    # pod install
    p `pod install --project-directory=#{path}`

    # Push home changes to remote
    GitOperator.new.commit(path, "finish #{GitflowType.name(GitflowType::FEATURE)} #{branch_name}")
    GitOperator.new.push(path, branch_name)

    GitService.new.verify_rebase(path, 'develop', 'Home')

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

.feature_pull(path, user) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/big_keeper/command/feature_pull.rb', line 2

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

    branch_name = GitOperator.new.current_branch(path)
    raise 'Not a feature branch, exit.' unless branch_name.include? 'feature'

    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)
    end

    p "Pull branch #{branch_name} for home..."
    GitOperator.new.pull(path)
  ensure
  end
end

.feature_push(path, user, comment) ⇒ Object



3
4
5
6
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
# File 'lib/big_keeper/command/feature_push.rb', line 3

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

    branch_name = GitOperator.new.current_branch(path)
    raise "Not a feature branch, exit." unless branch_name.include? 'feature'

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

    modules.each do |module_name|
      module_full_path = BigkeeperParser.module_full_path(path, user, module_name)
      module_branch_name = GitOperator.new.current_branch(module_full_path)

      if GitOperator.new.has_changes(module_full_path)
        p "Push branch #{branch_name} for module #{module_name}..."
        GitOperator.new.commit(module_full_path, comment)
        GitOperator.new.push(module_full_path, module_branch_name)
      else
        p "Nothing to push for #{module_name}."
      end
    end

    if GitOperator.new.has_changes(path)
      p "Push branch #{branch_name} for home..."
      GitOperator.new.commit(path, comment)
      GitOperator.new.push(path, branch_name)
    else
      p "Nothing to push for home."
    end
  ensure
  end
end

.feature_start(path, version, user, name, modules) ⇒ Object



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
52
53
54
55
56
57
58
59
# File 'lib/big_keeper/command/feature_start.rb', line 14

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

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

    GitService.new.verify_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(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

    # Start home feature
    GitService.new.start(path, feature_name, GitflowType::FEATURE)

    # Modify podfile as path and Start modules feature
    modules.each do |module_name|
      ModuleService.new.add(path, user, module_name, feature_name, GitflowType::FEATURE)
    end

    # pod install
    p `pod install --project-directory=#{path}`

    # Push home changes to remote
    GitOperator.new.commit(path, "init #{GitflowType.name(GitflowType::FEATURE)} #{feature_name}")
    GitOperator.new.push(path, branch_name)

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

.feature_switch(path, version, user, name) ⇒ Object



4
5
6
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
# File 'lib/big_keeper/command/feature_switch.rb', line 4

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

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

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

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

    # Stash current branch
    StashService.new.stash(path, branch_name, user, stath_modules)

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

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

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

    # Apply stash
    StashService.new.apply_stash(path, branch_name, user, modules)

    # pod install
    p `pod install --project-directory=#{path}`

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

.feature_update(path, user, modules) ⇒ Object



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
52
53
54
55
56
57
58
59
# File 'lib/big_keeper/command/feature_update.rb', line 14

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

    branch_name = GitOperator.new.current_branch(path)
    raise "Not a feature branch, exit." unless branch_name.include? 'feature'

    feature_name = branch_name.gsub(/feature\//, '')

    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

    add_modules = modules - current_modules
    del_modules = current_modules - modules

    if add_modules.empty? and del_modules.empty?
      p "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, feature_name, GitflowType::FEATURE)
      end

      del_modules.each do |module_name|
        ModuleService.new.del(path, user, module_name, feature_name, GitflowType::FEATURE)
      end

      # pod install
      p `pod install --project-directory=#{path}`

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

.home(name, params) ⇒ Object



12
13
14
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 12

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

.modulesObject



20
21
22
23
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 20

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

.pod(name, params) ⇒ Object



16
17
18
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 16

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/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|
      BigKeeperLog.default("#{pod_name} should be locked.")
    end
    BigKeeperLog.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/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?
      BigKeeperLog.warning("There is nothing to be locked.")
    else
      PodfileOperator.new.find_and_lock("#{path}/Podfile",dictionary)
      BigKeeperLog.highlight("The Podfile has been changed.")
      BigKeeperLog.separator
    end



end

.release_home_finish(path, version) ⇒ Object



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

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

.release_home_start(path, version, user) ⇒ Object



8
9
10
11
# File 'lib/big_keeper/command/release_home.rb', line 8

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

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



8
9
10
11
12
13
14
# File 'lib/big_keeper/command/release_module.rb', line 8

def self.start_module_release(path, version, user, module_name)
  main_path = File.expand_path("#{path}/Example")
  module_release(main_path,
              version,
    BigkeeperParser::module_names,
    GitInfo.new(BigkeeperParser::home_git, GitType::TAG, version), user)
end

.user(name) ⇒ Object



7
8
9
10
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 7

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

.version(name) ⇒ Object



3
4
5
# File 'lib/big_keeper/util/bigkeeper_parser.rb', line 3

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