新增:同步时间和创建数据返回

This commit is contained in:
yystopf 2024-04-16 17:53:35 +08:00
parent e358e3b6f6
commit 7271603248
6 changed files with 15 additions and 5 deletions

View File

@ -2,7 +2,7 @@ class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController
before_action :require_public_and_member_above
def create
@sync_repositories = Api::V1::Projects::SyncRepositories::CreateService.call(@project, sync_repository_params)
@sync_repository1, @sync_repository2, @sync_repository_branch1, @sync_repository_branch2 = Api::V1::Projects::SyncRepositories::CreateService.call(@project, sync_repository_params)
end
def sync
@ -18,7 +18,7 @@ class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController
private
def sync_repository_params
param.permit(:type, :external_token, :external_repo_address, :sync_granularity, :external_branch_name, :gitlink_branch_name, :first_sync_direction)
params.permit(:type, :external_token, :external_repo_address, :sync_granularity, :external_branch_name, :gitlink_branch_name, :first_sync_direction)
end
end

View File

@ -15,9 +15,9 @@ class TouchSyncJob < ApplicationJob
result = Reposync::SyncBranchService.call(sync_repository.repo_name, touchable.external_branch_name, sync_repository.sync_direction)
end
if result.is_a?(Array)
touchable.update_column(:sync_status, 1)
touchable.update_attributes!({sync_status: 1, sync_time: Time.now})
else
touchable.update_column(:sync_status, 2)
touchable.update_attributes!({sync_status: 2, sync_time: Time.now})
end
end
end

View File

@ -20,6 +20,7 @@
class SyncRepository < ApplicationRecord
belongs_to :project
has_many :sync_repository_branches, dependent: :destroy
validates :repo_name, uniqueness: { message: "已存在" }
end

View File

@ -20,4 +20,6 @@
class SyncRepositoryBranch < ApplicationRecord
belongs_to :sync_repository
enum sync_status: {success: 1, failure: 2}
end

View File

@ -3,7 +3,7 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
include ActiveModel::Model
attr_reader :project, :type, :external_token, :external_repo_address, :sync_granularity, :external_branch_name, :gitlink_branch_name, :first_sync_direction
attr_accessor :sync_repository1, :sync_repository2
attr_accessor :sync_repository1, :sync_repository2, :sync_repository_branch1, :sync_repository_branch2
validates :type, inclusion: {in: %w(SyncRepositories::Gitee SyncRepositories::Github)}
validates :external_repo_address, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" }
@ -36,6 +36,8 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
touch_first_sync
end
create_webhook
[@sync_repository1, @sync_repository2, @sync_repository_branch1, @sync_repository_branch2]
end
def check_gitlink_branch_name

View File

@ -0,0 +1,5 @@
json.gitlink_repo_address "#{EduSetting.get("gitlink_repo_domain")}/#{@project.owner&.login}/#{@project.identifier}.git"
json.external_repo_address @sync_repository1.external_repo_address
json.sync_granularity @sync_repository1.sync_granularity
json.gitlink_branch_name @sync_repository_branch1.gitlink_branch_name
json.external_branch_name @sync_repository_branch1.external_branch_name