FIX 优化ci初始化流程
This commit is contained in:
parent
b26c2f273f
commit
b75896821f
|
@ -15,7 +15,7 @@ class Ci::CloudAccountsController < Ci::BaseController
|
|||
if current_user&.ci_cloud_account.present?
|
||||
return render_error('该仓库已绑定了云帐号.')
|
||||
else
|
||||
cloud_account = Ci::CloudAccount.new(create_params.merge(project_id: @project.id))
|
||||
cloud_account = Ci::CloudAccount.new(create_params)
|
||||
cloud_account.user = current_user
|
||||
cloud_account.save!
|
||||
end
|
||||
|
@ -63,23 +63,18 @@ class Ci::CloudAccountsController < Ci::BaseController
|
|||
end
|
||||
|
||||
def activate
|
||||
result =
|
||||
if current_user.devops_has_token?
|
||||
# 已有drone_token的,直接激活项目
|
||||
Ci::Drone::API.new(@cloud_account.drone_token, @cloud_account.drone_url, @project.owner.login, @project.identifier).activate
|
||||
else
|
||||
# 没有token,说明是第一次激活devops, 需要用户填写token值
|
||||
return render_error('请先在CI服务端做用户认证.') if !current_user.devops_verified?
|
||||
Ci::Drone::API.new(params[:drone_token], @cloud_account.drone_url, @project.owner.login, @project.identifier).activate
|
||||
end
|
||||
return render_error('请先在指定地址做用户认证') unless current_user.ci_certification?
|
||||
|
||||
if result
|
||||
set_drone_token!(current_user, @cloud_account, params[:drone_token])
|
||||
return render_error('该项目已经激活') if @repo.repo_active?
|
||||
|
||||
ci_user = Ci::User.find_by(user_login: current_user.login)
|
||||
begin
|
||||
@repo.activate!
|
||||
@project.update_column(:open_devops, true)
|
||||
@repo.config_trustie_pipeline
|
||||
@cloud_account.update_column(ci_user_id: ci_user.user_id)
|
||||
render_ok
|
||||
else
|
||||
render_error("激活失败,请检查你的token值是否正确.")
|
||||
rescue Exception => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ class Ci::ProjectsController < Ci::BaseController
|
|||
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, params[:owner], params.merge(identifier: @project.identifier))
|
||||
if interactor.success?
|
||||
@file = interactor.result
|
||||
@repo.config_trustie_pipeline
|
||||
render_result(1, "更新成功")
|
||||
else
|
||||
render_error(interactor.error)
|
||||
|
|
|
@ -16,13 +16,12 @@ class Ci::Repo < Ci::RemoteBase
|
|||
[user, repo]
|
||||
end
|
||||
|
||||
def config_trustie_pipeline
|
||||
update_column(:repo_config, '.trustie-pipeline.yml')
|
||||
end
|
||||
|
||||
def activate
|
||||
# repo_active、repo_signer、repo_secret、repo_updated
|
||||
update_columns(repo_active: 1, repo_signer: generate_code, repo_secret: generate_code, repo_updated: Time.now.to_i)
|
||||
def activate!
|
||||
update_columns(repo_active: 1,
|
||||
repo_signer: generate_code,
|
||||
repo_secret: generate_code,
|
||||
repo_config: '.trustie-pipeline.yml',
|
||||
repo_updated: Time.now.to_i)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -12,18 +12,14 @@ module Droneable
|
|||
self.devops_step === User::DEVOPS_UNVERIFIED
|
||||
end
|
||||
|
||||
def devops_verified?
|
||||
self.devops_step === User::DEVOPS_VERIFIED
|
||||
end
|
||||
|
||||
def devops_has_token?
|
||||
self.devops_step === User::DEVOPS_HAS_TOKEN
|
||||
end
|
||||
|
||||
def set_drone_step!(step)
|
||||
self.update_column(:devops_step, step)
|
||||
end
|
||||
|
||||
def ci_certification?
|
||||
Ci::User.exists?(user_login: self.login)
|
||||
end
|
||||
|
||||
module ClassMethods
|
||||
end
|
||||
end
|
||||
|
|
|
@ -10,11 +10,9 @@ class User < ApplicationRecord
|
|||
# include Searchable::Dependents::User
|
||||
|
||||
# devops step
|
||||
# devops_step column: 0: 未填写服务器信息;1: 已填写服务器信息(未认证); 2: 已认证, 3: 已填写token值
|
||||
# devops_step column: 0: 未填写服务器信息;1: 已填写服务器信息(未认证);
|
||||
DEVOPS_UNINIT = 0
|
||||
DEVOPS_UNVERIFIED = 1
|
||||
DEVOPS_VERIFIED = 2
|
||||
DEVOPS_HAS_TOKEN = 3
|
||||
|
||||
# Account statuses
|
||||
STATUS_ANONYMOUS = 0
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddCiUserIdToCiCloudAccounts < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :ci_cloud_accounts, :ci_user_id, :integer
|
||||
end
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
class RemoveProjectIdFromCiCloudAccounts < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
remove_column :ci_cloud_accounts, :project_id
|
||||
remove_column :ci_cloud_accounts, :repo_id
|
||||
remove_column :ci_cloud_accounts, :drone_token
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue