Class: Pindo::Command::Dev::Pub

Inherits:
Pindo::Command::Dev show all
Defined in:
lib/pindo/command/dev/pub.rb

Constant Summary

Constants inherited from Pindo::Command

Pindo::Command::DEFAULT_OPTIONS, Pindo::Command::DEFAULT_ROOT_OPTIONS

Instance Attribute Summary

Attributes inherited from Pindo::Command

#args_help_flag

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pindo::Command

run, #validate!

Methods included from Funlog::Mixin

#pindo_log_instance

Methods included from Pindoconfig::Mixin

#pindo_single_config

Methods included from Githelper

#add_branch, #add_tag, #add_tag_with_check, #clone_clang_repo, #clone_devclang_repo, #clone_pindo_common_config_repo, #clone_pindo_env_config_repo, #clong_buildconfig_repo, #get_repo_base_name, #getcode_to_dir, #git_addpush_repo, #git_latest_commit_id, #local_branch_exists?, #local_tag_exists?, #prepare_gitenv, #process_need_add_files, #remote_branch_exists?, #remote_tag_exists?, #remove_branch, #remove_tag

Methods included from Executable

capture_command, #executable, execute_command, which, which!

Constructor Details

#initialize(argv) ⇒ Pub

Returns a new instance of Pub.



23
24
25
26
27
# File 'lib/pindo/command/dev/pub.rb', line 23

def initialize(argv)

    super
    @additional_args = argv.remainder!
end

Class Method Details

.optionsObject



18
19
20
21
# File 'lib/pindo/command/dev/pub.rb', line 18

def self.options
[
].concat(super)
end

Instance Method Details

#add_release_info(project_dir: nil) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/pindo/command/dev/pub.rb', line 53

def add_release_info(project_dir:nil)
    
    puts 
    puts "输入Release 备注:"
    description = PgyerHelper.share_instace.get_description()
    File.open("#{project_dir}/.release_info", 'w') { |f| f.write(description) }
    git_addpush_repo(path:project_dir, message:"update release info", commit_file_params:[".release_info"])           

end

#add_release_tag(project_dir: nil) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/pindo/command/dev/pub.rb', line 63

def add_release_tag(project_dir:nil)

    time_str =  Time.now.strftime('%Y_%m_%d')
    tag_name = "dev_" + time_str
    remove_tag(local_repo_dir:project_dir, tag_name:tag_name)
    result = add_tag(local_repo_dir:project_dir, tag_name:tag_name)

    puts
    puts "已经为当前仓库添加tag: #{tag_name}"
    puts "仓库路径:#{project_dir}"
    puts

end

#merge_to_release_branch(project_dir: nil, release_branch: nil, coding_branch: nil) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/pindo/command/dev/pub.rb', line 78

def merge_to_release_branch(project_dir:nil, release_branch:nil, coding_branch:nil)

      current_project_dir = project_dir


      if !coding_branch.eql?(release_branch)

          coding_branch_commit_id = git!(%W(-C #{current_project_dir} rev-parse #{coding_branch})).strip
          release_branch_commit_id = "111"
            
            if remote_branch_exists?(local_repo_dir: current_project_dir, branch:release_branch)
                  if local_branch_exists?(local_repo_dir: current_project_dir, branch:release_branch)
                      puts "存在#{release_branch}远程分支"
                      puts "存在#{release_branch}本地分支"
                      git!(%W(-C #{current_project_dir} checkout #{release_branch}))
                  else
                      puts "存在#{release_branch}远程分支"
                      puts "不存在#{release_branch}本地分支"
                      git!(%W(-C #{current_project_dir} checkout -b #{release_branch} origin/#{release_branch}))
                  end

                  git!(%W(-C #{current_project_dir} branch --set-upstream-to=origin/#{release_branch} #{release_branch}))
                  git!(%W(-C #{current_project_dir} pull))
                  # git!(%W(-C #{current_project_dir} merge #{coding_branch} --quiet))
                  res_data = Executable.capture_command('git', %W(merge #{coding_branch}), :capture => :out)

                  conflict_filelist = git!(%W(-C #{current_project_dir} diff --name-only --diff-filter=U --relative))
                  if !conflict_filelist.nil? && conflict_filelist.size > 0
                      puts "合并代码冲突, 冲突文件如下:"

                      raise Informative, "请手动处理冲突的文件!!!"

                  else
                      git!(%W(-C #{current_project_dir} push))


                      puts ""
                      puts "===================================="
                      puts "代码已经合并到#{release_branch}分支"
                      puts "===================================="
                      puts ""
                      release_branch_commit_id = git!(%W(-C #{current_project_dir} rev-parse #{release_branch})).strip
                  end

            else
                  if local_branch_exists?(local_repo_dir: current_project_dir, branch:release_branch)
                      puts "不存在#{release_branch}远程分支"
                      puts "存在#{release_branch}本地分支"
                      git!(%W(-C #{current_project_dir} checkout #{release_branch}))
                      git!(%W(-C #{current_project_dir} checkout -b #{release_branch}_temp))
                      git!(%W(-C #{current_project_dir} checkout #{coding_branch}))
                      git!(%W(-C #{current_project_dir} branch -D #{release_branch}))
                  else
                      puts "不存在#{release_branch}远程分支"
                      puts "不存在#{release_branch}本地分支"
                  end

                  git!(%W(-C #{current_project_dir} checkout -b #{release_branch}))
                  git!(%W(-C #{current_project_dir} push origin #{release_branch}))
                  git!(%W(-C #{current_project_dir} branch --set-upstream-to=origin/#{release_branch} #{release_branch}))


                  puts ""
                  puts "===================================="
                  puts "代码已经合并到#{release_branch}分支"
                  puts "===================================="
                  puts ""
                  release_branch_commit_id = git!(%W(-C #{current_project_dir} rev-parse #{release_branch})).strip
            end


            git!(%W(-C #{current_project_dir} checkout #{coding_branch}))
            if !release_branch_commit_id.eql?(coding_branch_commit_id)
                git!(%W(-C #{current_project_dir} merge #{release_branch}))
                puts
                puts "已将#{release_branch}合并到#{coding_branch}"
                puts
            end

      else
                  puts ""
                  puts "===================================="
                  puts "代码处于#{coding_branch}分支,无需合并"
                  puts "===================================="
                  puts ""
      end

end

#runObject



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/pindo/command/dev/pub.rb', line 29

def run

    release_branch = "master"
    current_project_dir = Dir.pwd

    process_need_add_files(project_dir:current_project_dir)

    answer = agree("是否添加发布备注信息?(Y/n)")
    if answer
      add_release_info(project_dir:current_project_dir)
    end
    
    answer = agree("是否将代码合并到master分支?(Y/n)")

    if answer
        current_branch = git!(%W(-C #{current_project_dir} rev-parse --abbrev-ref HEAD)).strip
        coding_branch = current_branch
        merge_to_release_branch(project_dir:current_project_dir, release_branch:release_branch, coding_branch:coding_branch)
        add_release_tag(project_dir:current_project_dir)
    end
   

end