From 16c31e254e5f21a9f63be6c149b90964d886bb9e Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 11 Nov 2015 15:33:43 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=8C=BA=E5=88=86Gitlab=E5=85=AC=E5=BC=80?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=92=8C=E7=A7=81=E6=9C=89=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/trustie/gitlab/sync.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/trustie/gitlab/sync.rb b/lib/trustie/gitlab/sync.rb index a303b22fb..ac01a44ec 100644 --- a/lib/trustie/gitlab/sync.rb +++ b/lib/trustie/gitlab/sync.rb @@ -10,6 +10,9 @@ module Trustie DEVELOPER = 30 MASTER = 40 OWNER = 50 + # 项目公开和私有 + PUBLIC = 20 + PRIVATE = 0 end class Sync @@ -45,7 +48,8 @@ module Trustie issues_enabled: false, snippets_enabled: false, public: false, - user_id: gid + user_id: gid, + visibility_level: project.is_public? ? UserLevel::PUBLIC : UserLevel::PRIVATE ) project.gpid = gproject.id project.save! @@ -84,7 +88,8 @@ module Trustie merge_requests_enabled: true, public: false, user_id: gid, - import_url: import_url + import_url: import_url, + visibility_level: project.is_public? ? UserLevel::PUBLIC : UserLevel::PRIVATE ) puts "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%" project.gpid = gproject.id From 3aa73fba35712f916d3e2e1d56886648d371295e Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 11 Nov 2015 16:33:09 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Gitlab=E6=9D=83=E9=99=90=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=20=E6=9B=B4=E6=96=B0=E9=A1=B9=E7=9B=AEGitlab=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 9 +++++++++ lib/gitlab-cli/lib/gitlab/client/projects.rb | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index d26e465ba..58dea46b7 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -607,6 +607,15 @@ class ProjectsController < ApplicationController @project.organization_id = params[:organization_id] params[:project][:is_public] ? @project.is_public = 1 : @project.is_public = 0 params[:project][:hidden_repo] ? @project.hidden_repo = 1 : @project.hidden_repo = 0 + # 更新公开私有时同步gitlab公开私有 + g = Gitlab.client + gproject = g.project(@project.gpid) + if params[:project][:is_public] + g.edit_project(gproject.id, 20) + else + g.edit_project(gproject.id, 0) + end + # end if validate_parent_id && @project.save @project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id') if params[:project][:is_public] == '0' diff --git a/lib/gitlab-cli/lib/gitlab/client/projects.rb b/lib/gitlab-cli/lib/gitlab/client/projects.rb index 04ea682aa..6247294f3 100644 --- a/lib/gitlab-cli/lib/gitlab/client/projects.rb +++ b/lib/gitlab-cli/lib/gitlab/client/projects.rb @@ -72,6 +72,23 @@ class Gitlab::Client post(url, :body => {:name => name}.merge(options)) end + # Updates a project team member to a specified access level. + # id (required) - The ID of a project + # name (optional) - project name + # path (optional) - repository name for project + # description (optional) - short project description + # default_branch (optional) + # issues_enabled (optional) + # merge_requests_enabled (optional) + # wiki_enabled (optional) + # snippets_enabled (optional) + # public (optional) - if true same as setting visibility_level = 20 + # visibility_level (optional) + + def edit_project(id, visibility_level) + put("/projects/#{id}", :body => {:visibility_level => visibility_level}) + end + # Deletes a project. # # @example From 2596f0a78844af5dbbaec1031be71610884a3f5f Mon Sep 17 00:00:00 2001 From: huang Date: Wed, 11 Nov 2015 16:39:05 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9D=83=E9=99=90?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 58dea46b7..065adf596 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -608,12 +608,10 @@ class ProjectsController < ApplicationController params[:project][:is_public] ? @project.is_public = 1 : @project.is_public = 0 params[:project][:hidden_repo] ? @project.hidden_repo = 1 : @project.hidden_repo = 0 # 更新公开私有时同步gitlab公开私有 - g = Gitlab.client - gproject = g.project(@project.gpid) - if params[:project][:is_public] - g.edit_project(gproject.id, 20) - else - g.edit_project(gproject.id, 0) + unless @project.gpid.nil? + g = Gitlab.client + gproject = g.project(@project.gpid) + params[:project][:is_public] ? g.edit_project(gproject.id, 20) : g.edit_project(gproject.id, 0) end # end if validate_parent_id && @project.save