Merge branch 'pre_trustie_server' into trustie_server

This commit is contained in:
yystopf 2024-05-15 16:22:33 +08:00
commit 35378c3a04
5 changed files with 34 additions and 9 deletions

View File

@ -1,6 +1,29 @@
class Api::V1::Projects::BranchesController < Api::V1::BaseController
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
@result_object = Api::V1::Projects::Branches::ListService.call(@project, {name: params[:keyword], state: params[:state], page: page, limit: limit}, current_user&.gitea_token)
end

View File

@ -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}
@each_json = []
@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
@each_json << {
gitlink_branch_name: item.gitlink_branch_name,

View File

@ -8,7 +8,7 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
validates :type, inclusion: {in: %w(SyncRepositories::Gitee SyncRepositories::Github)}
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
# validate :check_gitlink_branch_name
def initialize(project, params)
@project = project
@ -40,12 +40,12 @@ class Api::V1::Projects::SyncRepositories::CreateService < ApplicationService
[@sync_repository1, @sync_repository2, @sync_repository_branch1, @sync_repository_branch2]
end
def check_gitlink_branch_name
if sync_granularity == 2
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)
end
end
# def check_gitlink_branch_name
# if sync_granularity == 2
# 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)
# end
# end
private
def create_sync_repository

View File

@ -118,6 +118,8 @@ defaults format: :json do
end
resources :branches, param: :name, only:[:index, :create, :destroy] do
collection do
get :gitee
get :github
get :all
post :restore
patch :update_default_branch

View File

@ -11,7 +11,7 @@ class CreateActionNodeSelects < ActiveRecord::Migration[5.2]
t.integer :use_count, default: 0
t.references :user
t.timestamps
t.index :name
t.index :name, length: 191
end
end
end