Merge branch 'standalone_develop' into pm_project_develop
This commit is contained in:
commit
e812f07a14
2
Gemfile
2
Gemfile
|
@ -141,4 +141,4 @@ gem 'doorkeeper'
|
||||||
|
|
||||||
gem 'doorkeeper-jwt'
|
gem 'doorkeeper-jwt'
|
||||||
|
|
||||||
gem 'gitea-client', '~> 1.4.6'
|
gem 'gitea-client', '~> 1.5.7'
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
class Api::V1::GitlinkCompetitionAppliesController < Api::V1::BaseController
|
||||||
|
|
||||||
|
def create
|
||||||
|
return render_error("请输入正确的竞赛ID") unless params[:competition_id].present?
|
||||||
|
return render_error("请输入正确的队伍ID") unless params[:team_id].present?
|
||||||
|
return render_error("请输入正确的队伍成员信息") unless params[:team_members].is_a?(Array)
|
||||||
|
params[:team_members].each do |member|
|
||||||
|
apply = GitlinkCompetitionApply.find_or_create_by(competition_id: params[:competition_id], team_id: params[:team_id], educoder_login: member[:login])
|
||||||
|
apply.competition_identifier = params[:competition_identifier]
|
||||||
|
apply.team_name = params[:team_name]
|
||||||
|
apply.school_name = member[:school_name]
|
||||||
|
apply.nickname = member[:nickname]
|
||||||
|
apply.identity = member[:identity]
|
||||||
|
apply.role = member[:role]
|
||||||
|
apply.email = member[:email]
|
||||||
|
user_info = get_user_info_by_educoder_login(member[:login])
|
||||||
|
apply.phone = user_info["phone"]
|
||||||
|
apply.save
|
||||||
|
end
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_user_info_by_educoder_login(edu_login)
|
||||||
|
req_params = { "login" => "#{edu_login}", "private_token" => "hriEn3UwXfJs3PmyXnqQ" }
|
||||||
|
api_url= "https://data.educoder.net"
|
||||||
|
client = Faraday.new(url: api_url)
|
||||||
|
response = client.public_send("get", "/api/sources/get_user_info_by_login", req_params)
|
||||||
|
result = JSON.parse(response.body)
|
||||||
|
|
||||||
|
return nil if result["status"].to_s != "0"
|
||||||
|
|
||||||
|
# login 邮箱 手机号 姓名 学校/单位
|
||||||
|
user_info = result["data"]
|
||||||
|
|
||||||
|
return user_info
|
||||||
|
end
|
||||||
|
end
|
|
@ -5,8 +5,42 @@ class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::B
|
||||||
puts @result_object
|
puts @result_object
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def rerun
|
||||||
|
return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank?
|
||||||
|
gitea_result = $gitea_hat_client.post_repos_actions_runs_rerun_by_owner_repo_run(@project&.owner&.login, @project&.identifier, params[:run_id]) rescue nil
|
||||||
|
if gitea_result
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("重启所有流水线任务失败")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def job_rerun
|
||||||
|
return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank?
|
||||||
|
return render_error("请输入正确的流水线任务ID") if params[:job].blank?
|
||||||
|
gitea_result = $gitea_hat_client.post_repos_actions_runs_jobs_rerun_by_owner_repo_run_job(@project&.owner&.login, @project&.identifier, params[:run_id], params[:job]) rescue nil
|
||||||
|
if gitea_result
|
||||||
|
render_ok
|
||||||
|
else
|
||||||
|
render_error("重启流水线任务失败")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def job_show
|
def job_show
|
||||||
@result_object = Api::V1::Projects::Actions::Runs::JobShowService.call(@project, params[:run_id], params[:job], params[:log_cursors], current_user&.gitea_token)
|
@result_object = Api::V1::Projects::Actions::Runs::JobShowService.call(@project, params[:run_id], params[:job], params[:log_cursors], current_user&.gitea_token)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def job_logs
|
||||||
|
return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank?
|
||||||
|
return render_error("请输入正确的流水线任务ID") if params[:job].blank?
|
||||||
|
domain = GiteaService.gitea_config[:domain]
|
||||||
|
api_url = GiteaService.gitea_config[:hat_base_url]
|
||||||
|
|
||||||
|
url = "/repos/#{@owner.login}/#{@repository.identifier}/actions/runs/#{CGI.escape(params[:run_id])}/jobs/#{CGI.escape(params[:job])}/logs"
|
||||||
|
file_path = [domain, api_url, url].join
|
||||||
|
file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("?")
|
||||||
|
|
||||||
|
redirect_to file_path
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
|
@ -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,
|
||||||
|
|
|
@ -157,6 +157,7 @@ module RepositoriesHelper
|
||||||
ext = File.extname(s_content)[1..-1]
|
ext = File.extname(s_content)[1..-1]
|
||||||
ext = ext.split("?")[0] if ext.include?("?")
|
ext = ext.split("?")[0] if ext.include?("?")
|
||||||
if (image_type?(ext) || download_type(ext)) && !ext.blank?
|
if (image_type?(ext) || download_type(ext)) && !ext.blank?
|
||||||
|
s_content = s_content.starts_with?("/") ? s_content[1..-1] : s_content[0..-1]
|
||||||
s_content = File.expand_path(s_content, file_path)
|
s_content = File.expand_path(s_content, file_path)
|
||||||
s_content = s_content.split("#{Rails.root}/")[1]
|
s_content = s_content.split("#{Rails.root}/")[1]
|
||||||
# content = content.gsub(s[0], "/#{s_content}")
|
# content = content.gsub(s[0], "/#{s_content}")
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: gitlink_competition_applies
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# competition_id :integer
|
||||||
|
# competition_identifier :string(255)
|
||||||
|
# team_id :integer
|
||||||
|
# team_name :string(255)
|
||||||
|
# school_name :string(255)
|
||||||
|
# login :string(255)
|
||||||
|
# nickname :string(255)
|
||||||
|
# phone :string(255)
|
||||||
|
# identity :string(255)
|
||||||
|
# role :string(255)
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
#
|
||||||
|
|
||||||
|
class GitlinkCompetitionApply < ApplicationRecord
|
||||||
|
end
|
|
@ -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
|
||||||
|
|
|
@ -126,6 +126,9 @@ defaults format: :json do
|
||||||
post :enable
|
post :enable
|
||||||
resources :runs, only: [:index] do
|
resources :runs, only: [:index] do
|
||||||
post '/jobs/:job', to: 'runs#job_show'
|
post '/jobs/:job', to: 'runs#job_show'
|
||||||
|
post '/rerun', to: 'runs#rerun'
|
||||||
|
post '/jobs/:job/rerun', to: 'runs#job_rerun'
|
||||||
|
get '/jobs/:job/logs', to: 'runs#job_logs'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -152,6 +155,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
|
||||||
|
@ -191,6 +196,7 @@ defaults format: :json do
|
||||||
resources :projects, only: [:index]
|
resources :projects, only: [:index]
|
||||||
resources :project_topics, only: [:index, :create, :destroy]
|
resources :project_topics, only: [:index, :create, :destroy]
|
||||||
resources :project_datasets, only: [:index]
|
resources :project_datasets, only: [:index]
|
||||||
|
resources :gitlink_competition_applies, only: [:create]
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
class CreateGitlinkCompetitionApplies < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
create_table :gitlink_competition_applies do |t|
|
||||||
|
t.integer :competition_id
|
||||||
|
t.string :competition_identifier
|
||||||
|
t.integer :team_id
|
||||||
|
t.string :team_name
|
||||||
|
t.string :school_name
|
||||||
|
t.string :educoder_login
|
||||||
|
t.string :nickname
|
||||||
|
t.string :phone
|
||||||
|
t.string :email
|
||||||
|
t.string :identity
|
||||||
|
t.string :role
|
||||||
|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,5 @@
|
||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe GitlinkCompetitionApply, type: :model do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
Loading…
Reference in New Issue