require "pathname" require 'date' require_relative 'git_helper' require 'terminal-table' require_relative 'pod_helper.rb' require "cocoapods" require_relative "module.rb" require_relative "spec_helper.rb" module QCloudHive def QCloudHive.RemapProduct(cmd, opts) pods = HivePod.podspecs Repo.addChildSpec("xxxx",pods[3]) end class Repo def Repo.push(cmd, opts) end def Repo.relaseCommits(name) end def Repo.request(cmd, opts) git = Git.open(Dir.pwd) if git == nil Error("当前不是Git目录") end message = GetOptValue(cmd, opts, :i_message) if git.current_branch == "master" Error "无法将master分支合并到master分支" end name = QCloudHive::GITURLDecoder.new(git.remote.url).name L.debug name project = CodeOA.existProjectByName?(name) if project == nil Error "工程还没有在CodeOA上创建!!#{name}" end begin L.info "#{project.id} #{git.current_branch}" Gitlab.create_merge_request(project.id, message, :source_branch=>git.current_branch, :target_branch=>"master") rescue => err Error "创建失败#{err}" end end def Repo.checkGitStatus(git, tableRows) git.status.changed.each do |path, statu| tableRows << ["", "", statu.type.red, path.red] end git.status.deleted.each do |path, statu| tableRows << ["", "", statu.type.red, path.red] end git.status.added.each do |path, statu| tableRows << ["","", statu.type.red, path.red] end git.status.untracked.each do |path, statu| tableRows << ["", "", "U".red, path.red] end end def Repo.checkStatus(cmd, opts) projectTable = [] Config.manifest.projects.each { |p| projectTable << ["#{p.path}".red, "Branche" ,p.gitRepo.clean? ? "clean".green : "dirty".red] if not p.exsitServer? projectTable << ["", "远端没有该模块,请提交" ] else if not p.exsitPodRepo? projectTable << ["", "", "", "🐝🐝请提交该模块到Pod仓库"] else if p.needReleasePod? projectTable << ["", "", "", "🐝🐝提交该模块的新修改到Pod仓库"] end end # projectTable << [p.moduleName] currentBranch = p.gitRepo.branches[p.gitRepo.current_branch] currentFreature = ProjectFeature.new(p, currentBranch) if currentFreature.remoteBranch.nil? projectTable << ["", currentBranch.full,"", "远端没有该分支,请及时提交到服务器 ⬆️⬆️⬆️⬆️".red] else compareRet = currentFreature.compareRemote if compareRet == 1 projectTable << ["", "","" ,"本地有未同步的修改,请及时提交到服务器 ⬆️⬆️⬆️⬆️".red] elsif compareRet == -1 projectTable << ["", "","" ,"远端有新的修改,请及时Pull⬇️⬇️⬇️".blue] else projectTable << ["", "","" ,""] end compareMaster = currentFreature.compareMaster if compareMaster == 1 projectTable << ["", "","" ,"领先于master分支,请留意进行merge request!!!"] elsif compareMaster == -1 projectTable << ["", "","" ,"落后于master分支有差异,请留意合并master的修改!!!"] end end end checkGitStatus(p.gitRepo, projectTable) projectTable << :separator } table = Terminal::Table.new :rows => projectTable puts table end def Repo.status(git) if git.remotes.count == 0 Error "您没有设置改模块的远端地址,请设置!!!#{path}" end L.debug "#{git.clean?}" changedCount = 0 git.status.each { |statu| tag = nil if statu.type != nil tag = statu.type.red elsif statu.untracked == true tag = "U".red end if tag != nil changedCount += 0 printf "%-60s %s \n", statu.path, tag end } end def Repo.clean?(git) root = Pathname(Config.projectRootDirectory) Config.manifest.projects.each { |p| path = root.join(p.path) begin g = Git.open(path) L.debug "#{g} #{g.clean?}" rescue => err puts "读取git工程失败 #{path} #{err}" end } end def Repo.fackSpec(name) end def Repo.fackSpecContainerPath fackPath = Pathname(Config.projectRootDirectory).join(".fackspec") if not fackPath.exist? fackPath.mkdir end return fackPath.to_path end def Repo.subFackSpec(name, rebuild=true) fackpath = fackSpecContainerPath+"/#{name}" if rebuild == true if Pathname(fackpath).exist? FileUtils.rm_rf(fackpath) end end HiveModule.createLocalModule(name, fackpath) return HiveSpec.new(name, fackpath+"/#{name}.podspec") end def Repo.addChildSpec(parentName, subHiveSpec) faceParentHiveSpec = subFackSpec(parentName) spec = faceParentHiveSpec.podspec subSpec = subHiveSpec.podspec sourceFiles = subSpec.attributes_hash["source_files"] if sourceFiles.is_a?(String) sourceFiles = subHiveSpec.path.parent.join(sourceFiles).to_path end subSpec.source_files = sourceFiles spec.subspec subHiveSpec.name,subSpec faceParentHiveSpec.writeJson end end end