forked from Trustie/forgeplus
fixed 同步增加gitlink同步
This commit is contained in:
parent
112d78f620
commit
a5530a4b90
|
|
@ -24,6 +24,17 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
|||
render :json => response.read_body
|
||||
end
|
||||
|
||||
def gitlink
|
||||
url = URI("https://www.gitlink.org.cn/api/#{params[:owner]}/#{params[:repo]}/branches?access_token=#{params[:token]}&page=#{page}&per_page=#{limit}")
|
||||
https = Net::HTTP.new(url.host, url.port)
|
||||
https.use_ssl = true
|
||||
|
||||
request = Net::HTTP::Get.new(url)
|
||||
# request["Authorization"] = "Bearer #{params[:token]}"
|
||||
response = https.request(request)
|
||||
render :json => response.read_body
|
||||
end
|
||||
|
||||
def index
|
||||
@result_object = Api::V1::Projects::Branches::ListService.call(@project, {name: params[:keyword], state: params[:state], page: page, limit: limit}, current_user&.gitea_token)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -295,6 +295,10 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
end
|
||||
elsif params[:access_token].present?
|
||||
user = User.find_by(gitea_token: params[:access_token])
|
||||
tip_exception(401, "无效token") if user.blank?
|
||||
User.current = user
|
||||
else
|
||||
User.current = find_current_user
|
||||
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ class TouchSyncJob < ApplicationJob
|
|||
def perform(touchable)
|
||||
puts "aaaa"
|
||||
case touchable.class.to_s
|
||||
when 'SyncRepositories::Github' || 'SyncRepositories::Gitee'
|
||||
when 'SyncRepositories::Github' || 'SyncRepositories::Gitee' || 'SyncRepositories::Gitlink'
|
||||
Reposync::SyncRepoService.call(touchable.repo_name)
|
||||
when 'SyncRepositoryBranch'
|
||||
sync_repository = touchable.sync_repository
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -76,7 +76,9 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
|
|||
url = ""
|
||||
if type == "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"
|
||||
else
|
||||
elsif type == "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
|
||||
webhook_params = {
|
||||
|
|
@ -94,6 +96,8 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
|
|||
def repo_name(sync_direction)
|
||||
if type == "SyncRepositories::Gitee"
|
||||
return "gitee:#{project.id}:#{sync_granularity}:#{sync_direction}"
|
||||
elsif type == "SyncRepositories::Gitlink"
|
||||
return "gitlink:#{project.id}:#{sync_granularity}:#{sync_direction}"
|
||||
else
|
||||
return "github:#{project.id}:#{sync_granularity}:#{sync_direction}"
|
||||
end
|
||||
|
|
|
|||
|
|
@ -269,6 +269,7 @@ defaults format: :json do
|
|||
collection do
|
||||
get :gitee
|
||||
get :github
|
||||
get :gitlink
|
||||
get :all
|
||||
post :restore
|
||||
patch :update_default_branch
|
||||
|
|
|
|||
Loading…
Reference in New Issue