forked from Trustie/forgeplus
新增:gitlink双向同步
This commit is contained in:
parent
112d78f620
commit
39e7eded22
|
|
@ -0,0 +1,24 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: sync_repositories
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# project_id :integer
|
||||
# type :string(255)
|
||||
# repo_name :string(255)
|
||||
# external_repo_address :string(255)
|
||||
# sync_granularity :integer
|
||||
# sync_direction :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# external_token :string(255)
|
||||
# webhook_gid :integer
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_sync_repositories_on_project_id (project_id)
|
||||
#
|
||||
|
||||
class SyncRepositories::Gitlink < SyncRepository
|
||||
|
||||
end
|
||||
|
|
@ -5,7 +5,7 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
|
|||
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, :sync_repository_branch1, :sync_repository_branch2, :gitea_webhook
|
||||
|
||||
validates :type, inclusion: {in: %w(SyncRepositories::Gitee SyncRepositories::Github)}
|
||||
validates :type, inclusion: {in: %w(SyncRepositories::Gitee SyncRepositories::Github SyncRepositories::Gitlink)}
|
||||
validates :external_repo_address, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" }
|
||||
validates :sync_granularity, :first_sync_direction, inclusion: {in: [1,2]}
|
||||
# validate :check_gitlink_branch_name
|
||||
|
|
@ -74,8 +74,11 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
|
|||
|
||||
def create_webhook
|
||||
url = ""
|
||||
if type == "SyncRepositories::Gitee"
|
||||
case type
|
||||
when 'SyncRepositories::Gitee'
|
||||
url = "#{Rails.application.config_for(:configuration)['platform_url']}/api/v1/#{project&.owner&.login}/#{project&.identifier}/sync_repositories/sync?sync_direction=1&repo_type=SyncRepositories::Gitee"
|
||||
when 'SyncRepositories::Gitlink'
|
||||
url = "#{Rails.application.config_for(:configuration)['platform_url']}/api/v1/#{project&.owner&.login}/#{project&.identifier}/sync_repositories/sync?sync_direction=1&repo_type=SyncRepositories::Gitlink"
|
||||
else
|
||||
url = "#{Rails.application.config_for(:configuration)['platform_url']}/api/v1/#{project&.owner&.login}/#{project&.identifier}/sync_repositories/sync?sync_direction=1&repo_type=SyncRepositories::Github"
|
||||
end
|
||||
|
|
@ -92,8 +95,11 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
|
|||
end
|
||||
|
||||
def repo_name(sync_direction)
|
||||
if type == "SyncRepositories::Gitee"
|
||||
case type
|
||||
when 'SyncRepositories::Gitee'
|
||||
return "gitee:#{project.id}:#{sync_granularity}:#{sync_direction}"
|
||||
when 'SyncRepositories::Gitlink'
|
||||
return "gitlink:#{project.id}:#{sync_granularity}:#{sync_direction}"
|
||||
else
|
||||
return "github:#{project.id}:#{sync_granularity}:#{sync_direction}"
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in New Issue