From c5f6f5884f0eda603e5994f6fc54381af812e4fb Mon Sep 17 00:00:00 2001 From: nwb Date: Wed, 23 Jul 2014 11:15:09 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=9B=E5=BB=BA=E7=89=88?= =?UTF-8?q?=E6=9C=AC=E5=BA=93=E6=9B=BF=E6=8D=A2=E6=88=90gitlab=E6=A8=A1?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 23 +++++++++++++++++++++- app/helpers/gitlab_helper.rb | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 7588eef21..dc05ce500 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -39,6 +39,7 @@ class RepositoriesController < ApplicationController before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ] helper :repositories include RepositoriesHelper + include GitlabHelper #@root_path = RepositoriesHelper::ROOT_PATH @@ -91,10 +92,30 @@ class RepositoriesController < ApplicationController render :action => 'show', :layout => 'base_projects' end + # 创建git版本库 def create - if params[:repository_scm].to_s == 'Gitlab' + if params[:repository_scm].to_s == 'Git' # add by nwb # 增加对gitlab版本库的支持 + # 判断gitlab用户是否存在,不存在则创建 + user = User.current + gitlab_user = GitlabUser.find_by_user_id(user.id) + if gitlab_user.nil? + if create_user(user.login,user.show_name,user.password,user.mail,user.id) + else + # 创建gitlab用户失败 + # 返回可自定义用户创建gitlab的界面 + end + end + # 创建gitlab版本库 + repos = params[:repository][:identifier] + if create_project_for_user(repos,@project.id,gitlab_user.gitlab_user_id) + # 创建成功 + else + # 创建gitlab项目失败 + end + + # 连接创建成功后的gitlab版本库 attrs = pickup_extra_info @repository = Repository.factory('Git') @repository.safe_attributes = params[:repository] diff --git a/app/helpers/gitlab_helper.rb b/app/helpers/gitlab_helper.rb index f70c20894..4b3f753b7 100644 --- a/app/helpers/gitlab_helper.rb +++ b/app/helpers/gitlab_helper.rb @@ -89,8 +89,9 @@ module GitlabHelper # 为指定用户创建版本库 # project_name:版本库名称 user_id:Gitlab版本库中的用户编号 + # project_id: 项目在trustie中的编号 # add by nwb - def create_project_for_user(project_name,user_id) + def create_project_for_user(project_name,project_id,user_id) url = REPO_IP_ADDRESS + GITLAB_API + "/projects/user/" + user_id uri = URI.parse(url) data = {user_id:user_id, name:project_name,private_token:GitlabHelper.gitlab_token}