Browse Source

Merge branch 'standalone_develop' into pre_trustie_server

pull/345/head
yystopf 2 years ago
parent
commit
697f022ab1
5 changed files with 34 additions and 9 deletions
  1. +23
    -0
      app/controllers/api/v1/projects/branches_controller.rb
  2. +1
    -1
      app/controllers/api/v1/projects/sync_repositories_controller.rb
  3. +7
    -7
      app/services/api/v1/projects/sync_repositories/create_service.rb
  4. +2
    -0
      config/routes/api.rb
  5. +1
    -1
      db/migrate/20240408010213_create_action_node_selects.rb

+ 23
- 0
app/controllers/api/v1/projects/branches_controller.rb 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


+ 1
- 1
app/controllers/api/v1/projects/sync_repositories_controller.rb 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,


+ 7
- 7
app/services/api/v1/projects/sync_repositories/create_service.rb 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


+ 2
- 0
config/routes/api.rb 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


+ 1
- 1
db/migrate/20240408010213_create_action_node_selects.rb 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

Loading…
Cancel
Save