Sha256: ab957bacde7a289332bf7809bc3fb585f6edd5360bfa94092e285df4839910c5

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
qcloudhive-0.1.0 lib/qcloudhive/gitlab.rb