First tests

This commit is contained in:
alexey
2025-03-18 00:10:53 +03:00
parent ecf3d47392
commit 4cc0477e39
4 changed files with 105 additions and 7 deletions

View File

@@ -307,7 +307,7 @@ class DBase
end
def get_builds()
$DDB["select t1.id as buildid, t1.create_at as createat, t1.result as state, t2.reponame as reponame, t2.id as gitid, t3.id as projid, t3.projname as prjname, count(*) as pkgcnt from buildtask as t1 join repos as t2 on t1.repo_id = t2.id join projects as t3 on t1.proj_id = t3.id join build_rpm as t4 on t4.build_id = t1.id group by buildid, createat, state, reponame, projid, prjname, gitid order by t1.id"].all
$DDB["select t1.id as buildid, t1.create_at as createat, t1.result as state, t2.reponame as reponame, t2.id as gitid, t3.id as projid, t3.projname as prjname, count(*) as pkgcnt from buildtask as t1 join repos as t2 on t1.repo_id = t2.id join projects as t3 on t1.proj_id = t3.id left join build_rpm as t4 on t4.build_id = t1.id group by buildid, createat, state, reponame, projid, prjname, gitid order by t1.id"].all
end
def get_build_info(build_id)
@@ -328,19 +328,30 @@ class DBase
end
def get_builds_for_project(prj_id)
$DDB["select t1.id as buildid, t1.create_at as createat, t1.result as state, t2.reponame as reponame, t2.id as gitid, t3.id as projid, t3.projname as prjname, count(*) as pkgcnt from buildtask as t1 join repos as t2 on t1.repo_id = t2.id join projects as t3 on t1.proj_id = t3.id join build_rpm as t4 on t4.build_id = t1.id where t1.proj_id = ? group by buildid, createat, state, reponame, projid, prjname, gitid order by t1.id", prj_id.to_i].all
$DDB["select t1.id as buildid, t1.create_at as createat, t1.result as state, t2.reponame as reponame, t2.id as gitid, t3.id as projid, t3.projname as prjname, count(*) as pkgcnt from buildtask as t1 join repos as t2 on t1.repo_id = t2.id join projects as t3 on t1.proj_id = t3.id left join build_rpm as t4 on t4.build_id = t1.id where t1.proj_id = ? group by buildid, createat, state, reponame, projid, prjname, gitid order by t1.id", prj_id.to_i].all
end
def get_builds_for_project_git(prj_id, git_id)
$DDB["select t1.id as buildid, t1.create_at as createat, t1.result as state, t2.reponame as reponame, t2.id as gitid, t3.id as projid, t3.projname as prjname, count(*) as pkgcnt from buildtask as t1 join repos as t2 on t1.repo_id = t2.id join projects as t3 on t1.proj_id = t3.id join build_rpm as t4 on t4.build_id = t1.id where t1.proj_id = ? and t1.repo_id = ? group by buildid, createat, state, reponame, projid, prjname, gitid order by t1.id", prj_id.to_i, git_id.to_i].all
end
def get_builds_for_project_git_rpm(prj_id, git_id)
$DDB["select t3.savepath, t3.signpath, t3.sign from buildtask as t1 join build_rpm as t2 on t2.build_id = t1.id join rpms as t3 on t3.id = t2.rpm_id where t1.proj_id = ? and t1.repo_id = ?", prj_id.to_i, git_id.to_i].all
$DDB["select t1.id as buildid, t1.create_at as createat, t1.result as state, t2.reponame as reponame, t2.id as gitid, t3.id as projid, t3.projname as prjname, count(*) as pkgcnt from buildtask as t1 join repos as t2 on t1.repo_id = t2.id join projects as t3 on t1.proj_id = t3.id left join build_rpm as t4 on t4.build_id = t1.id where t1.proj_id = ? and t1.repo_id = ? group by buildid, createat, state, reponame, projid, prjname, gitid order by t1.id", prj_id.to_i, git_id.to_i].all
end
def delete_git_from_project(prj_id, git_id)
ReposProjects.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).delete
ProjectsReposSpec.where(proj_id: prj_id.to_i, repo_id: git_id.to_i).delete
end
def delete_project(prj_id)
ReposProjects.where(proj_id: prj_id.to_i).delete
ProjectsReposSpec.where(proj_id: prj_id.to_i).delete
builds = BuildTask.where(proj_id: prj_id.to_i)
build.each do |item|
rpms = BuildRpms.where(build_id: item[:id])
Rpms.where(id: rpms[:rpm_id]).delete
end
BuildTask.where(proj_id: prj_id.to_i).delete
end
def projects_with_current_as_link(prj_id)
ProjectsProjects.where(proj_id_repository: prj_id.to_i).all
end
end

View File

@@ -333,6 +333,7 @@ class ProjectsActions
if active_build
@error = "Нельзя удалить git репозиторий с незавершенными сборками"
else
proj_path = get_project_path(prj_id)
git_name = @db.get_repo_info_by_id(git_id)
git_source = File.join(proj_path, PROJECTS_STRUCTURE[:SRC], git_name[:reponame])
FileUtils.rm_rf(git_source, secure: true)
@@ -340,4 +341,29 @@ class ProjectsActions
end
@error
end
def delete_project(prj_id)
@error = nil
builds_lst = db.get_builds_for_project(prj_id)
active_build = false
builds_lst.each do |item|
if item[:state] == 0
active_build = true
break
end
end
if active_build
@error = "Нельзя удалить git репозиторий с незавершенными сборками"
else
linked = @db.projects_with_current_as_link(prj_id)
if linked.nil?
proj_path = get_project_path(prj_id)
FileUtils.rm_rf(proj_path, secure: true)
@db.delete_project(prj_id, git_id)
else
@error = "На текущий проект ссылаются другие проекты. Удаление запрещено"
end
end
@error
end
end