242 lines
6.4 KiB
Ruby
242 lines
6.4 KiB
Ruby
require "sequel"
|
||
|
||
cfg_internal = IniConfig.new()
|
||
Sequel.connect(cfg_internal.get_db)
|
||
|
||
class Repos < Sequel::Model(:repos)
|
||
end
|
||
|
||
class Recips < Sequel::Model(:recips)
|
||
end
|
||
|
||
class RepocRecips < Sequel::Model(:repos_recips)
|
||
end
|
||
|
||
class Projects < Sequel::Model(:projects)
|
||
end
|
||
|
||
class ReposProjects < Sequel::Model(:repos_projects)
|
||
end
|
||
|
||
class ProjectsReposSpec < Sequel::Model(:projects_repos_spec)
|
||
end
|
||
|
||
class ProjectsProjects < Sequel::Model(:projects_projects)
|
||
end
|
||
|
||
class BuildTask < Sequel::Model(:buildtask)
|
||
end
|
||
|
||
class DBase
|
||
attr :error, :last_id
|
||
|
||
def creategit(project_name, description)
|
||
@error = nil
|
||
data = Repos.where(reponame: project_name).first
|
||
if data.nil?
|
||
id = Repos.insert(reponame: project_name, descr: description, public: 1)
|
||
@last_id = id
|
||
else
|
||
@error = "Данный репозиторий уже существует"
|
||
end
|
||
@error
|
||
end
|
||
|
||
def get_repo_info_by_name(repo_name)
|
||
Repos.where(reponame: repo_name).first
|
||
end
|
||
|
||
def get_repo_info_by_id(id)
|
||
Repos[id]
|
||
end
|
||
|
||
def get_recips()
|
||
result = []
|
||
Recips.order(:id).map do |item|
|
||
{ :fname => item[:filepath], :descr => item[:descr], :id => item[:id] }
|
||
end
|
||
end
|
||
|
||
def delete_repo_by_name(repo_name)
|
||
rep_id = Repos.where(reponame: repo_name).first
|
||
unless rep_id[:id].nil?
|
||
id = rep_id[:id]
|
||
RepocRecips.where(repo_id: id).delete
|
||
ReposProjects.where(repo_id: id).delete
|
||
end
|
||
end
|
||
|
||
def createrecip(filepath, description, codedata, gitlist)
|
||
error_data = nil
|
||
filepath_san = sanitize_rcptname(filepath)
|
||
is_data = Recips.where(filepath: filepath_san).first
|
||
if codedata.nil? || codedata.strip == ""
|
||
error_data
|
||
else
|
||
if is_data.nil?
|
||
id = Recips.insert(filepath: filepath_san, descr: description, content: codedata)
|
||
@last_id = id
|
||
if !gitlist.nil? && gitlist.length > 0
|
||
gitlist.each do |item|
|
||
data = Repos.where(id: item.to_i).first
|
||
unless data.nil?
|
||
RepocRecips.insert(repo_id: data[:id], recip_id: id)
|
||
end
|
||
end
|
||
end
|
||
error_data
|
||
else
|
||
"Рецепт с таким именем #{filepath_san} уже существует"
|
||
end
|
||
end
|
||
end
|
||
|
||
def updaterecip(id, filepath, description, codedata, gitlist)
|
||
error_data = nil
|
||
filepath_san = sanitize_rcptname(filepath)
|
||
is_data = Recips.where(filepath: filepath_san).first
|
||
if codedata.nil? || codedata.strip == ""
|
||
error_data
|
||
else
|
||
unless is_data.nil?
|
||
Recips.where(id: id.to_i).update(filepath: filepath_san, descr: description, content: codedata)
|
||
RepocRecips.where(recip_id: id.to_i).delete
|
||
if !gitlist.nil? && gitlist.length > 0
|
||
gitlist.each do |item|
|
||
data = Repos.where(id: item.to_i).first
|
||
unless data.nil?
|
||
RepocRecips.insert(repo_id: data[:id], recip_id: id)
|
||
end
|
||
end
|
||
end
|
||
error_data
|
||
else
|
||
"Рецепт с таким именем #{filepath_san} не существует"
|
||
end
|
||
end
|
||
end
|
||
|
||
def get_rcp_info_by_id(rcpi_id)
|
||
info = Recips[rcpi_id.to_i]
|
||
gits = RepocRecips.where(recip_id: info[:id])
|
||
info[:repos_list] = gits.map { |item| item[:repo_id].to_s }
|
||
info
|
||
end
|
||
|
||
def delete_rcp(id)
|
||
RepocRecips.where(recip_id: id.to_i).delete
|
||
Recips.where(id: id.to_i).delete
|
||
end
|
||
|
||
def proj_list
|
||
Projects.order(:id).all
|
||
end
|
||
|
||
def proj(id)
|
||
Projects[id]
|
||
end
|
||
|
||
def proj_create(proj_name, proj_descr)
|
||
@error = nil
|
||
data = Projects.where(projname: proj_name).first
|
||
if data.nil?
|
||
id = Projects.insert(projname: proj_name, descr: proj_descr, public: 1)
|
||
@last_id = id
|
||
else
|
||
@error = "Данный проект уже существует"
|
||
end
|
||
@error
|
||
end
|
||
|
||
def get_gits_for_projects(id)
|
||
result = []
|
||
git_list = ReposProjects.where(proj_id: id.to_i).all
|
||
unless git_list.nil?
|
||
result = git_list.map do |item|
|
||
Repos[item[:repo_id]]
|
||
end.reject do |item|
|
||
item.nil?
|
||
end
|
||
end
|
||
result
|
||
end
|
||
|
||
def save_git_project(prj_id, git_id)
|
||
result = ReposProjects.where(proj_id: prj_id, repo_id: git_id).first
|
||
if result.nil?
|
||
id = ReposProjects.insert(proj_id: prj_id, repo_id: git_id)
|
||
@last_id = id
|
||
end
|
||
end
|
||
|
||
def get_project_repo_spec(prj_id, git_id)
|
||
ProjectsReposSpec.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).first
|
||
end
|
||
|
||
def save_project_repo_spec(prj_id, git_id, spec)
|
||
rep = ProjectsReposSpec.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).first
|
||
if rep.nil?
|
||
id = ProjectsReposSpec.insert(proj_id: prj_id.to_i, repo_id: git_id.to_i, spec_name: spec)
|
||
@last_id = id
|
||
else
|
||
ProjectsReposSpec.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).update(spec_name: spec)
|
||
@last_id = nil
|
||
end
|
||
end
|
||
|
||
def delete_project_repo_spec(prj_id, git_id)
|
||
ProjectsReposSpec.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).delete
|
||
end
|
||
|
||
def get_projects_links(prj_id)
|
||
ProjectsProjects.where(proj_id: prj_id.to_i).all
|
||
end
|
||
|
||
def delete_linked_projects(prj_id)
|
||
ProjectsProjects.where(proj_id: prj_id.to_i).delete
|
||
end
|
||
|
||
def delete_linked_projects_with_id(prj_id, prj_id_link)
|
||
ProjectsProjects.where(proj_id: prj_id.to_i, proj_id_repository: prj_id_link.to_i).delete
|
||
end
|
||
|
||
def save_linked_projects(prj_id, prj_id_link)
|
||
item = ProjectsProjects.where(proj_id: prj_id.to_i, proj_id_repository: prj_id_link.to_i).first
|
||
if item.nil?
|
||
id = ProjectsProjects.insert(proj_id: prj_id.to_i, proj_id_repository: prj_id_link.to_i)
|
||
@last_id = id
|
||
end
|
||
end
|
||
|
||
def get_git_recips(git_id)
|
||
res = []
|
||
recip = RepocRecips.where(repo_id: git_id.to_i).all
|
||
unless recip.nil?
|
||
res = recip.map do |item|
|
||
rcp_info = Recips[item[:recip_id]]
|
||
rcp_info
|
||
end
|
||
end
|
||
res
|
||
end
|
||
|
||
#result = 0 (in progress), 1 (stopped - error), 2 (stopped - success)
|
||
def create_build_task(prj_id, git_id, proj_path)
|
||
id = BuildTask.insert(repo_id: git_id.to_i, proj_id: prj_id.to_i, signpath: "", logpath: "", errlogpath: "", result: 0)
|
||
@last_id = id
|
||
BuildTask.where(id: id).update(logpath: File.join(proj_path, "#{id}"))
|
||
end
|
||
|
||
def update_build_task_status(build_id, status)
|
||
BuildTask.where(id: build_id.to_i).update(result: status.to_i)
|
||
end
|
||
|
||
def update_build_task_error_log(build_id, path)
|
||
BuildTask.where(id: build_id.to_i).update(errlogpath: path)
|
||
end
|
||
|
||
def get_build_task_process_log(build_id)
|
||
BuildTask.where(id: build_id.to_i).first
|
||
end
|
||
end
|