ADD 解决ci端用户授权后,项目同步失败的问题
This commit is contained in:
parent
6419453fca
commit
ad43c6975b
|
@ -26,11 +26,17 @@ class Ci::CloudAccountsController < Ci::BaseController
|
||||||
return render_error('请先在指定地址做用户认证') unless @user.ci_certification?
|
return render_error('请先在指定地址做用户认证') unless @user.ci_certification?
|
||||||
|
|
||||||
return render_error('该项目已经激活') if @repo && @repo.repo_active?
|
return render_error('该项目已经激活') if @repo && @repo.repo_active?
|
||||||
|
|
||||||
@cloud_account = Ci::CloudAccount.find params[:id]
|
|
||||||
begin
|
begin
|
||||||
|
@cloud_account = Ci::CloudAccount.find params[:id]
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
repo.activate!(@user.user_id)
|
if @repo
|
||||||
|
return render_error('该项目已经激活') if @repo.repo_active?
|
||||||
|
@repo.activate!(@user.user_id)
|
||||||
|
else
|
||||||
|
@repo = Ci::Repo.auto_create!(@uesr, @project)
|
||||||
|
@user.update_column(:user_syncing, false)
|
||||||
|
end
|
||||||
|
|
||||||
result = bind_hook!(@user, @cloud_account, @repo)
|
result = bind_hook!(@user, @cloud_account, @repo)
|
||||||
@project.update_columns(open_devops: true, gitea_webhook_id: result['id'])
|
@project.update_columns(open_devops: true, gitea_webhook_id: result['id'])
|
||||||
@cloud_account.update_column(:ci_user_id, @user.user_id)
|
@cloud_account.update_column(:ci_user_id, @user.user_id)
|
||||||
|
|
|
@ -3,4 +3,18 @@ class Ci::Perm < Ci::RemoteBase
|
||||||
|
|
||||||
belongs_to :user, class_name: 'Ci::User', foreign_key: :perm_user_id
|
belongs_to :user, class_name: 'Ci::User', foreign_key: :perm_user_id
|
||||||
belongs_to :repo, class_name: 'Ci::Repo', foreign_key: :perm_repo_uid
|
belongs_to :repo, class_name: 'Ci::Repo', foreign_key: :perm_repo_uid
|
||||||
|
|
||||||
|
def self.auto_create!(user, repo)
|
||||||
|
perm = new(
|
||||||
|
perm_user_id: user.user_id,
|
||||||
|
perm_repo_uid: repo.repo_id,
|
||||||
|
perm_read: true,
|
||||||
|
perm_write: true,
|
||||||
|
perm_admin: true,
|
||||||
|
perm_synced: 0,
|
||||||
|
perm_created: Time.now.to_i,
|
||||||
|
perm_updated: Time.now.to_i
|
||||||
|
)
|
||||||
|
perm.save!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,7 +11,7 @@ class Ci::Repo < Ci::RemoteBase
|
||||||
user = Ci::User.find_by_user_login namespace_path
|
user = Ci::User.find_by_user_login namespace_path
|
||||||
repo = Ci::Repo.where(repo_namespace: namespace_path, repo_name: identifier).first
|
repo = Ci::Repo.where(repo_namespace: namespace_path, repo_name: identifier).first
|
||||||
|
|
||||||
(user.blank? || repo.blank?) ? nil : [user, repo]
|
[user, repo]
|
||||||
end
|
end
|
||||||
|
|
||||||
def activate!(ci_user_id)
|
def activate!(ci_user_id)
|
||||||
|
@ -24,4 +24,32 @@ class Ci::Repo < Ci::RemoteBase
|
||||||
repo_updated: Time.now.to_i)
|
repo_updated: Time.now.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.auto_create!(user, project)
|
||||||
|
repo = new(
|
||||||
|
repo_user_id: user.user_id,
|
||||||
|
repo_namespace: project.owner.login,
|
||||||
|
repo_name: project.identifier,
|
||||||
|
repo_slug: "#{project.owner.login}/#{project.identifier}",
|
||||||
|
repo_clone_url: project.repository.url,
|
||||||
|
repo_active: 1,
|
||||||
|
repo_private: true,
|
||||||
|
repo_visibility: 'private',
|
||||||
|
repo_branch: 'master',
|
||||||
|
repo_counter: 0,
|
||||||
|
repo_trusted: false,
|
||||||
|
repo_protected: false,
|
||||||
|
repo_synced: 0,
|
||||||
|
repo_version: 1,
|
||||||
|
repo_signer: generate_code,
|
||||||
|
repo_secret: generate_code,
|
||||||
|
repo_timeout: 60,
|
||||||
|
repo_config: '.trustie-pipeline.yml',
|
||||||
|
repo_created: Time.now.to_i,
|
||||||
|
repo_updated: Time.now.to_i
|
||||||
|
)
|
||||||
|
if repo.save!
|
||||||
|
Ci::Perm.auto_create!(user, repo)
|
||||||
|
repo
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue