Merge branch 'standalone_develop' into pre_trustie_server
This commit is contained in:
commit
697f022ab1
|
@ -1,6 +1,29 @@
|
||||||
class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
||||||
before_action :require_public_and_member_above, only: [:index, :all]
|
before_action :require_public_and_member_above, only: [:index, :all]
|
||||||
|
|
||||||
|
def gitee
|
||||||
|
url = URI("https://gitee.com/api/v5/repos/#{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)
|
||||||
|
response = https.request(request)
|
||||||
|
render :json => response.read_body
|
||||||
|
end
|
||||||
|
|
||||||
|
def github
|
||||||
|
url = URI("https://api.github.com/repos/#{params[:owner]}/#{params[:repo]}/branches?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]}"
|
||||||
|
request["Accept"] = "application/vnd.github+json"
|
||||||
|
request["X-GitHub-Api-Version"] = "2022-11-28"
|
||||||
|
|
||||||
|
response = https.request(request)
|
||||||
|
render :json => response.read_body
|
||||||
|
end
|
||||||
|
|
||||||
def index
|
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)
|
@result_object = Api::V1::Projects::Branches::ListService.call(@project, {name: params[:keyword], state: params[:state], page: page, limit: limit}, current_user&.gitea_token)
|
||||||
end
|
end
|
||||||
|
|
|
@ -112,7 +112,7 @@ class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController
|
||||||
@group_sync_repository_branch = @sync_repository_branches.joins(:sync_repository).group("sync_repositories.type, sync_repository_branches.gitlink_branch_name, sync_repository_branches.external_branch_name").select("sync_repositories.type as type,max(sync_repository_branches.updated_at) as updated_at, sync_repository_branches.gitlink_branch_name, sync_repository_branches.external_branch_name").sort_by{|i|i.updated_at}
|
@group_sync_repository_branch = @sync_repository_branches.joins(:sync_repository).group("sync_repositories.type, sync_repository_branches.gitlink_branch_name, sync_repository_branches.external_branch_name").select("sync_repositories.type as type,max(sync_repository_branches.updated_at) as updated_at, sync_repository_branches.gitlink_branch_name, sync_repository_branches.external_branch_name").sort_by{|i|i.updated_at}
|
||||||
@each_json = []
|
@each_json = []
|
||||||
@group_sync_repository_branch.each do |item|
|
@group_sync_repository_branch.each do |item|
|
||||||
branches = @sync_repository_branches.joins(:sync_repository).where(sync_repositories: {type: item.type}, gitlink_branch_name: item.gitlink_branch_name, external_branch_name: item.external_branch_name).order(updated_at: :desc)
|
branches = @sync_repository_branches.joins(:sync_repository).where(sync_repositories: {type: item.type}, gitlink_branch_name: item.gitlink_branch_name, external_branch_name: item.external_branch_name).order(sync_time: :desc)
|
||||||
branch = branches.first
|
branch = branches.first
|
||||||
@each_json << {
|
@each_json << {
|
||||||
gitlink_branch_name: item.gitlink_branch_name,
|
gitlink_branch_name: item.gitlink_branch_name,
|
||||||
|
|
|
@ -8,7 +8,7 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
|
||||||
validates :type, inclusion: {in: %w(SyncRepositories::Gitee SyncRepositories::Github)}
|
validates :type, inclusion: {in: %w(SyncRepositories::Gitee SyncRepositories::Github)}
|
||||||
validates :external_repo_address, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" }
|
validates :external_repo_address, format: { with: CustomRegexp::URL_REGEX, multiline: true, message: "地址格式不正确" }
|
||||||
validates :sync_granularity, :first_sync_direction, inclusion: {in: [1,2]}
|
validates :sync_granularity, :first_sync_direction, inclusion: {in: [1,2]}
|
||||||
validate :check_gitlink_branch_name
|
# validate :check_gitlink_branch_name
|
||||||
|
|
||||||
def initialize(project, params)
|
def initialize(project, params)
|
||||||
@project = project
|
@project = project
|
||||||
|
@ -40,12 +40,12 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
|
||||||
[@sync_repository1, @sync_repository2, @sync_repository_branch1, @sync_repository_branch2]
|
[@sync_repository1, @sync_repository2, @sync_repository_branch1, @sync_repository_branch2]
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_gitlink_branch_name
|
# def check_gitlink_branch_name
|
||||||
if sync_granularity == 2
|
# if sync_granularity == 2
|
||||||
result = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(project&.owner&.login, project&.identifier) rescue nil
|
# result = $gitea_hat_client.get_repos_branch_name_set_by_owner_repo(project&.owner&.login, project&.identifier) rescue nil
|
||||||
raise Error, '分支不存在' if !result.include?(gitlink_branch_name)
|
# raise Error, '分支不存在' if !result.include?(gitlink_branch_name)
|
||||||
end
|
# end
|
||||||
end
|
# end
|
||||||
|
|
||||||
private
|
private
|
||||||
def create_sync_repository
|
def create_sync_repository
|
||||||
|
|
|
@ -118,6 +118,8 @@ defaults format: :json do
|
||||||
end
|
end
|
||||||
resources :branches, param: :name, only:[:index, :create, :destroy] do
|
resources :branches, param: :name, only:[:index, :create, :destroy] do
|
||||||
collection do
|
collection do
|
||||||
|
get :gitee
|
||||||
|
get :github
|
||||||
get :all
|
get :all
|
||||||
post :restore
|
post :restore
|
||||||
patch :update_default_branch
|
patch :update_default_branch
|
||||||
|
|
|
@ -11,7 +11,7 @@ class CreateActionNodeSelects < ActiveRecord::Migration[5.2]
|
||||||
t.integer :use_count, default: 0
|
t.integer :use_count, default: 0
|
||||||
t.references :user
|
t.references :user
|
||||||
t.timestamps
|
t.timestamps
|
||||||
t.index :name
|
t.index :name, length: 191
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue