require 'gitlab' require 'singleton' require_relative "config.rb" require_relative "utils.rb" module QCloudHive module CodeOA def CodeOA.setup(token) Gitlab.endpoint = "http://git.code.oa.com/api/v3" Gitlab.private_token = token end def CodeOA.exist?(projectName) project = existProjectByName?(projectName) L.debug "project #{project}" if project != nil return true else return false end end def CodeOA.branch(project, name) begin Gitlab.branch(project, name) rescue Gitlab::Error::NotFound return nil end end def CodeOA.existProjectByName?(projectName) projects = Gitlab.project_search(projectName) L.info "所有项目 #{projects.count}" aimProjects = projects.select{ |p| L.debug "#{projectName} #{p.name} #{p.namespace.path} #{Config.team}" p.name == projectName && p.namespace.path == Config.team } if aimProjects.count > 0 return aimProjects.first else return nil end end def CodeOA.createProject(projectName) project = CodeOA.existProjectByName?(projectName) if project != nil puts ("#{name}已经在CodeOA上存在,将不会在git.code.oa.com上再次新建改项目") return project else Gitlab.create_project(projectName, { :description => "#{projectName}的仓库", :namespace_id => Config.namespaceID }) CodeOA.existProjectByName?(projectName) end end def CodeOA.branchs(project) Gitlab.branches(project.id) end def CodeOA.empty?(project) if Gitlab.branches(project.id).count == 0 true else false end end end end