Merge pull request '代码仓库同步部分代码' (#282) from reposync_feature into standalone_develop

This commit is contained in:
2024-05-10 15:05:04 +08:00
33 changed files with 952 additions and 5 deletions

View File

@@ -55,14 +55,13 @@
# default_branch :string(255) default("master")
# website :string(255)
# lesson_url :string(255)
# use_blockchain :boolean default("0")
# is_pinned :boolean default("0")
# recommend_index :integer default("0")
# use_blockchain :boolean default("0")
# pr_view_admin :boolean default("0")
#
# Indexes
#
# index_projects_on_forked_count (forked_count)
# index_projects_on_forked_from_project_id (forked_from_project_id)
# index_projects_on_identifier (identifier)
# index_projects_on_invite_code (invite_code)
@@ -72,7 +71,6 @@
# index_projects_on_license_id (license_id)
# index_projects_on_name (name)
# index_projects_on_platform (platform)
# index_projects_on_praises_count (praises_count)
# index_projects_on_project_category_id (project_category_id)
# index_projects_on_project_language_id (project_language_id)
# index_projects_on_project_type (project_type)
@@ -80,7 +78,6 @@
# index_projects_on_rgt (rgt)
# index_projects_on_status (status)
# index_projects_on_updated_on (updated_on)
# index_projects_on_user_id (user_id)
#
class Project < ApplicationRecord
@@ -140,6 +137,7 @@ class Project < ApplicationRecord
has_many :commit_logs, dependent: :destroy
has_many :daily_project_statistics, dependent: :destroy
has_one :project_dataset, dependent: :destroy
has_many :sync_repositories, dependent: :destroy
after_create :incre_user_statistic, :incre_platform_statistic
after_save :check_project_members
before_save :set_invite_code, :reset_unmember_followed, :set_recommend_and_is_pinned, :reset_cache_data

View File

@@ -0,0 +1,22 @@
# == Schema Information
#
# Table name: sync_repositories
#
# id :integer not null, primary key
# project_id :integer
# type :string(255)
# repo_name :string(255)
# external_repo_address :string(255)
# sync_granularity :integer
# sync_direction :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_sync_repositories_on_project_id (project_id)
#
class SyncRepositories::Gitee < SyncRepository
end

View File

@@ -0,0 +1,21 @@
# == Schema Information
#
# Table name: sync_repositories
#
# id :integer not null, primary key
# project_id :integer
# type :string(255)
# repo_name :string(255)
# external_repo_address :string(255)
# sync_granularity :integer
# sync_direction :integer
# created_at :datetime not null
# updated_at :datetime not null
#
# Indexes
#
# index_sync_repositories_on_project_id (project_id)
#
class SyncRepositories::Github < SyncRepository
end

View File

@@ -0,0 +1,35 @@
# == Schema Information
#
# Table name: sync_repositories
#
# id :integer not null, primary key
# project_id :integer
# type :string(255)
# repo_name :string(255)
# external_repo_address :string(255)
# sync_granularity :integer
# sync_direction :integer
# created_at :datetime not null
# updated_at :datetime not null
# external_token :string(255)
# webhook_gid :integer
#
# Indexes
#
# index_sync_repositories_on_project_id (project_id)
#
class SyncRepository < ApplicationRecord
belongs_to :project
has_many :sync_repository_branches, dependent: :destroy
before_destroy :unbind_reposyncer
validates :repo_name, uniqueness: { message: "已存在" }
def unbind_reposyncer
Reposync::DeleteRepoService.call(self.repo_name) rescue nil
end
end

View File

@@ -0,0 +1,38 @@
# == Schema Information
#
# Table name: sync_repository_branches
#
# id :integer not null, primary key
# sync_repository_id :integer
# gitlink_branch_name :string(255)
# external_branch_name :string(255)
# sync_time :datetime
# sync_status :integer default("0")
# reposync_branch_id :integer
# created_at :datetime not null
# updated_at :datetime not null
# enable :boolean default("1")
#
# Indexes
#
# index_sync_repository_branches_on_sync_repository_id (sync_repository_id)
#
class SyncRepositoryBranch < ApplicationRecord
belongs_to :sync_repository
before_destroy :unbind_reposyncer
enum sync_status: {success: 1, failure: 2}
def unbind_reposyncer
if self.sync_repository.sync_direction.to_i == 1
Reposync::DeleteBranchService.call(self.sync_repository&.repo_name, self.gitlink_branch_name) rescue nil
else
Reposync::DeleteBranchService.call(self.sync_repository&.repo_name, self.external_branch_name) rescue nil
end
end
end