Compare commits
114 Commits
master
...
dev_edu_lo
| Author | SHA1 | Date |
|---|---|---|
|
|
4494cbe3a9 | |
|
|
a1b18c07df | |
|
|
32ac61d889 | |
|
|
229885f42c | |
|
|
263636126b | |
|
|
35e11bf375 | |
|
|
69efc69e2d | |
|
|
ace13abe92 | |
|
|
e8da6364d8 | |
|
|
a7e20dcae2 | |
|
|
06e24a8ea4 | |
|
|
070df3c9dd | |
|
|
0bb45c7359 | |
|
|
6aa7a3a3b2 | |
|
|
7c0bc5d444 | |
|
|
334c0c2c09 | |
|
|
113f8ded36 | |
|
|
0178c8b913 | |
|
|
dc07042e83 | |
|
|
6ebab1be66 | |
|
|
27f510e6c9 | |
|
|
d9a27b7728 | |
|
|
68f1d7f7f6 | |
|
|
7e3517d873 | |
|
|
877ef54b24 | |
|
|
133eed6afe | |
|
|
eba2df5a2d | |
|
|
85a37fdbcc | |
|
|
01341d4389 | |
|
|
a62b29a263 | |
|
|
3a475a4674 | |
|
|
0eccafcb69 | |
|
|
0dbed862a7 | |
|
|
dfc998a9cc | |
|
|
8be4bc823c | |
|
|
7af6d8d754 | |
|
|
5a8dc9d5e7 | |
|
|
ecdb79ee48 | |
|
|
50e0ad9804 | |
|
|
953d6790d0 | |
|
|
136d1c1abd | |
|
|
e085ef374b | |
|
|
a557139ad0 | |
|
|
6d0ac60d5a | |
|
|
dda1868a72 | |
|
|
93a1a08393 | |
|
|
4d4d8d1369 | |
|
|
ab42fb7476 | |
|
|
11ac2f9c9d | |
|
|
8a9c3df2e5 | |
|
|
e90f80255e | |
|
|
1b6c082480 | |
|
|
ce1152cd4f | |
|
|
c8a9094ad0 | |
|
|
569088d846 | |
|
|
6159cda155 | |
|
|
d738ea432b | |
|
|
4a30e8c83f | |
|
|
b3288937c9 | |
|
|
7520fa03c2 | |
|
|
f282d971e3 | |
|
|
56f01801ae | |
|
|
45e70367d5 | |
|
|
a0b376e70a | |
|
|
d62d757c42 | |
|
|
033c2607e2 | |
|
|
0d6abdf7d0 | |
|
|
22c68f4c70 | |
|
|
fcd86fb01b | |
|
|
faecb99136 | |
|
|
15a002f601 | |
|
|
206d7bc159 | |
|
|
5e0006a830 | |
|
|
3abf993463 | |
|
|
efbf6d627d | |
|
|
6836907146 | |
|
|
6c4058cde5 | |
|
|
5a2e17abe2 | |
|
|
9a8b89bcd8 | |
|
|
4856da1607 | |
|
|
883a5f7e38 | |
|
|
1658c1b923 | |
|
|
74f6a54d29 | |
|
|
adb315521e | |
|
|
01cad866b8 | |
|
|
3447b17cdf | |
|
|
0079255e98 | |
|
|
490bff5ded | |
|
|
008b8ac709 | |
|
|
d0532a8f70 | |
|
|
a8c4cde350 | |
|
|
5de5974102 | |
|
|
3d3e778078 | |
|
|
f5ea8dc4a2 | |
|
|
c4b942a5f2 | |
|
|
13391b189a | |
|
|
b116a72ce7 | |
|
|
f01aec94d6 | |
|
|
cc97f85a1e | |
|
|
133995080a | |
|
|
27304c35dc | |
|
|
d6bf85ef73 | |
|
|
be9c01bf1d | |
|
|
edeaaa5db7 | |
|
|
0e41b6cc9b | |
|
|
5f3946f187 | |
|
|
b7be00f3ec | |
|
|
9b21e29426 | |
|
|
f37fccfdb3 | |
|
|
810d2dbac6 | |
|
|
6af97d865f | |
|
|
efba4b2b4f | |
|
|
aaf1f43cc2 | |
|
|
823c99bd71 |
|
|
@ -6,6 +6,20 @@ class AccountsController < ApplicationController
|
|||
render json: session
|
||||
end
|
||||
|
||||
# 为了同步平台上未注册gitea的用户
|
||||
def gitea_register
|
||||
user = User.find_by(login: sync_gitea_params[:login])
|
||||
Users::SyncGiteaForm.new(sync_gitea_params.merge(user: user)).validate!
|
||||
return render_error("该用户已同步协作平台") if user.gitea_token.present? && user.gitea_uid.present?
|
||||
|
||||
result = create_gitea_user!(user, sync_gitea_params[:login], sync_gitea_params[:email], sync_gitea_params[:password])
|
||||
|
||||
result[:user] ? render_ok : render_error(result[:message])
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(-1, e.message)
|
||||
end
|
||||
|
||||
# 其他平台同步注册的用户
|
||||
def remote_register
|
||||
username = params[:username]&.gsub(/\s+/, "")
|
||||
|
|
@ -361,6 +375,10 @@ class AccountsController < ApplicationController
|
|||
{ login: pre + code, email: email, phone: phone }
|
||||
end
|
||||
|
||||
def sync_gitea_params
|
||||
params.permit(:login, :email, :password)
|
||||
end
|
||||
|
||||
def user_params
|
||||
params.require(:user).permit(:login, :email, :phone)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -35,15 +35,16 @@ module LaboratoryHelper
|
|||
# my_projects: "/users/#{current_user.try(:login)}/projects",
|
||||
# my_projects: "https://www.trustie.net/users/#{current_user.try(:login)}/user_projectlist",
|
||||
{
|
||||
new_syllabuses: "https://www.trustie.net/syllabuses/new",
|
||||
new_course: "https://www.trustie.net/courses/new",
|
||||
edit_account: "https://www.trustie.net/my/account",
|
||||
my_courses: "https://www.trustie.net/users/#{current_user.try(:login)}/user_courselist",
|
||||
new_syllabuses: "https://forge.educoder.net/syllabuses/new",
|
||||
new_course: "https://forge.educoder.net/courses/new",
|
||||
edit_account: "https://forge.educoder.net/my/account",
|
||||
my_courses: "https://forge.educoder.net/users/#{current_user.try(:login)}/user_courselist",
|
||||
my_projects: "/users/#{current_user.try(:login)}/projects",
|
||||
my_organ: "https://www.trustie.net/users/#{current_user.try(:login)}/user_organizations",
|
||||
default_url: "https://www.trustie.net/",
|
||||
tiding_url: "https://www.trustie.net/users/#{current_user.try(:login)}/user_messages",
|
||||
register_url: "https://www.trustie.net/login?login=false"
|
||||
my_organ: "https://forge.educoder.net/users/#{current_user.try(:login)}/user_organizations",
|
||||
default_url: "http://106.75.178.228",
|
||||
forge_url: "http://106.75.178.228:81",
|
||||
tiding_url: "https://www.educoder.net/users/#{current_user.try(:login)}/user_tidings",
|
||||
register_url: "https://www.educoder.net/user/register"
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ module RegisterHelper
|
|||
extend ActiveSupport::Concern
|
||||
|
||||
def autologin_register(username, email, password, platform= 'forge')
|
||||
result = {message: nil, user: nil}
|
||||
|
||||
user = User.new(admin: false, login: username, mail: email, type: "User")
|
||||
user.password = password
|
||||
user.platform = platform
|
||||
|
|
@ -11,20 +9,32 @@ module RegisterHelper
|
|||
|
||||
return unless user.valid?
|
||||
|
||||
create_gitea_user!(user, username, email, password)
|
||||
end
|
||||
|
||||
def create_gitea_user!(forge_user, username, email, password=random_password)
|
||||
result = {message: nil, user: nil}
|
||||
|
||||
interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password})
|
||||
if interactor.success?
|
||||
gitea_user = interactor.result
|
||||
Rails.logger.info "##### [gitea] create_gitea_user result: #{gitea_user}"
|
||||
result = Gitea::User::GenerateTokenService.call(username, password)
|
||||
user.gitea_token = result['sha1']
|
||||
user.gitea_uid = gitea_user[:body]['id']
|
||||
if user.save!
|
||||
UserExtension.create!(user_id: user.id)
|
||||
result[:user] = {id: user.id, token: user.gitea_token}
|
||||
forge_user.gitea_token = result['sha1']
|
||||
forge_user.gitea_uid = gitea_user[:body]['id']
|
||||
forge_user.mail = email
|
||||
if forge_user.save
|
||||
UserExtension.create!(user_id: forge_user.id) if forge_user.user_extension.blank?
|
||||
result[:user] = {id: forge_user.id, token: forge_user.gitea_token}
|
||||
end
|
||||
else
|
||||
Rails.logger.info "##### [gitea] create_gitea_user result: #{interactor.error}"
|
||||
result[:message] = interactor.error
|
||||
end
|
||||
result
|
||||
end
|
||||
|
||||
|
||||
def random_password
|
||||
"#{Random.rand(11111111)}"
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,6 +5,14 @@ class ForksController < ApplicationController
|
|||
|
||||
def create
|
||||
@new_project = Projects::ForkService.new(current_user, @project, params[:organization]).call
|
||||
|
||||
# TODO: fix Educoder shixun
|
||||
if @new_project.persisted?
|
||||
ProjectScore.create(:project_id => @new_project.id, :score => 0) if @new_project.project_score.nil?
|
||||
|
||||
project_info = ProjectInfo.new(:user_id => current_user.id, :project_id => @new_project.id)
|
||||
@project.project_infos << project_info
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
|
|
|||
|
|
@ -21,6 +21,14 @@ class MainController < ApplicationController
|
|||
uid_logger("main start is #{cookies[:_educoder_session]}")
|
||||
end
|
||||
|
||||
if params[:path] && params[:path].start_with?('projects/')
|
||||
project_id = params[:path].split("/")[1]
|
||||
project = Project.find_by_id(project_id)
|
||||
if project.present?
|
||||
return redirect_to("/projects/#{project.owner.login}/#{project.identifier}", status: 301)
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: 这块之后需要整合,者架构重新变化,统一跳转到index后再路由分发
|
||||
if params[:path] && params[:path]&.include?("h5educoderbuild") && params[:path].split("/").first == "h5educoderbuild"
|
||||
render file: 'public/h5educoderbuild/index.html', :layout => false
|
||||
|
|
|
|||
|
|
@ -7,7 +7,16 @@ class MembersController < ApplicationController
|
|||
before_action :check_member_not_exists!, only: %i[remove change_role]
|
||||
|
||||
def create
|
||||
if @user.gitea_token.blank?
|
||||
result = Gitea::User::GetService.call(@user.login)
|
||||
if result[:status] == :error
|
||||
# gitea不存在用户@user,直接注册
|
||||
user_result = create_gitea_user!(@user, @user.login, @user.mail)
|
||||
return render_error(user_result[:message]) if user_result[:message]
|
||||
end
|
||||
end
|
||||
interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user)
|
||||
|
||||
render_response(interactor)
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ class ProjectsController < ApplicationController
|
|||
menu.append(menu_hash_by_name("versions")) if @project.has_menu_permission("versions")
|
||||
menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources")
|
||||
menu.append(menu_hash_by_name("activity"))
|
||||
menu.append(menu_hash_by_name("gantt"))
|
||||
menu.append(menu_hash_by_name("sonar"))
|
||||
menu.append(menu_hash_by_name("setting")) if current_user.admin? || @project.manager?(current_user)
|
||||
|
||||
render json: menu
|
||||
|
|
@ -47,6 +49,13 @@ class ProjectsController < ApplicationController
|
|||
Projects::CreateForm.new(project_params).validate!
|
||||
@project = Projects::CreateService.new(current_user, project_params).call
|
||||
|
||||
# TODO: fix Educoder shixun
|
||||
if @project.persisted?
|
||||
ProjectScore.create(:project_id => @project.id, :score => 0) if @project.project_score.nil?
|
||||
|
||||
project_info = ProjectInfo.new(:user_id => current_user.id, :project_id => @project.id)
|
||||
@project.project_infos << project_info
|
||||
end
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ class PullRequestsController < ApplicationController
|
|||
ActiveRecord::Base.transaction do
|
||||
@pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params)
|
||||
if @gitea_pull_request[:status] == :success
|
||||
@pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"])
|
||||
@pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"])
|
||||
render_ok
|
||||
else
|
||||
render_error("create pull request error: #{@gitea_pull_request[:status]}")
|
||||
|
|
|
|||
|
|
@ -205,6 +205,51 @@ class RepositoriesController < ApplicationController
|
|||
redirect_to file_path
|
||||
end
|
||||
|
||||
def sonarqube
|
||||
@sonarqubes = @project.sonarqubes
|
||||
|
||||
branches = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier)
|
||||
branches.each do |branch|
|
||||
sonarqube = @sonarqubes.find_by(branch_name: branch['name'])
|
||||
file_num = 0
|
||||
|
||||
entries = Gitea::Repository::Entries::ListService.call(@owner, @project.identifier, ref: branch['name'])
|
||||
file_num += entries.size
|
||||
entries.each do |entry|
|
||||
file_path_uri = URI.parse(URI.encode(entry['path'].to_s.strip))
|
||||
|
||||
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: branch['name'])
|
||||
if interactor.success?
|
||||
result = interactor.result
|
||||
|
||||
while result.is_a?(Array)
|
||||
file_num += result.size
|
||||
result.each do |res|
|
||||
file_path_uri = URI.parse(URI.encode(res['path'].to_s.strip))
|
||||
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: branch['name'])
|
||||
result = interactor.result
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if sonarqube
|
||||
sonarqube.update(bug_num: 0, loophole: 0, repetition_rate: 0, file_num: file_num, created_at: Time.now)
|
||||
sleep 3.seconds
|
||||
sonarqube.update_column(:updated_at, Time.now)
|
||||
else
|
||||
@project.sonarqubes.create!(
|
||||
branch_name: branch['name'],
|
||||
bug_num: 0,
|
||||
loophole: 0,
|
||||
repetition_rate: 0,
|
||||
file_num: file_num
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def find_project
|
||||
|
|
@ -316,7 +361,7 @@ class RepositoriesController < ApplicationController
|
|||
local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id))
|
||||
if local_requests.save
|
||||
gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call
|
||||
if gitea_request[:status] == :success && local_requests.update_attributes(gpid: gitea_request["body"]["number"])
|
||||
if gitea_request[:status] == :success && local_requests.update_attributes(gitea_number: gitea_request["body"]["number"])
|
||||
local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ class UsersController < ApplicationController
|
|||
|
||||
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users, :hovercard]
|
||||
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard]
|
||||
before_action :require_login, only: %i[me list sync_user_info]
|
||||
before_action :require_login, only: %i[me list]
|
||||
before_action :connect_to_ci_db, only: [:get_user_info]
|
||||
before_action :convert_image!, only: [:update]
|
||||
skip_before_action :check_sign, only: [:attachment_show]
|
||||
|
|
@ -254,23 +254,58 @@ class UsersController < ApplicationController
|
|||
render_ok
|
||||
end
|
||||
|
||||
def sync_user_info
|
||||
# TODO: For Educoder
|
||||
def change_password
|
||||
user = User.find_by_login params[:login]
|
||||
return render_forbidden unless user === current_user
|
||||
|
||||
form_params= {
|
||||
login: params[:login],
|
||||
email: user&.mail,
|
||||
password: params[:password],
|
||||
user: user
|
||||
}
|
||||
Gitea::User::ChangePasswordForm.new(form_params).validate!
|
||||
|
||||
sync_params = {
|
||||
email: params[:email],
|
||||
email: user&.mail,
|
||||
password: params[:password]
|
||||
}
|
||||
|
||||
Users::UpdateInfoForm.new(sync_params.merge(login: params[:login])).validate!
|
||||
if sync_params.present?
|
||||
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
|
||||
if interactor.success?
|
||||
user.update!(password: params[:password], is_sync_pwd: true)
|
||||
render_ok
|
||||
else
|
||||
render_error(interactor.error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
|
||||
if interactor.success?
|
||||
user.update!(password: params[:password], mail: params[:email], status: User::STATUS_EDIT_INFO)
|
||||
render_ok
|
||||
else
|
||||
render_error(interactor.error)
|
||||
# TODO: For Educoder
|
||||
def change_email
|
||||
user = User.find_by_login params[:login]
|
||||
|
||||
form_params= {
|
||||
login: params[:login],
|
||||
email: user&.mail,
|
||||
user: user
|
||||
}
|
||||
|
||||
Gitea::User::ChangeEmailForm.new(form_params).validate!
|
||||
|
||||
sync_params = {
|
||||
email: params[:email]
|
||||
}
|
||||
|
||||
if sync_params.present?
|
||||
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
|
||||
if interactor.success?
|
||||
user.update!(mail: params[:email])
|
||||
render_ok
|
||||
else
|
||||
render_error(interactor.error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
class Gitea::User::ChangeEmailForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :user
|
||||
attr_accessor :email, :login
|
||||
|
||||
validates :email, presence: true, format: { with: CustomRegexp::EMAIL }
|
||||
validates :login, presence: true
|
||||
end
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
class Gitea::User::ChangePasswordForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :user
|
||||
attr_accessor :email, :login, :password
|
||||
|
||||
validates :email, presence: true, format: { with: CustomRegexp::EMAIL }
|
||||
validates :login, presence: true
|
||||
validates :password, presence: true
|
||||
|
||||
# validate :check_old_password
|
||||
|
||||
def check_old_password
|
||||
return if user.check_password?(old_password.to_s)
|
||||
|
||||
errors.add(:old_password, :password_error)
|
||||
end
|
||||
|
||||
# def check_user!
|
||||
# user === current_user
|
||||
# end
|
||||
end
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
class Users::SyncGiteaForm
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_accessor :login, :password, :email, :user
|
||||
|
||||
validates :login, :password, :email, presence: true
|
||||
|
||||
validate :check_user, :check_password
|
||||
|
||||
def check_user
|
||||
user = User.find_by(login: login)
|
||||
raise '用户不存在.' unless user.present?
|
||||
end
|
||||
|
||||
def check_password
|
||||
raise '用户密码错误.' unless user.check_password?(password)
|
||||
end
|
||||
end
|
||||
|
|
@ -23,13 +23,17 @@ module Gitea
|
|||
def run
|
||||
Gitea::UserForm.new(params).validate!
|
||||
response = Gitea::User::RegisterService.call(params.merge(token: token))
|
||||
render_result(response)
|
||||
|
||||
if response[:status] == :success
|
||||
@result = response
|
||||
else
|
||||
fail!(response[:message])
|
||||
end
|
||||
rescue Exception => exception
|
||||
Rails.logger.info "Exception ===========> #{exception.message}"
|
||||
fail!(exception.message)
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
attr_reader :params
|
||||
|
|
@ -38,10 +42,6 @@ module Gitea
|
|||
@error = error
|
||||
end
|
||||
|
||||
def render_result(response)
|
||||
@result = response
|
||||
end
|
||||
|
||||
def token
|
||||
{
|
||||
username: Gitea.gitea_config[:access_key_id],
|
||||
|
|
|
|||
|
|
@ -39,6 +39,6 @@ class Gitea::Pull < Gitea::Base
|
|||
|
||||
serialize :conflicted_files, Array
|
||||
|
||||
belongs_to :pull_request, class_name: '::PullRequest', foreign_key: :id, primary_key: :gitea_number, optional: true
|
||||
belongs_to :pull_request, class_name: '::PullRequest', foreign_key: :id, primary_key: :gitea_id, optional: true
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: projects
|
||||
|
|
@ -38,8 +37,6 @@
|
|||
# rep_identifier :string(255)
|
||||
# project_category_id :integer
|
||||
# project_language_id :integer
|
||||
# license_id :integer
|
||||
# ignore_id :integer
|
||||
# praises_count :integer default("0")
|
||||
# watchers_count :integer default("0")
|
||||
# issues_count :integer default("0")
|
||||
|
|
@ -53,9 +50,10 @@
|
|||
# open_devops_count :integer default("0")
|
||||
# recommend :boolean default("0")
|
||||
# platform :integer default("0")
|
||||
# license_id :integer
|
||||
# ignore_id :integer
|
||||
# default_branch :string(255) default("master")
|
||||
# website :string(255)
|
||||
# order_index :integer default("0")
|
||||
# lesson_url :string(255)
|
||||
#
|
||||
# Indexes
|
||||
|
|
@ -79,6 +77,7 @@
|
|||
|
||||
|
||||
|
||||
|
||||
class Project < ApplicationRecord
|
||||
include Matchable
|
||||
include Publicable
|
||||
|
|
@ -110,6 +109,7 @@ class Project < ApplicationRecord
|
|||
has_one :project_educoder, dependent: :destroy
|
||||
|
||||
has_one :project_score, dependent: :destroy
|
||||
has_many :project_infos, :dependent => :destroy
|
||||
has_one :repository, dependent: :destroy
|
||||
has_many :pull_requests, dependent: :destroy
|
||||
has_many :issue_tags, -> { order("issue_tags.created_at DESC") }, dependent: :destroy
|
||||
|
|
@ -125,6 +125,7 @@ class Project < ApplicationRecord
|
|||
has_one :applied_transfer_project,-> { order created_at: :desc }, dependent: :destroy
|
||||
has_many :pinned_projects, dependent: :destroy
|
||||
has_many :has_pinned_users, through: :pinned_projects, source: :user
|
||||
has_many :sonarqubes, dependent: :destroy
|
||||
|
||||
after_save :check_project_members, :reset_cache_data
|
||||
before_save :set_invite_code
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: project_infos
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# project_id :integer
|
||||
# user_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class ProjectInfo < ActiveRecord::Base
|
||||
|
||||
belongs_to :project
|
||||
belongs_to :user
|
||||
validates_presence_of :project_id, :user_id
|
||||
validates_uniqueness_of :project_id, :scope => :user_id
|
||||
|
||||
end
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
class ProjectUnit < ApplicationRecord
|
||||
belongs_to :project
|
||||
|
||||
enum unit_type: {code: 1, issues: 2, pulls: 3, devops: 4, versions: 5, resources: 6}
|
||||
enum unit_type: {code: 1, issues: 2, pulls: 3, devops: 4, versions: 5, resources: 6, gantt: 7, sonar: 8}
|
||||
|
||||
validates :unit_type, uniqueness: { scope: :project_id}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
# Table name: pull_requests
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# pull_request_id :integer
|
||||
# gpid :integer
|
||||
# gitea_id :integer
|
||||
# gitea_number :integer
|
||||
# user_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
|
|
@ -37,7 +37,7 @@ class PullRequest < ApplicationRecord
|
|||
has_many :pull_request_tags, foreign_key: :pull_request_id
|
||||
has_many :project_trends, as: :trend, dependent: :destroy
|
||||
has_many :attachments, as: :container, dependent: :destroy
|
||||
has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_number, class_name: 'Gitea::Pull'
|
||||
has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_id, class_name: 'Gitea::Pull'
|
||||
|
||||
scope :merged_and_closed, ->{where.not(status: 0)}
|
||||
scope :opening, -> {where(status: 0)}
|
||||
|
|
@ -54,8 +54,10 @@ class PullRequest < ApplicationRecord
|
|||
Project.find_by(id: self.fork_project_id)
|
||||
end
|
||||
|
||||
def bind_gitea_pull_request!(gitea_pull_number)
|
||||
update_column(:gitea_number, gitea_pull_number)
|
||||
def bind_gitea_pull_request!(gitea_pull_number, gitea_pull_id)
|
||||
update_columns(
|
||||
gitea_number: gitea_pull_number,
|
||||
gitea_id: gitea_pull_id)
|
||||
end
|
||||
|
||||
def merge!
|
||||
|
|
|
|||
|
|
@ -0,0 +1,18 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: sonarqubes
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# loophole :integer default("0")
|
||||
# repetition_rate :integer default("0")
|
||||
# bug_num :integer default("0")
|
||||
# file_num :integer default("0")
|
||||
# project_id :integer
|
||||
# branch_name :string(255)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class Sonarqube < ApplicationRecord
|
||||
belongs_to :project, optional: true
|
||||
end
|
||||
|
|
@ -24,7 +24,7 @@
|
|||
#
|
||||
|
||||
class Version < ApplicationRecord
|
||||
belongs_to :project, counter_cache: true, touch: true
|
||||
belongs_to :project, counter_cache: true, touch: true, optional: true
|
||||
has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id"
|
||||
belongs_to :user, optional: true
|
||||
|
||||
|
|
|
|||
|
|
@ -25,8 +25,7 @@ class Gitea::Repository::CreateService < Gitea::ClientService
|
|||
private
|
||||
|
||||
def request_params
|
||||
create_params = params.merge(readme: "readme")
|
||||
Hash.new.merge(token: token, data: create_params)
|
||||
Hash.new.merge(token: token, data: params)
|
||||
end
|
||||
|
||||
def url
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
class Gitea::User::GetService < Gitea::ClientService
|
||||
attr_reader :username
|
||||
# params:
|
||||
# username* string # required
|
||||
def initialize(username)
|
||||
@username = username
|
||||
end
|
||||
|
||||
def call
|
||||
response = get(url, params)
|
||||
|
||||
status, message, body = render_response(response)
|
||||
json_format(status, message, body)
|
||||
end
|
||||
|
||||
private
|
||||
def url
|
||||
"/users/#{username}"
|
||||
end
|
||||
|
||||
def params
|
||||
{username: username}
|
||||
end
|
||||
|
||||
|
||||
def json_format(status, message, body)
|
||||
case status
|
||||
when 200 then success(body)
|
||||
else
|
||||
error(message, status)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -10,8 +10,7 @@ class Gitea::User::RegisterService < Gitea::ClientService
|
|||
params = Hash.new.merge(data: user_params, token: @token)
|
||||
|
||||
response = post(API_REST, params)
|
||||
status, message, body = render_response(response)
|
||||
json_format(status, message, body)
|
||||
response_payload(response)
|
||||
end
|
||||
|
||||
private
|
||||
|
|
@ -27,11 +26,28 @@ class Gitea::User::RegisterService < Gitea::ClientService
|
|||
}
|
||||
end
|
||||
|
||||
def json_format(status, message, body)
|
||||
def response_payload(response)
|
||||
status = response.status
|
||||
body = response&.body
|
||||
|
||||
log_error(status, body)
|
||||
status_payload(status, body)
|
||||
end
|
||||
|
||||
def status_payload(status, body)
|
||||
case status
|
||||
when 201 then success(body)
|
||||
else
|
||||
error(message, status)
|
||||
when 201 then success(json_parse!(body))
|
||||
when 403 then error("你没有权限操作!")
|
||||
when 400 then error("服务器开小差了")
|
||||
when 422
|
||||
body = json_parse!(body)
|
||||
message = body['message']
|
||||
if message.include?('email')
|
||||
error("邮箱#{email}已被注册")
|
||||
elsif message.include?('name')
|
||||
error("用户名#{username}已被注册")
|
||||
end
|
||||
else error("系统错误!")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -9,10 +9,11 @@
|
|||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if school && school.identifier.present? %>
|
||||
<% else %>
|
||||
<%# if school && school.identifier.present? %>
|
||||
<%#= link_to school.identifier.to_s, statistics_college_path(school.identifier), target: '_blank' %>
|
||||
<%# else %>
|
||||
--
|
||||
<% end %>
|
||||
<%# end %>
|
||||
</td>
|
||||
<td class="member-container">
|
||||
<div class="laboratory-user">
|
||||
|
|
@ -29,21 +30,6 @@
|
|||
</div>
|
||||
</td>
|
||||
<td><%= laboratory.created_at.strftime('%Y-%m-%d %H:%M') %></td>
|
||||
<td>
|
||||
<% if school.present? && laboratory.id != 1 %>
|
||||
<%= check_box_tag :sync_course,!laboratory.sync_course,laboratory.sync_course,remote:true,data:{id:laboratory.id},class:"laboratory-sync-form" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if school.present? && laboratory.id != 1 %>
|
||||
<%= check_box_tag :sync_subject,!laboratory.sync_subject,laboratory.sync_subject,remote:true,data:{id:laboratory.id},class:"laboratory-sync-form" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if school.present? && laboratory.id != 1 %>
|
||||
<%= check_box_tag :sync_shixun,!laboratory.sync_shixun,laboratory.sync_shixun,remote:true,data:{id:laboratory.id},class:"laboratory-sync-form" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="action-container">
|
||||
<%= link_to '定制', admins_laboratory_laboratory_setting_path(laboratory), class: 'action' %>
|
||||
|
||||
|
|
@ -51,18 +37,4 @@
|
|||
<%= javascript_void_link '添加管理员', class: 'action', data: { laboratory_id: laboratory.id, toggle: 'modal', target: '.admin-add-laboratory-user-modal' } %>
|
||||
<%= link_to '同步用户', synchronize_user_admins_laboratory_path(laboratory), remote: true, data: { confirm: '确认同步该单位下的所有用户到云上实验室吗?' }, class: 'action' %>
|
||||
<% end %>
|
||||
|
||||
<div class="d-inline">
|
||||
<%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %>
|
||||
<div class="dropdown-menu more-action-dropdown">
|
||||
<%= link_to '轮播图', admins_laboratory_carousels_path(laboratory), class: 'dropdown-item' %>
|
||||
|
||||
<%= link_to '查看实训项目', admins_laboratory_laboratory_shixuns_path(laboratory), class: 'dropdown-item' %>
|
||||
<%= link_to '查看实践课程', admins_laboratory_laboratory_subjects_path(laboratory), class: 'dropdown-item' %>
|
||||
|
||||
<% if school.present? && laboratory.id != 1 %>
|
||||
<%= delete_link '删除', admins_laboratory_path(laboratory, element: ".laboratory-item-#{laboratory.id}"), class: 'dropdown-item delete-laboratory-action' %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
|
|
|||
|
|
@ -7,9 +7,6 @@
|
|||
<th width="6%">统计链接</th>
|
||||
<th width="22%">管理员</th>
|
||||
<th width="10%"><%= sort_tag('创建时间', name: 'id', path: admins_laboratories_path) %></th>
|
||||
<th width="4%" title="同步显示主站下该单位的课堂">同步课堂</th>
|
||||
<th width="4%" title="同步显示主站下该单位用户创建的实践课程">同步实践课程</th>
|
||||
<th width="4%" title="同步显示主站下该单位用户创建的实训">同步实训</th>
|
||||
<th width="16%">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
|
|
|||
|
|
@ -33,10 +33,6 @@
|
|||
|
||||
<li>
|
||||
<%= sidebar_item_group('#setting-submenu', '网站建设', icon: 'cogs') do %>
|
||||
<li><%= sidebar_item(edit_admins_about_path, '关于我们', icon: 'smile-o', controller: 'admins-abouts') %></li>
|
||||
<li><%= sidebar_item(edit_admins_contact_us_path, '联系我们', icon: 'commenting-o', controller: 'admins-contact_us') %></li>
|
||||
<li><%= sidebar_item(admins_cooperatives_path, '合作伙伴', icon: 'handshake-o', controller: 'admins-cooperatives') %></li>
|
||||
<li><%= sidebar_item(edit_admins_agreement_path, '服务协议', icon: 'file-text-o', controller: 'admins-agreements') %></li>
|
||||
<li><%= sidebar_item(edit_admins_help_center_path, '帮助中心', icon: 'question-circle-o', controller: 'admins-help_centers') %></li>
|
||||
<li><%= sidebar_item(admins_faqs_path, 'FAQ', icon: 'question-circle', controller: 'admins-faqs') %></li>
|
||||
<% end %>
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
json.extract! @project, :id, :name,:identifier
|
||||
json.login @project&.owner&.login
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
json.array! @sonarqubes do |sonarqube|
|
||||
json.branch_name sonarqube.branch_name
|
||||
json.bug_num sonarqube.bug_num
|
||||
json.loophole sonarqube.loophole
|
||||
json.repetition_rate number_to_percentage(sonarqube.repetition_rate, precision: 1)
|
||||
json.file_num sonarqube.file_num
|
||||
json.created_at format_time(sonarqube.created_at)
|
||||
json.updated_at format_time(sonarqube.updated_at)
|
||||
end
|
||||
|
|
@ -20,6 +20,11 @@ json.setting do
|
|||
|
||||
nav_bar = default_setting.navbar
|
||||
|
||||
|
||||
|
||||
hash = {hidden: false, link: 'http://106.75.178.228/ecs/department?school_id=1', name: '工程认证'}
|
||||
nav_bar << hash
|
||||
|
||||
# if User.current.logged?
|
||||
# nav_bar[2]["link"] = "https://forgeplus.trustie.net/users/#{current_user.login}/projects"
|
||||
# nav_bar[2]["hidden"] = false
|
||||
|
|
|
|||
|
|
@ -6,11 +6,13 @@ json.user_id @user.id
|
|||
json.image_url url_to_avatar(@user)
|
||||
json.admin @user.admin?
|
||||
json.is_teacher @user.user_extension&.teacher?
|
||||
json.has_gitea_user @user.gitea_token.present? && @user.gitea_uid.present?
|
||||
json.is_sync_pwd @user.is_sync_pwd
|
||||
json.user_identity @user.identity
|
||||
json.tidding_count 0
|
||||
json.user_phone_binded @user.phone.present?
|
||||
# json.phone @user.phone
|
||||
# json.email @user.mail
|
||||
json.email @user.mail
|
||||
json.profile_completed @user.profile_completed?
|
||||
json.professional_certification @user.professional_certification
|
||||
json.devops_step @user.devops_step
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
'zh-CN':
|
||||
activemodel:
|
||||
attributes:
|
||||
gitea/user/change_password_form:
|
||||
user: ''
|
||||
email: 邮箱
|
||||
login: 用户名
|
||||
old_password: 旧密码
|
||||
password: 新密码
|
||||
errors:
|
||||
models:
|
||||
gitea/user/change_password_form:
|
||||
attributes:
|
||||
old_password:
|
||||
password_error: 错误
|
||||
user:
|
||||
not_exist: 不存在
|
||||
|
|
@ -188,6 +188,7 @@ Rails.application.routes.draw do
|
|||
get :logout
|
||||
get :get_verification_code
|
||||
get :valid_email_and_phone
|
||||
post :gitea_register
|
||||
post :remote_register
|
||||
post :remote_update
|
||||
post :remote_login
|
||||
|
|
@ -223,7 +224,8 @@ Rails.application.routes.draw do
|
|||
post :sync_salt
|
||||
get :trustie_projects
|
||||
get :trustie_related_projects
|
||||
post :sync_user_info
|
||||
post :change_password
|
||||
post :change_email
|
||||
|
||||
scope '/ci', module: :ci do
|
||||
scope do
|
||||
|
|
@ -431,6 +433,7 @@ Rails.application.routes.draw do
|
|||
get 'readme'
|
||||
get 'languages'
|
||||
get 'archive/:archive', to: 'repositories#archive', as: "archive", constraints: { archive: /.+/, format: /(zip|gzip)/ }
|
||||
get 'sonarqube'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class AddPlatformToUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :users, :platform, :string, default: 0
|
||||
add_column :users, :platform, :string, default: 0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class AddGiteaTokenToUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :users, :gitea_token, :string
|
||||
add_column :users, :gitea_token, :string
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class AddProjectCategoryIdAndProjectLanguageIdToProjects < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :projects, :project_category_id, :integer
|
||||
# add_column :projects, :project_language_id, :integer
|
||||
add_column :projects, :project_category_id, :integer
|
||||
add_column :projects, :project_language_id, :integer
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class AddUserRefToRepository < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :repositories, :user_id, :integer
|
||||
# add_index :repositories, :user_id
|
||||
add_column :repositories, :user_id, :integer
|
||||
add_index :repositories, :user_id
|
||||
|
||||
Project.joins(:repository).find_each do |project|
|
||||
project&.repository&.update_column(:user_id, project&.user_id) unless project&.repository.blank?
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class AddGiteaUidToUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :users, :gitea_uid, :integer
|
||||
add_column :users, :gitea_uid, :integer
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class AddMirrorUrlToRepositories < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :repositories, :mirror_url, :string
|
||||
add_column :repositories, :mirror_url, :string
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
class CreateIssueTags < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# create_table :issue_tags do |t|
|
||||
# t.string :title
|
||||
# t.string :description
|
||||
# t.string :color
|
||||
# t.integer :user_id
|
||||
# t.integer :project_id
|
||||
# t.integer :issues_count,default: 0
|
||||
# t.timestamps
|
||||
# end
|
||||
# add_index :issue_tags, [:user_id, :title,:project_id]
|
||||
create_table :issue_tags do |t|
|
||||
t.string :title
|
||||
t.string :description
|
||||
t.string :color
|
||||
t.integer :user_id
|
||||
t.integer :project_id
|
||||
t.integer :issues_count,default: 0
|
||||
t.timestamps
|
||||
end
|
||||
add_index :issue_tags, [:user_id, :title,:project_id]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class AddPraisesCountToProjects < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :projects, :praises_count, :integer, :default => 0
|
||||
add_column :projects, :praises_count, :integer, :default => 0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
class AddIssuesTypeAndToken < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :issues, :issue_type, :string
|
||||
# add_column :issues, :token, :string
|
||||
# add_column :issues, :issue_tag_ids, :string
|
||||
add_column :issues, :issue_type, :string
|
||||
add_column :issues, :token, :string
|
||||
add_column :issues, :issue_tag_ids, :string
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class RenameIssueTagTitle < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# rename_column :issue_tags, :title, :name
|
||||
rename_column :issue_tags, :title, :name
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
class CreateIssueTagsRelates < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# create_table :issue_tags_relates do |t|
|
||||
# t.integer :issue_id
|
||||
# t.integer :issue_tag_id
|
||||
# t.timestamps
|
||||
# end
|
||||
# add_index :issue_tags_relates, [:issue_id, :issue_tag_id]
|
||||
create_table :issue_tags_relates do |t|
|
||||
t.integer :issue_id
|
||||
t.integer :issue_tag_id
|
||||
t.timestamps
|
||||
end
|
||||
add_index :issue_tags_relates, [:issue_id, :issue_tag_id]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class RenameIssuesIssueTagIds < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# rename_column :issues, :issue_tag_ids, :issue_tags_value
|
||||
rename_column :issues, :issue_tag_ids, :issue_tags_value
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
class CreateIssueTimes < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# create_table :issue_times do |t|
|
||||
# t.integer :issue_id
|
||||
# t.integer :user_id
|
||||
# t.datetime :start_time
|
||||
# t.datetime :end_time
|
||||
# t.string :cost_time
|
||||
# t.timestamps
|
||||
# end
|
||||
# add_index :issue_times, [:issue_id, :user_id]
|
||||
create_table :issue_times do |t|
|
||||
t.integer :issue_id
|
||||
t.integer :user_id
|
||||
t.datetime :start_time
|
||||
t.datetime :end_time
|
||||
t.string :cost_time
|
||||
t.timestamps
|
||||
end
|
||||
add_index :issue_times, [:issue_id, :user_id]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class AddIsLockToIssue < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :issues, :is_lock, :boolean, default: false
|
||||
add_column :issues, :is_lock, :boolean, default: false
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
class AddWatchersCountToProjects < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :projects, :watchers_count, :integer, :default => 0
|
||||
add_column :projects, :watchers_count, :integer, :default => 0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
class CreateVersionReleases < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# create_table :version_releases do |t|
|
||||
# t.integer :user_id
|
||||
# t.string :name
|
||||
# t.text :body
|
||||
# t.string :tag_name
|
||||
# t.string :target_commitish
|
||||
# t.boolean :draft, default: false
|
||||
# t.boolean :prerelease, default: false
|
||||
# t.string :tarball_url
|
||||
# t.string :zipball_url
|
||||
# t.string :url
|
||||
# t.string :version_gid
|
||||
# t.timestamps
|
||||
# end
|
||||
create_table :version_releases do |t|
|
||||
t.integer :user_id
|
||||
t.string :name
|
||||
t.text :body
|
||||
t.string :tag_name
|
||||
t.string :target_commitish
|
||||
t.boolean :draft, default: false
|
||||
t.boolean :prerelease, default: false
|
||||
t.string :tarball_url
|
||||
t.string :zipball_url
|
||||
t.string :url
|
||||
t.string :version_gid
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class AddProjectIdToVersionRelease < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :version_releases, :repository_id, :integer
|
||||
# add_index :version_releases, [:repository_id]
|
||||
add_column :version_releases, :repository_id, :integer
|
||||
add_index :version_releases, [:repository_id]
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class AddColumnToIssueTags < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :issue_tags, :gid, :integer
|
||||
# add_column :issue_tags, :gitea_url, :string
|
||||
add_column :issue_tags, :gid, :integer
|
||||
add_column :issue_tags, :gitea_url, :string
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
class AddColumnToPullRequests < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :pull_requests, :version_id, :integer
|
||||
# add_column :pull_requests, :body, :text
|
||||
# add_column :pull_requests, :from_ref, :string
|
||||
# add_column :pull_requests, :to_ref, :string
|
||||
add_column :pull_requests, :version_id, :integer
|
||||
add_column :pull_requests, :body, :text
|
||||
add_column :pull_requests, :from_ref, :string
|
||||
add_column :pull_requests, :to_ref, :string
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -4,10 +4,10 @@ class ChangePullRequestsColumns < ActiveRecord::Migration[5.2]
|
|||
# add_column :pull_request_assigns, :user_login, :string
|
||||
#
|
||||
# add_index :pull_request_assigns, [:user_login]
|
||||
#
|
||||
# rename_column :pull_requests, :version_id, :milestone
|
||||
# rename_column :pull_requests, :from_ref, :head
|
||||
# rename_column :pull_requests, :to_ref, :base
|
||||
|
||||
rename_column :pull_requests, :version_id, :milestone
|
||||
rename_column :pull_requests, :from_ref, :head
|
||||
rename_column :pull_requests, :to_ref, :base
|
||||
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class AddColumnsToPullRequests < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :pull_requests, :issue_id, :integer
|
||||
# add_column :issues, :issue_classify, :string
|
||||
add_column :pull_requests, :issue_id, :integer
|
||||
add_column :issues, :issue_classify, :string
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class AddIssuesRefNameAndBranchName < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :issues, :ref_name, :string
|
||||
# add_column :issues, :branch_name, :string
|
||||
add_column :issues, :ref_name, :string
|
||||
add_column :issues, :branch_name, :string
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
class MigrateTidingStatus < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
Tiding.where(container_type: "JoinCourse", status: 0).each do |tiding|
|
||||
unless CourseMessage.where(course_message_id: tiding.trigger_user_id, course_id: tiding.container_id, course_message_type: "JoinCourseRequest", status: 0).exists?
|
||||
tiding.update!(status: 1)
|
||||
end
|
||||
end
|
||||
# Tiding.where(container_type: "JoinCourse", status: 0).each do |tiding|
|
||||
# unless CourseMessage.where(course_message_id: tiding.trigger_user_id, course_id: tiding.container_id, course_message_type: "JoinCourseRequest", status: 0).exists?
|
||||
# tiding.update!(status: 1)
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
class AddIssuesCountAndPullRequestsCountToProjects < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :projects, :issues_count, :integer, :default => 0
|
||||
# add_column :projects, :pull_requests_count, :integer, :default => 0
|
||||
add_column :projects, :issues_count, :integer, :default => 0
|
||||
add_column :projects, :pull_requests_count, :integer, :default => 0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
class MigrateUserLocation < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
UserExtension.where("location like '%省'").each do |ue|
|
||||
ue.update_column("location", ue.location.chop)
|
||||
end
|
||||
|
||||
UserExtension.where("location_city like '%市'").each do |ue|
|
||||
ue.update_column("location_city", ue.location_city.chop)
|
||||
end
|
||||
# UserExtension.where("location like '%省'").each do |ue|
|
||||
# ue.update_column("location", ue.location.chop)
|
||||
# end
|
||||
#
|
||||
# UserExtension.where("location_city like '%市'").each do |ue|
|
||||
# ue.update_column("location_city", ue.location_city.chop)
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class AddIssuesCountToVersions < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# add_column :versions, :issues_count, :integer, :default => 0
|
||||
# add_column :versions, :closed_issues_count, :integer, :default => 0
|
||||
# add_column :versions, :percent, :float, default: 0.0
|
||||
add_column :versions, :issues_count, :integer, :default => 0
|
||||
add_column :versions, :closed_issues_count, :integer, :default => 0
|
||||
add_column :versions, :percent, :float, default: 0.0
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,69 +1,69 @@
|
|||
class ChangeQuillToMd < ActiveRecord::Migration[5.2]
|
||||
#迁移quill编辑器的内容为md
|
||||
def change
|
||||
migrate_time = Time.current - 20.days
|
||||
migrate_time = Time.current - 20.days
|
||||
|
||||
all_issues = Issue.where("updated_on > ?", migrate_time)
|
||||
pros = PullRequest.where("updated_at > ?", migrate_time)
|
||||
journals = Journal.where("created_on > ?", migrate_time)
|
||||
|
||||
|
||||
Issue.transaction do
|
||||
if all_issues.size > 0
|
||||
all_issues.each do |i|
|
||||
description = i.description
|
||||
if description.present? && description.include?("insert")
|
||||
new_content = change_content(description)
|
||||
i.update_attribute(:description, new_content)
|
||||
end
|
||||
puts "__update_issue_content_____id:#{i.id}__"
|
||||
end
|
||||
end
|
||||
end
|
||||
# Issue.transaction do
|
||||
# if all_issues.size > 0
|
||||
# all_issues.each do |i|
|
||||
# description = i.description
|
||||
# if description.present? && description.include?("insert")
|
||||
# new_content = change_content(description)
|
||||
# i.update_attribute(:description, new_content)
|
||||
# end
|
||||
# puts "__update_issue_content_____id:#{i.id}__"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
Journal.transaction do
|
||||
if journals.size > 0
|
||||
journals.each do |j|
|
||||
description = j.notes
|
||||
if description.present? && description.include?("insert")
|
||||
new_content = change_content(description)
|
||||
j.update_attribute(:notes, new_content)
|
||||
end
|
||||
puts "__update_journal_content_____id:#{j.id}__"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
# Journal.transaction do
|
||||
# if journals.size > 0
|
||||
# journals.each do |j|
|
||||
# description = j.notes
|
||||
# if description.present? && description.include?("insert")
|
||||
# new_content = change_content(description)
|
||||
# j.update_attribute(:notes, new_content)
|
||||
# end
|
||||
# puts "__update_journal_content_____id:#{j.id}__"
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# end
|
||||
|
||||
PullRequest.transaction do
|
||||
if pros.size > 0
|
||||
pros.each do |p|
|
||||
description = p.body
|
||||
if description.present? && description.include?("insert")
|
||||
new_content = change_content(description)
|
||||
p.update_attribute(:body, new_content)
|
||||
end
|
||||
puts "__update_pull_request_content_____id:#{p.id}__"
|
||||
end
|
||||
end
|
||||
end
|
||||
# PullRequest.transaction do
|
||||
# if pros.size > 0
|
||||
# pros.each do |p|
|
||||
# description = p.body
|
||||
# if description.present? && description.include?("insert")
|
||||
# new_content = change_content(description)
|
||||
# p.update_attribute(:body, new_content)
|
||||
# end
|
||||
# puts "__update_pull_request_content_____id:#{p.id}__"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
def change_content(content)
|
||||
puts "####________content_____######{content}"
|
||||
new_content = ""
|
||||
return "" if content.blank?
|
||||
desc = JSON.parse(content)["ops"]
|
||||
if desc.length > 0
|
||||
desc.each do |d|
|
||||
image = d["insert"]["image"]
|
||||
if image.present?
|
||||
new_content += "![#{image['alt']}](#{image['url']})"
|
||||
else
|
||||
new_content += d["insert"].gsub("\n", "")
|
||||
end
|
||||
end
|
||||
end
|
||||
new_content
|
||||
end
|
||||
# def change_content(content)
|
||||
# puts "####________content_____######{content}"
|
||||
# new_content = ""
|
||||
# return "" if content.blank?
|
||||
# desc = JSON.parse(content)["ops"]
|
||||
# if desc.length > 0
|
||||
# desc.each do |d|
|
||||
# image = d["insert"]["image"]
|
||||
# if image.present?
|
||||
# new_content += "![#{image['alt']}](#{image['url']})"
|
||||
# else
|
||||
# new_content += d["insert"].gsub("\n", "")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# new_content
|
||||
# end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,6 @@
|
|||
class AddColumnsToProjects < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :projects, :license_id, :integer
|
||||
add_column :projects, :ignore_id, :integer
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
class CreateSonarqubes < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :sonarqubes do |t|
|
||||
t.integer :loophole, :default => 0
|
||||
t.integer :repetition_rate, :default => 0
|
||||
t.integer :bug_num, :default => 0
|
||||
t.integer :file_num, :default => 0
|
||||
t.integer :project_id
|
||||
t.integer :branch_name
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
class ChangeBranchNameTypeToSonarqube < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column :sonarqubes, :branch_name, :string
|
||||
end
|
||||
end
|
||||
|
|
@ -15,15 +15,27 @@ namespace :sync_data_to_gitea do
|
|||
next unless regx.match user.mail
|
||||
|
||||
tmp_password = set_password
|
||||
user_params = {
|
||||
username: user.login,
|
||||
email: user.mail,
|
||||
password: tmp_password
|
||||
}
|
||||
|
||||
gitea_user = Gitea::User::RegisterService.new(user_params).call
|
||||
result = Gitea::User::GenerateTokenService.new(user.login, tmp_password).call
|
||||
user.update_columns(gitea_token: result['sha1'], gitea_uid: gitea_user['id'])
|
||||
# TODO: Educoder sync
|
||||
interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: tmp_password})
|
||||
if interactor.success?
|
||||
gitea_user = interactor.result
|
||||
result = Gitea::User::GenerateTokenService.call(user.login, tmp_password)
|
||||
user.update_columns(gitea_token: result['sha1'], gitea_uid: gitea_user[:body]['id'])
|
||||
else
|
||||
puts "#################【Gitea: 用户同步失败: #{interactor.error} #################"
|
||||
end
|
||||
|
||||
# TODO: Trustie sync
|
||||
# user_params = {
|
||||
# username: user.login,
|
||||
# email: user.mail,
|
||||
# password: tmp_password
|
||||
# }
|
||||
#
|
||||
# gitea_user = Gitea::User::RegisterService.new(user_params).call
|
||||
# result = Gitea::User::GenerateTokenService.new(user.login, tmp_password).call
|
||||
# user.update_columns(gitea_token: result['sha1'], gitea_uid: gitea_user['id'])
|
||||
rescue Exception => e
|
||||
Rails.logger.error e
|
||||
next
|
||||
|
|
|
|||
Loading…
Reference in New Issue