Added git information

This commit is contained in:
alexey
2025-02-20 00:15:26 +03:00
parent 982ea3322c
commit 895fb918b5
10 changed files with 349 additions and 15 deletions

View File

@@ -59,22 +59,83 @@ class GitRepo
def getrepos
repos_data = []
repos_files = Dir[File.join(@path, "*.git")]
repos_files.each do |fl|
repo_name = File.basename(fl, ".git")
db_info = @db.get_repo_info_by_name(repo_name)
unless db_info.nil?
db_info = db_info.first
repos_data << { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public }
else
result = create_git_db_only(repo_name)
if result.nil?
db_info = @db.get_repo_info_by_name(repo_name)
File.open("locks/gitcreate", "r") do |f|
f.flock(File::LOCK_SH)
repos_files = Dir[File.join(@path, "*.git")]
repos_files.each do |fl|
repo_name = File.basename(fl, ".git")
db_info = @db.get_repo_info_by_name(repo_name)
unless db_info.nil?
db_info = db_info.first
repos_data << { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public }
else
result = create_git_db_only(repo_name)
if result.nil?
db_info = @db.get_repo_info_by_name(repo_name)
db_info = db_info.first
repos_data << { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public }
end
end
end
end
repos_data
end
def repo_info(reponame, branch = nil)
info = {}
result = ""
@error = nil
repos_data = { :full => 0 }
git_path = File.join(@path, reponame + ".git")
File.open("locks/gitcreate", "r") do |f|
f.flock(File::LOCK_SH)
if File.exist?(git_path)
repo = Rugged::Repository.new(git_path)
db_info = @db.get_repo_info_by_name(reponame)
unless db_info.nil?
db_info = db_info.first
repos_data = { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public, :full => 1 }
else
result = create_git_db_only(reponame)
if result.nil?
db_info = @db.get_repo_info_by_name(reponame)
db_info = db_info.first
repos_data = { :reponame => db_info.reponame, :descr => db_info.descr, :public => db_info.public, :full => 1 }
end
end
if repos_data[:full] == 1
info[:info] = repos_data
if repo.empty?
info[:commits] = []
info[:branches] = []
info[:tags] = []
else
ref = repo.head
unless branch.nil?
ref_name = File.join("refs/heads/", branch)
ref = repo.references[ref_name]
end
commits = []
unless ref.nil?
walker = Rugged::Walker.new(repo)
walker.sorting(Rugged::SORT_DATE)
walker.push(ref.target)
commits = walker.map do |commit|
{ :message => commit.message, :author => commit.author, :time => commit.time, :sha => commit.oid }
end.first(10)
end
info[:commits] = commits
info[:branches] = repo.branches.each_name(:local).sort
info[:tags] = repo.tags.map { |tag| tag.name }
end
else
@error = result
end
else
@error = "Репозиторий отсутсвует"
end
end
info[:error] = @error
info
end
end

10
classes/systeminfo.rb Normal file
View File

@@ -0,0 +1,10 @@
require "socket"
require "etc"
def systeminfo_get_ip
Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
end
def systeminfo_get_username
Etc.getpwuid(Process.uid).name
end