From caa7acc654a80eaef130b849183f43c3359fd9cc Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 22 May 2024 11:05:40 +0800 Subject: [PATCH 01/24] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=BC=80?= =?UTF-8?q?=E6=BA=90=E5=A4=A7=E8=B5=9B=E6=88=98=E9=98=9F=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E8=87=B3gitlink?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gitlink_competition_applies_controller.rb | 37 +++++++++++++++++++ app/models/gitlink_competition_apply.rb | 21 +++++++++++ config/routes/api.rb | 1 + ...5212_create_gitlink_competition_applies.rb | 19 ++++++++++ spec/models/gitlink_competition_apply_spec.rb | 5 +++ 5 files changed, 83 insertions(+) create mode 100644 app/controllers/api/v1/gitlink_competition_applies_controller.rb create mode 100644 app/models/gitlink_competition_apply.rb create mode 100644 db/migrate/20240522015212_create_gitlink_competition_applies.rb create mode 100644 spec/models/gitlink_competition_apply_spec.rb diff --git a/app/controllers/api/v1/gitlink_competition_applies_controller.rb b/app/controllers/api/v1/gitlink_competition_applies_controller.rb new file mode 100644 index 000000000..5f2d7ef28 --- /dev/null +++ b/app/controllers/api/v1/gitlink_competition_applies_controller.rb @@ -0,0 +1,37 @@ +class Api::V1::GitlinkCompetitionAppliesController < Api::V1::BaseController + + def create + return render_error("请输入正确的竞赛ID") unless params[:competition_id].present? + return render_error("请输入正确的队伍ID") unless params[:team_id].present? + return render_error("请输入正确的队伍成员信息") unless params[:team_members].is_a?(Array) + params[:team_members].each do |member| + apply = GitlinkCompetitionApply.find_or_create_by(competition_id: params[:competition_id], team_id: params[:team_id], educoder_login: member[:login]) + apply.competition_identifier = params[:competition_identifier] + apply.team_name = params[:team_name] + apply.school_name = member[:school_name] + apply.nickname = member[:nickname] + apply.identity = member[:identity] + apply.role = member[:role] + apply.email = member[:email] + user_info = get_user_info_by_educoder_login(member[:login]) + apply.phone = user_info["phone"] + apply.save + end + render_ok + end + + def get_user_info_by_educoder_login(edu_login) + req_params = { "login" => "#{edu_login}", "private_token" => "hriEn3UwXfJs3PmyXnqQ" } + api_url= "https://data.educoder.net" + client = Faraday.new(url: api_url) + response = client.public_send("get", "/api/sources/get_user_info_by_login", req_params) + result = JSON.parse(response.body) + + return nil if result["status"].to_s != "0" + + # login 邮箱 手机号 姓名 学校/单位 + user_info = result["data"] + + return user_info + end +end \ No newline at end of file diff --git a/app/models/gitlink_competition_apply.rb b/app/models/gitlink_competition_apply.rb new file mode 100644 index 000000000..f3b7d4ce1 --- /dev/null +++ b/app/models/gitlink_competition_apply.rb @@ -0,0 +1,21 @@ + # == Schema Information +# +# Table name: gitlink_competition_applies +# +# id :integer not null, primary key +# competition_id :integer +# competition_identifier :string(255) +# team_id :integer +# team_name :string(255) +# school_name :string(255) +# login :string(255) +# nickname :string(255) +# phone :string(255) +# identity :string(255) +# role :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# + +class GitlinkCompetitionApply < ApplicationRecord +end diff --git a/config/routes/api.rb b/config/routes/api.rb index b502a679e..59d061629 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -159,6 +159,7 @@ defaults format: :json do resources :projects, only: [:index] resources :project_topics, only: [:index, :create, :destroy] resources :project_datasets, only: [:index] + resources :gitlink_competition_applies, only: [:create] end end diff --git a/db/migrate/20240522015212_create_gitlink_competition_applies.rb b/db/migrate/20240522015212_create_gitlink_competition_applies.rb new file mode 100644 index 000000000..6f24a0922 --- /dev/null +++ b/db/migrate/20240522015212_create_gitlink_competition_applies.rb @@ -0,0 +1,19 @@ +class CreateGitlinkCompetitionApplies < ActiveRecord::Migration[5.2] + def change + create_table :gitlink_competition_applies do |t| + t.integer :competition_id + t.string :competition_identifier + t.integer :team_id + t.string :team_name + t.string :school_name + t.string :educoder_login + t.string :nickname + t.string :phone + t.string :email + t.string :identity + t.string :role + + t.timestamps + end + end +end diff --git a/spec/models/gitlink_competition_apply_spec.rb b/spec/models/gitlink_competition_apply_spec.rb new file mode 100644 index 000000000..8b05ff4ad --- /dev/null +++ b/spec/models/gitlink_competition_apply_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe GitlinkCompetitionApply, type: :model do + pending "add some examples to (or delete) #{__FILE__}" +end From 572a6de2ad823db9e71ff7633613e89d9cacc12c Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 28 May 2024 15:55:22 +0800 Subject: [PATCH 02/24] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9Aactions?= =?UTF-8?q?=E9=87=8D=E6=96=B0=E8=BF=90=E8=A1=8C=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 2 +- .../v1/projects/actions/runs_controller.rb | 34 +++++++++++++++++++ config/routes/api.rb | 3 ++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index edaae8a75..811fabc41 100644 --- a/Gemfile +++ b/Gemfile @@ -141,4 +141,4 @@ gem 'doorkeeper' gem 'doorkeeper-jwt' -gem 'gitea-client', '~> 1.4.6' +gem 'gitea-client', '~> 1.5.7' diff --git a/app/controllers/api/v1/projects/actions/runs_controller.rb b/app/controllers/api/v1/projects/actions/runs_controller.rb index 05918dbe2..ff7c28e85 100644 --- a/app/controllers/api/v1/projects/actions/runs_controller.rb +++ b/app/controllers/api/v1/projects/actions/runs_controller.rb @@ -5,8 +5,42 @@ class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::B puts @result_object end + def rerun + return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank? + gitea_result = $gitea_hat_client.post_repos_actions_runs_rerun_by_owner_repo_run(@project&.owner&.login, @project&.identifier, params[:run_id]) rescue nil + if gitea_result + render_ok + else + render_error("重启所有流水线任务失败") + end + end + + def job_rerun + return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank? + return render_error("请输入正确的流水线任务ID") if params[:job].blank? + gitea_result = $gitea_hat_client.post_repos_actions_runs_jobs_rerun_by_owner_repo_run_job(@project&.owner&.login, @project&.identifier, params[:run_id], params[:job]) rescue nil + if gitea_result + render_ok + else + render_error("重启流水线任务失败") + end + end + def job_show @result_object = Api::V1::Projects::Actions::Runs::JobShowService.call(@project, params[:run_id], params[:job], params[:log_cursors], current_user&.gitea_token) end + def job_logs + return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank? + return render_error("请输入正确的流水线任务ID") if params[:job].blank? + domain = GiteaService.gitea_config[:domain] + api_url = GiteaService.gitea_config[:hat_base_url] + + url = "/repos/#{@owner.login}/#{@repository.identifier}/actions/runs/#{CGI.escape(params[:run_id])}/jobs/#{CGI.escape(params[:job])}/logs" + file_path = [domain, api_url, url].join + file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("?") + + redirect_to file_path + end + end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index 59d061629..34751cf50 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -96,6 +96,9 @@ defaults format: :json do post :enable resources :runs, only: [:index] do post '/jobs/:job', to: 'runs#job_show' + post '/rerun', to: 'runs#rerun' + post '/jobs/:job/rerun', to: 'runs#job_rerun' + get '/jobs/:job/logs', to: 'runs#job_logs' end end end From 4c8286385190b4f104f02b97172251c642703cde Mon Sep 17 00:00:00 2001 From: xxq250 Date: Fri, 31 May 2024 14:20:50 +0800 Subject: [PATCH 03/24] =?UTF-8?q?org=20=E5=AE=B9=E9=94=99get=5Fletter=5Fav?= =?UTF-8?q?atar=5Furl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/organization.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/models/organization.rb b/app/models/organization.rb index f978611b1..faa6396df 100644 --- a/app/models/organization.rb +++ b/app/models/organization.rb @@ -216,4 +216,9 @@ class Organization < Owner ids.uniq.size end + # user容错处理 + def get_letter_avatar_url + "" + end + end From c58ca88edd7b180683b766c1f23109f2f19bb290 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 3 Jun 2024 10:36:31 +0800 Subject: [PATCH 04/24] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E9=A1=B9=E7=9B=AE=E7=9B=B8=E5=85=B3=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/projects_controller.rb | 2 +- app/controllers/projects_controller.rb | 21 ++++++++++++++++++- app/jobs/check_mirror_job.rb | 2 +- app/jobs/migrate_remote_repository_job.rb | 13 +++++++++++- .../gitea/repository/delete_service.rb | 7 ++++--- 5 files changed, 38 insertions(+), 7 deletions(-) diff --git a/app/controllers/admins/projects_controller.rb b/app/controllers/admins/projects_controller.rb index dc3f6030a..926ab8a29 100644 --- a/app/controllers/admins/projects_controller.rb +++ b/app/controllers/admins/projects_controller.rb @@ -32,7 +32,7 @@ class Admins::ProjectsController < Admins::BaseController def destroy project = Project.find_by!(id: params[:id]) ActiveRecord::Base.transaction do - Gitea::Repository::DeleteService.new(project.owner, project.identifier).call + Gitea::Repository::DeleteService.new(project.owner, project.identifier, current_user.gitea_token).call project.destroy! # render_delete_success UserAction.create(action_id: project.id, action_type: "DestroyProject", user_id: current_user.id, :ip => request.remote_ip, data_bank: project.attributes.to_json) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index d7a0396a1..e57826f3c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -255,7 +255,7 @@ class ProjectsController < ApplicationController def destroy if current_user.admin? || @project.manager?(current_user) ActiveRecord::Base.transaction do - Gitea::Repository::DeleteService.new(@project.owner, @project.identifier).call + Gitea::Repository::DeleteService.new(@project.owner, @project.identifier,current_user.gitea_token).call @project.destroy! @project.forked_projects.update_all(forked_from_project_id: nil) # 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量 @@ -305,6 +305,25 @@ class ProjectsController < ApplicationController end def simple + if !@project.common? && @project&.repository&.mirror&.waiting? + gitea_result = $gitea_client.get_repos_by_owner_repo(@project&.owner&.login, @project&.identifier) + if !gitea_result["empty"] + @project&.update_columns(gpid: gitea_result["id"]) + @project&.repository&.mirror&.succeeded! + project_id = @project&.id + user_id = @project&.owner&.id + puts "############ mirror project_id,user_id: #{project_id},#{user_id} ############" + OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(project_id, user_id) if project_id.present? && user_id.present? + UpdateProjectTopicJob.set(wait: 1.seconds).perform_later(project_id) if project_id.present? + puts "############ mirror status: #{repo.mirror.status} ############" + end + elsif !@project.common? && @project&.repository&.mirror&.failed? + Gitea::Repository::DeleteService.new(@project.owner, @project.identifier,current_user.gitea_token).call + @project.destroy! + @project.forked_projects.update_all(forked_from_project_id: nil) + # 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量 + @project.project_category.decrement!(:private_projects_count, 1) if @project.project_category.present? && !@project.is_public + end # 为了缓存活跃项目的基本信息,后续删除 Cache::V2::ProjectCommonService.new(@project.id).read # 项目名称,标识,所有者变化时重置缓存 diff --git a/app/jobs/check_mirror_job.rb b/app/jobs/check_mirror_job.rb index 9854110b8..7de7cbd1b 100644 --- a/app/jobs/check_mirror_job.rb +++ b/app/jobs/check_mirror_job.rb @@ -11,7 +11,7 @@ class CheckMirrorJob < ApplicationJob unless response.present? SyncLog.sync_log("==========check_project_error_id:#{project.id}============") ActiveRecord::Base.transaction do - delete_gitea = Gitea::Repository::DeleteService.new(project.owner, project.identifier).call + delete_gitea = Gitea::Repository::DeleteService.new(project.owner, project.identifier, project.owner.gitea_token).call if delete_gitea.status == 204 || delete_gitea.status == 404 #删除成功或者仓库不存在,都重新创建 repository_params= { name: project.identifier, diff --git a/app/jobs/migrate_remote_repository_job.rb b/app/jobs/migrate_remote_repository_job.rb index 2493bff01..cc3cdf4a9 100644 --- a/app/jobs/migrate_remote_repository_job.rb +++ b/app/jobs/migrate_remote_repository_job.rb @@ -19,7 +19,18 @@ class MigrateRemoteRepositoryJob < ApplicationJob UpdateProjectTopicJob.set(wait: 1.seconds).perform_later(project_id) if project_id.present? puts "############ mirror status: #{repo.mirror.status} ############" else - repo&.mirror&.failed! + gitea_result = $gitea_client.get_repos_by_owner_repo(repo&.project&.owner&.login, repo&.project&.identifier) + if gitea_result["empty"] + repo&.mirror&.failed! + else + repo&.project&.update_columns(gpid: gitea_result["id"]) + repo&.mirror&.succeeded! + project_id = repo&.project&.id + puts "############ mirror project_id,user_id: #{project_id},#{user_id} ############" + OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(project_id, user_id) if project_id.present? && user_id.present? + UpdateProjectTopicJob.set(wait: 1.seconds).perform_later(project_id) if project_id.present? + puts "############ mirror status: #{repo.mirror.status} ############" + end end # UpdateProjectTopicJob 中语言要延迟1S才能获取 BroadcastMirrorRepoMsgJob.set(wait: 1.seconds).perform_later(repo.id) unless repo&.mirror.waiting? diff --git a/app/services/gitea/repository/delete_service.rb b/app/services/gitea/repository/delete_service.rb index eee6ca6d6..c5d5c1b50 100644 --- a/app/services/gitea/repository/delete_service.rb +++ b/app/services/gitea/repository/delete_service.rb @@ -1,9 +1,10 @@ class Gitea::Repository::DeleteService < Gitea::ClientService - attr_reader :user, :repo_name + attr_reader :user, :repo_name, :token - def initialize(user, repo_name) + def initialize(user, repo_name, token=nil) @user = user @repo_name = repo_name + @token = token end def call @@ -13,7 +14,7 @@ class Gitea::Repository::DeleteService < Gitea::ClientService private def params - Hash.new.merge(token: user.gitea_token) + Hash.new.merge(token: token) end def url From 45587ad543c90a4df77d8ca18428a69cd3bad958 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 May 2024 17:50:54 +0800 Subject: [PATCH 05/24] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E6=B4=BB=E8=B7=83=E5=BA=A6=E7=AE=97=E6=B3=95=E5=8F=8A?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/v1/projects/portrait_controller.rb | 52 ++++++++ .../cache/v2/platform_statistic_service.rb | 121 ++++++++++++++++++ config/routes/api.rb | 1 + config/sidekiq_cron.yml | 9 +- 4 files changed, 182 insertions(+), 1 deletion(-) create mode 100644 app/controllers/api/v1/projects/portrait_controller.rb diff --git a/app/controllers/api/v1/projects/portrait_controller.rb b/app/controllers/api/v1/projects/portrait_controller.rb new file mode 100644 index 000000000..e77e7f8e3 --- /dev/null +++ b/app/controllers/api/v1/projects/portrait_controller.rb @@ -0,0 +1,52 @@ +class Api::V1::Projects::PortraitController < Api::V1::BaseController + before_action :require_public_and_member_above + + def index + platform_statistic = $redis_cache.hgetall("v2-platform-statistic") + + # 社区影响力 + praise_count = PraiseTread.where(praise_tread_object_type: "Project", praise_tread_object_id: @project.id).count + watcher_count = Watcher.where(watchable_type:"Project", watchable_id: @project.id).count + fork_count = ForkUser.where(project_id: @project.id).count + community_impact_praise = platform_statistic['max-praise-count'].to_i == 0 ? 0 : 30*(praise_count.to_f/platform_statistic['max-praise-count'].to_i) + community_impact_watcher = platform_statistic['max-watcher-count'].to_i == 0 ? 0 : 30*(watcher_count.to_f/platform_statistic['max-watcher-count'].to_i) + community_impact_fork = platform_statistic['max-fork-count'].to_i == 0 ? 0 : 40*(fork_count.to_f/platform_statistic['max-fork-count'].to_i) + community_impact = community_impact_praise + community_impact_watcher + community_impact_fork + + # 项目成熟度 + pullrequest_count = PullRequest.where(project_id: @project.id).count + issue_count = Issue.issue_issue.where(project_id: @project.id).count + commit_count = CommitLog.joins(:project).merge(Project.common).where(project_id: @project.id).count + project_maturity_pullrequest = platform_statistic['max-pullrequest-count'].to_i == 0 ? 0 : 30*(pullrequest_count.to_f/platform_statistic['max-pullrequest-count'].to_i) + project_maturity_issue = platform_statistic['max-issue-count'].to_i == 0 ? 0 : 30*(issue_count.to_f/platform_statistic['max-issue-count'].to_i) + project_maturity_commit = platform_statistic['max-commit-count'].to_i == 0 ? 0 : 40*(commit_count.to_f/platform_statistic['max-commit-count'].to_i) + project_maturity = project_maturity_pullrequest + project_maturity_issue + project_maturity_commit + + # 项目健康度 + closed_pullrequest_count = PullRequest.where(project_id: @project.id).merged_and_closed.count + closed_issue_count = Issue.issue_issue.where(project_id: @project.id).closed.count + has_license = @project.license.present? ? 1 : 0 + project_health_issue = (issue_count < 10 || closed_issue_count < 10) ? 0 : 40*(closed_issue_count-10).to_f/(issue_count-10) + project_health_pullrequest = (pullrequest_count < 5 || closed_pullrequest_count < 5) ? 0 : 30*(closed_pullrequest_count-5).to_f/(pullrequest_count-5) + project_health_license = 20*has_license + project_health = project_health_issue + project_health_pullrequest + project_health_license + + # 团队影响度 + member_count = Member.where(project_id: @project.id).count + recent_one_month_member_count = Member.where(project_id:@project.id).where("created_on > ?", Time.now - 30.days).count + team_impact_member = platform_statistic['max-member-count'].to_i == 0 ? 0 : 40*(member_count.to_f/platform_statistic['max-member-count'].to_i) + team_impact_recent_member = platform_statistic['max-recent-one-month-member-count'].to_i == 0 ? 0 : 60*(recent_one_month_member_count.to_f/platform_statistic['max-recent-one-month-member-count'].to_i) + team_impact = team_impact_member + team_impact_recent_member + + # 开发活跃度 + recent_one_month_pullrequest_count = PullRequest.where(project_id: @project.id).where("created_at > ?", Time.now - 30.days).count + recent_one_month_issue_count = Issue.issue_issue.where(project_id: @project.id).where("created_on > ?", Time.now - 30.days).count + recent_one_month_commit_count = CommitLog.joins(:project).merge(Project.common).where(project_id: @project.id).where("created_at > ?", Time.now - 30.days).count + develop_activity_pullrequest = platform_statistic['max-recent-one-month-pullrequest-count'].to_i == 0 ? 0 : 20*(recent_one_month_pullrequest_count.to_f/platform_statistic['max-recent-one-month-pullrequest-count'].to_i) + develop_activity_issue = platform_statistic['max-recent-one-month-issue-count'].to_i == 0 ? 0 : 20*(recent_one_month_issue_count.to_f/platform_statistic['max-recent-one-month-issue-count'].to_i) + develop_activity_commit = platform_statistic['max-recent-one-month-commit-count'].to_i == 0 ? 0 : 40*(recent_one_month_commit_count.to_f/platform_statistic['max-recent-one-month-commit-count'].to_i) + develop_activity = 20 + develop_activity_pullrequest + develop_activity_issue + develop_activity_commit + + render :json => {community_impact: community_impact, project_maturity: project_maturity, project_health: project_health, team_impact: team_impact, develop_activity: develop_activity} + end +end \ No newline at end of file diff --git a/app/services/cache/v2/platform_statistic_service.rb b/app/services/cache/v2/platform_statistic_service.rb index 5bf4f4a74..a7d9437a0 100644 --- a/app/services/cache/v2/platform_statistic_service.rb +++ b/app/services/cache/v2/platform_statistic_service.rb @@ -31,6 +31,61 @@ class Cache::V2::PlatformStatisticService < ApplicationService "v2-platform-statistic" end + # 平台最高关注数 + def max_watcher_count_key + "max-watcher-count" + end + + # 平台最高点赞数 + def max_praise_count_key + "max-praise-count" + end + + # 平台最高fork数 + def max_fork_count_key + "max-fork-count" + end + + # 平台最高pr数 + def max_pullrequest_count_key + "max-pullrequest-count" + end + + # 平台最高issue数 + def max_issue_count_key + "max-issue-count" + end + + # 平台最高commit数 + def max_commit_count_key + "max-commit-count" + end + + # 平台最高仓库人数 + def max_member_count_key + "max-member-count" + end + + # 平台近一个月新增成员最大值 + def max_recent_one_month_member_count_key + "max-recent-one-month-member-count" + end + + # 平台近一个月合并请求最大值 + def max_recent_one_month_pullrequest_count_key + "max-recent-one-month-pullrequest-count" + end + + # 平台近一个月issue最大值 + def max_recent_one_month_issue_count_key + "max-recent-one-month-issue-count" + end + + # 平台近一个月commit最大值 + def max_recent_one_month_commit_count_key + "max-recent-one-month-commit-count" + end + def follow_count_key "follow-count" end @@ -136,6 +191,61 @@ class Cache::V2::PlatformStatisticService < ApplicationService $redis_cache.hgetall(platform_statistic_key) end + def reset_platform_max_watcher_count + max_watcher = Watcher.where(watchable_type:"Project").group(:watchable_type, :watchable_id).count.sort_by{|i|i[1]}.last || [] + $redis_cache.hset(platform_statistic_key, max_watcher_count_key, max_watcher[1].nil? ? 0 : max_watcher[1]) + end + + def reset_platform_max_praise_count + max_praise = PraiseTread.where(praise_tread_object_type: "Project").group(:praise_tread_object_type, :praise_tread_object_id).count.sort_by{|i|i[1]}.last || [] + $redis_cache.hset(platform_statistic_key, max_praise_count_key, max_praise[1].nil? ? 0 : max_praise[1]) + end + + def reset_platform_max_fork_count + max_fork = ForkUser.group(:project_id).count.sort_by{|i|i[1]}.last || [] + $redis_cache.hset(platform_statistic_key, max_fork_count_key, max_fork[1].nil? ? 0 : max_fork[1]) + end + + def reset_platform_max_pullrequest_count + max_pullrequest = PullRequest.group(:project_id).count.sort_by{|i|i[1]}.last || [] + $redis_cache.hset(platform_statistic_key, max_pullrequest_count_key, max_pullrequest[1].nil? ? 0 : max_pullrequest[1]) + end + + def reset_platform_max_issue_count + max_issue = Issue.issue_issue.group(:project_id).count.sort_by{|i|i[1]}.last || [] + $redis_cache.hset(platform_statistic_key, max_issue_count_key, max_issue[1].nil? ? 0 : max_issue[1]) + end + + def reset_platform_max_commit_count + max_commit = CommitLog.joins(:project).merge(Project.common).group(:project_id).count.sort_by{|i|i[1]}.last || [] + $redis_cache.hset(platform_statistic_key, max_commit_count_key, max_commit[1].nil? ? 0 : max_commit[1]) + end + + def reset_platform_max_member_count + max_member = Member.where.not(project_id: [0,-1]).group(:project_id).count.sort_by{|i|i[1]}.last || [] + $redis_cache.hset(platform_statistic_key, max_member_count_key, max_member[1].nil? ? 0 : max_member[1]) + end + + def reset_platform_max_recent_one_month_member_count + max_recent_one_month_member = Member.where("created_on > ?", Time.now - 30.days).group(:project_id).count.sort_by{|i|i[1]}.last || [] + $redis_cache.hset(platform_statistic_key, max_recent_one_month_member_count_key, max_recent_one_month_member[1].nil? ? 0 : max_recent_one_month_member[1]) + end + + def reset_platform_max_recent_one_month_pullrequest_count + max_recent_one_month_pullrequest = PullRequest.where("created_at > ?", Time.now - 30.days).group(:project_id).count.sort_by{|i|i[1]}.last || [] + $redis_cache.hset(platform_statistic_key, max_recent_one_month_pullrequest_count_key, max_recent_one_month_pullrequest[1].nil? ? 0 : max_recent_one_month_pullrequest[1]) + end + + def reset_platform_max_recent_one_month_issue_count + max_recent_one_month_issue = Issue.issue_issue.where("created_on > ?", Time.now - 30.days).group(:project_id).count.sort_by{|i|i[1]}.last || [] + $redis_cache.hset(platform_statistic_key, max_recent_one_month_issue_count_key, max_recent_one_month_issue[1].nil? ? 0 : max_recent_one_month_issue[1]) + end + + def reset_platform_max_recent_one_month_commit_count + max_recent_one_month_commit = CommitLog.joins(:project).merge(Project.common).where("created_at > ?", Time.now - 30.days).group(:project_id).count.sort_by{|i|i[1]}.last || [] + $redis_cache.hset(platform_statistic_key, max_recent_one_month_commit_count_key, max_recent_one_month_commit[1].nil? ? 0 : max_recent_one_month_commit[1]) + end + def reset_platform_follow_count $redis_cache.hset(platform_statistic_key, follow_count_key, Watcher.where(watchable_type: 'User').count) end @@ -178,6 +288,17 @@ class Cache::V2::PlatformStatisticService < ApplicationService reset_platform_project_praise_count reset_platform_project_watcher_count reset_platform_pullrequest_count + reset_platform_max_watcher_count + reset_platform_max_praise_count + reset_platform_max_fork_count + reset_platform_max_pullrequest_count + reset_platform_max_issue_count + reset_platform_max_commit_count + reset_platform_max_member_count + reset_platform_max_recent_one_month_member_count + reset_platform_max_recent_one_month_pullrequest_count + reset_platform_max_recent_one_month_issue_count + reset_platform_max_recent_one_month_commit_count $redis_cache.hgetall(platform_statistic_key) end diff --git a/config/routes/api.rb b/config/routes/api.rb index 34751cf50..5f4691a24 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -78,6 +78,7 @@ defaults format: :json do # projects文件夹下的 scope module: :projects do + resources :portrait, only: [:index] resources :sync_repositories, only: [:create, :index] do collection do post :update_info diff --git a/config/sidekiq_cron.yml b/config/sidekiq_cron.yml index 72a69bbad..40c655a74 100644 --- a/config/sidekiq_cron.yml +++ b/config/sidekiq_cron.yml @@ -16,4 +16,11 @@ create_daily_project_statistics: daily_platform_statistics: cron: "0 1 * * *" class: "DailyPlatformStatisticsJob" - queue: default \ No newline at end of file + queue: default + +cache_async_reset: + cron: "0 2 * * *" + class: "CacheAsyncResetJob" + queue: cache + args: + - "platform_statistic_service" \ No newline at end of file From be2491cd90f5a9a2e0692a65b4100420c357f6cb Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 May 2024 15:55:21 +0800 Subject: [PATCH 06/24] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E5=8F=96=E5=B0=8F=E6=95=B0=E7=82=B9=E5=90=8E=E4=B8=A4?= =?UTF-8?q?=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/v1/projects/portrait_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/api/v1/projects/portrait_controller.rb b/app/controllers/api/v1/projects/portrait_controller.rb index e77e7f8e3..de6514169 100644 --- a/app/controllers/api/v1/projects/portrait_controller.rb +++ b/app/controllers/api/v1/projects/portrait_controller.rb @@ -11,7 +11,7 @@ class Api::V1::Projects::PortraitController < Api::V1::BaseController community_impact_praise = platform_statistic['max-praise-count'].to_i == 0 ? 0 : 30*(praise_count.to_f/platform_statistic['max-praise-count'].to_i) community_impact_watcher = platform_statistic['max-watcher-count'].to_i == 0 ? 0 : 30*(watcher_count.to_f/platform_statistic['max-watcher-count'].to_i) community_impact_fork = platform_statistic['max-fork-count'].to_i == 0 ? 0 : 40*(fork_count.to_f/platform_statistic['max-fork-count'].to_i) - community_impact = community_impact_praise + community_impact_watcher + community_impact_fork + community_impact = format("%.2f", community_impact_praise + community_impact_watcher + community_impact_fork) # 项目成熟度 pullrequest_count = PullRequest.where(project_id: @project.id).count @@ -20,7 +20,7 @@ class Api::V1::Projects::PortraitController < Api::V1::BaseController project_maturity_pullrequest = platform_statistic['max-pullrequest-count'].to_i == 0 ? 0 : 30*(pullrequest_count.to_f/platform_statistic['max-pullrequest-count'].to_i) project_maturity_issue = platform_statistic['max-issue-count'].to_i == 0 ? 0 : 30*(issue_count.to_f/platform_statistic['max-issue-count'].to_i) project_maturity_commit = platform_statistic['max-commit-count'].to_i == 0 ? 0 : 40*(commit_count.to_f/platform_statistic['max-commit-count'].to_i) - project_maturity = project_maturity_pullrequest + project_maturity_issue + project_maturity_commit + project_maturity = format("%.2f", project_maturity_pullrequest + project_maturity_issue + project_maturity_commit) # 项目健康度 closed_pullrequest_count = PullRequest.where(project_id: @project.id).merged_and_closed.count @@ -29,14 +29,14 @@ class Api::V1::Projects::PortraitController < Api::V1::BaseController project_health_issue = (issue_count < 10 || closed_issue_count < 10) ? 0 : 40*(closed_issue_count-10).to_f/(issue_count-10) project_health_pullrequest = (pullrequest_count < 5 || closed_pullrequest_count < 5) ? 0 : 30*(closed_pullrequest_count-5).to_f/(pullrequest_count-5) project_health_license = 20*has_license - project_health = project_health_issue + project_health_pullrequest + project_health_license + project_health = format("%.2f", project_health_issue + project_health_pullrequest + project_health_license) # 团队影响度 member_count = Member.where(project_id: @project.id).count recent_one_month_member_count = Member.where(project_id:@project.id).where("created_on > ?", Time.now - 30.days).count team_impact_member = platform_statistic['max-member-count'].to_i == 0 ? 0 : 40*(member_count.to_f/platform_statistic['max-member-count'].to_i) team_impact_recent_member = platform_statistic['max-recent-one-month-member-count'].to_i == 0 ? 0 : 60*(recent_one_month_member_count.to_f/platform_statistic['max-recent-one-month-member-count'].to_i) - team_impact = team_impact_member + team_impact_recent_member + team_impact = format("%.2f", team_impact_member + team_impact_recent_member) # 开发活跃度 recent_one_month_pullrequest_count = PullRequest.where(project_id: @project.id).where("created_at > ?", Time.now - 30.days).count @@ -45,7 +45,7 @@ class Api::V1::Projects::PortraitController < Api::V1::BaseController develop_activity_pullrequest = platform_statistic['max-recent-one-month-pullrequest-count'].to_i == 0 ? 0 : 20*(recent_one_month_pullrequest_count.to_f/platform_statistic['max-recent-one-month-pullrequest-count'].to_i) develop_activity_issue = platform_statistic['max-recent-one-month-issue-count'].to_i == 0 ? 0 : 20*(recent_one_month_issue_count.to_f/platform_statistic['max-recent-one-month-issue-count'].to_i) develop_activity_commit = platform_statistic['max-recent-one-month-commit-count'].to_i == 0 ? 0 : 40*(recent_one_month_commit_count.to_f/platform_statistic['max-recent-one-month-commit-count'].to_i) - develop_activity = 20 + develop_activity_pullrequest + develop_activity_issue + develop_activity_commit + develop_activity = format("%.2f", 20 + develop_activity_pullrequest + develop_activity_issue + develop_activity_commit) render :json => {community_impact: community_impact, project_maturity: project_maturity, project_health: project_health, team_impact: team_impact, develop_activity: develop_activity} end From 07918dbb04df481a12165bf503829774ead24f7c Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 30 May 2024 08:31:56 +0800 Subject: [PATCH 07/24] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1issue=E6=95=B0=E9=87=8F=E6=8E=92=E9=99=A4=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E7=AE=A1=E7=90=86=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/cache/v2/platform_statistic_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/cache/v2/platform_statistic_service.rb b/app/services/cache/v2/platform_statistic_service.rb index a7d9437a0..5de758513 100644 --- a/app/services/cache/v2/platform_statistic_service.rb +++ b/app/services/cache/v2/platform_statistic_service.rb @@ -212,7 +212,7 @@ class Cache::V2::PlatformStatisticService < ApplicationService end def reset_platform_max_issue_count - max_issue = Issue.issue_issue.group(:project_id).count.sort_by{|i|i[1]}.last || [] + max_issue = Issue.where.not(project_id: 0).issue_issue.group(:project_id).count.sort_by{|i|i[1]}.last || [] $redis_cache.hset(platform_statistic_key, max_issue_count_key, max_issue[1].nil? ? 0 : max_issue[1]) end From 1b4ca03ac7fce34a9a00fece41afb58b2e6c48c1 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 3 Jun 2024 14:25:18 +0800 Subject: [PATCH 08/24] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=BC=80=E5=90=AF=E7=94=A8=E6=88=B7=E7=94=BB=E5=83=8F?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/projects_helper.rb | 1 + app/models/project.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 93e2bde76..0f34b7c1b 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -68,6 +68,7 @@ module ProjectsHelper cloud_ide_saas_url: cloud_ide_saas_url(user), open_blockchain: Site.has_blockchain? && project.use_blockchain, has_dataset: project.project_dataset.present?, + open_portrait: project.open_portrait, ignore_id: project.ignore_id }).compact diff --git a/app/models/project.rb b/app/models/project.rb index 2231320d3..c5fb448a0 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -457,6 +457,10 @@ class Project < ApplicationRecord $redis_cache.hdel("issue_cache_delete_count", self.id) end + def open_portrait + EduSetting.get("open_portrait_projects").present? ? EduSetting.get("open_portrait_projects").split(",").include?(self.id.to_s) : false + end + def self.mindspore_contributors cache_result = $redis_cache.get("ProjectMindsporeContributors") if cache_result.nil? From a05ef8d107321482a806df7435be2baf789450fe Mon Sep 17 00:00:00 2001 From: xxq250 Date: Mon, 3 Jun 2024 16:27:21 +0800 Subject: [PATCH 09/24] =?UTF-8?q?=E5=AF=BC=E5=85=A5=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=EF=BC=8C=E8=AF=B7=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e57826f3c..c9b3ad299 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -323,6 +323,7 @@ class ProjectsController < ApplicationController @project.forked_projects.update_all(forked_from_project_id: nil) # 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量 @project.project_category.decrement!(:private_projects_count, 1) if @project.project_category.present? && !@project.is_public + tip_exception("导入失败,请重试!") end # 为了缓存活跃项目的基本信息,后续删除 Cache::V2::ProjectCommonService.new(@project.id).read From 626fa8a7b3dff7557eeb01d40984211bcdbcdf55 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 3 Jun 2024 17:18:20 +0800 Subject: [PATCH 10/24] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index c9b3ad299..b5c5903b7 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -324,17 +324,18 @@ class ProjectsController < ApplicationController # 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量 @project.project_category.decrement!(:private_projects_count, 1) if @project.project_category.present? && !@project.is_public tip_exception("导入失败,请重试!") - end - # 为了缓存活跃项目的基本信息,后续删除 - Cache::V2::ProjectCommonService.new(@project.id).read - # 项目名称,标识,所有者变化时重置缓存 - project_common = $redis_cache.hgetall("v2-project-common:#{@project.id}") - if project_common.present? - if project_common["name"] != @project.name || project_common["identifier"] != @project.identifier || project_common["owner_id"] != @project.user_id - Cache::V2::ProjectCommonService.new(@project.id).reset + else + # 为了缓存活跃项目的基本信息,后续删除 + Cache::V2::ProjectCommonService.new(@project.id).read + # 项目名称,标识,所有者变化时重置缓存 + project_common = $redis_cache.hgetall("v2-project-common:#{@project.id}") + if project_common.present? + if project_common["name"] != @project.name || project_common["identifier"] != @project.identifier || project_common["owner_id"] != @project.user_id + Cache::V2::ProjectCommonService.new(@project.id).reset + end end + json_response(@project, current_user) end - json_response(@project, current_user) end def recommend From aa739a25b6f475cfaf329bac9bf5322d9d2787a4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 3 Jun 2024 17:45:34 +0800 Subject: [PATCH 11/24] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=9B=9E?= =?UTF-8?q?=E6=BB=9A+debug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b5c5903b7..1c0857cf5 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -312,30 +312,30 @@ class ProjectsController < ApplicationController @project&.repository&.mirror&.succeeded! project_id = @project&.id user_id = @project&.owner&.id - puts "############ mirror project_id,user_id: #{project_id},#{user_id} ############" + Rails.logger.info "############ mirror project_id,user_id: #{project_id},#{user_id} ############" OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(project_id, user_id) if project_id.present? && user_id.present? UpdateProjectTopicJob.set(wait: 1.seconds).perform_later(project_id) if project_id.present? - puts "############ mirror status: #{repo.mirror.status} ############" + Rails.logger.info "############ mirror status: #{@project&.repository&.mirror&.status} ############" end elsif !@project.common? && @project&.repository&.mirror&.failed? + Rails.logger.info "############ mirror status: #{@project&.repository&.mirror&.status}" Gitea::Repository::DeleteService.new(@project.owner, @project.identifier,current_user.gitea_token).call @project.destroy! @project.forked_projects.update_all(forked_from_project_id: nil) # 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量 @project.project_category.decrement!(:private_projects_count, 1) if @project.project_category.present? && !@project.is_public tip_exception("导入失败,请重试!") - else - # 为了缓存活跃项目的基本信息,后续删除 - Cache::V2::ProjectCommonService.new(@project.id).read - # 项目名称,标识,所有者变化时重置缓存 - project_common = $redis_cache.hgetall("v2-project-common:#{@project.id}") - if project_common.present? - if project_common["name"] != @project.name || project_common["identifier"] != @project.identifier || project_common["owner_id"] != @project.user_id - Cache::V2::ProjectCommonService.new(@project.id).reset - end - end - json_response(@project, current_user) end + # 为了缓存活跃项目的基本信息,后续删除 + Cache::V2::ProjectCommonService.new(@project.id).read + # 项目名称,标识,所有者变化时重置缓存 + project_common = $redis_cache.hgetall("v2-project-common:#{@project.id}") + if project_common.present? + if project_common["name"] != @project.name || project_common["identifier"] != @project.identifier || project_common["owner_id"] != @project.user_id + Cache::V2::ProjectCommonService.new(@project.id).reset + end + end + json_response(@project, current_user) end def recommend From 4d0225e0d97e7d6472a99ac8073b0f4fc60d87d4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 4 Jun 2024 16:55:06 +0800 Subject: [PATCH 12/24] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=A4=B1=E8=B4=A5=E6=8F=90=E7=A4=BA=E4=BB=A5=E5=8F=8A?= =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=B6=88=E6=81=AF=E6=A8=A1=E6=9D=BF422?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admins/message_templates_controller.rb | 12 +++++------- app/controllers/projects_controller.rb | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/app/controllers/admins/message_templates_controller.rb b/app/controllers/admins/message_templates_controller.rb index 6a5000c24..af77858e1 100644 --- a/app/controllers/admins/message_templates_controller.rb +++ b/app/controllers/admins/message_templates_controller.rb @@ -7,12 +7,12 @@ class Admins::MessageTemplatesController < Admins::BaseController end def new - @message_template = MessageTemplate.new + @message_template = MessageTemplate::CustomTip.new end - def create - @message_template = MessageTemplate::CustomTip.new(message_template_params) - @message_template.type = "MessageTemplate::CustomTip" + def create + @message_template = MessageTemplate::CustomTip.new(ignore_params) + if @message_template.save! redirect_to admins_message_templates_path flash[:success] = "创建消息模板成功" @@ -47,9 +47,7 @@ class Admins::MessageTemplatesController < Admins::BaseController private def message_template_params - # type = @message_template.present? ? @message_template.type : "MessageTemplate::CustomTip" - # params.require(type.split("::").join("_").underscore.to_sym).permit! - params.require(:message_template_custom_tip).permit! + params.require(@message_template.type.split("::").join("_").underscore.to_sym).permit! end def get_template diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 1c0857cf5..074225e43 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -324,7 +324,7 @@ class ProjectsController < ApplicationController @project.forked_projects.update_all(forked_from_project_id: nil) # 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量 @project.project_category.decrement!(:private_projects_count, 1) if @project.project_category.present? && !@project.is_public - tip_exception("导入失败,请重试!") + return render_error("导入失败,请重试!") end # 为了缓存活跃项目的基本信息,后续删除 Cache::V2::ProjectCommonService.new(@project.id).read From 750a032f3f9523110aeff570aebc1ac49d8365e7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 4 Jun 2024 17:04:04 +0800 Subject: [PATCH 13/24] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/message_templates_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admins/message_templates_controller.rb b/app/controllers/admins/message_templates_controller.rb index af77858e1..dbe63a66b 100644 --- a/app/controllers/admins/message_templates_controller.rb +++ b/app/controllers/admins/message_templates_controller.rb @@ -11,7 +11,7 @@ class Admins::MessageTemplatesController < Admins::BaseController end def create - @message_template = MessageTemplate::CustomTip.new(ignore_params) + @message_template = MessageTemplate::CustomTip.new(message_template_params) if @message_template.save! redirect_to admins_message_templates_path From e09dbfeba5585139f9dc48f9ecbc020a992bc969 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 4 Jun 2024 17:14:30 +0800 Subject: [PATCH 14/24] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/admins/message_templates_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/admins/message_templates_controller.rb b/app/controllers/admins/message_templates_controller.rb index dbe63a66b..abe332ac5 100644 --- a/app/controllers/admins/message_templates_controller.rb +++ b/app/controllers/admins/message_templates_controller.rb @@ -11,8 +11,8 @@ class Admins::MessageTemplatesController < Admins::BaseController end def create - @message_template = MessageTemplate::CustomTip.new(message_template_params) - + @message_template = MessageTemplate::CustomTip.new + @message_template.attributes = message_template_params if @message_template.save! redirect_to admins_message_templates_path flash[:success] = "创建消息模板成功" From 395c3fd1fc67e9138ac1f7c55611253636389f96 Mon Sep 17 00:00:00 2001 From: xxq250 Date: Wed, 5 Jun 2024 08:51:23 +0800 Subject: [PATCH 15/24] =?UTF-8?q?fixed=20=E9=A1=B9=E7=9B=AE=E6=B2=A1?= =?UTF-8?q?=E6=9C=89master=E5=88=86=E6=94=AF=E6=97=B6=EF=BC=8C=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E5=8F=91=E8=A1=8C=E7=89=88=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/version_releases_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 2419a1fef..d542fbb76 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -157,7 +157,7 @@ class VersionReleasesController < ApplicationController name: params[:name], prerelease: params[:prerelease] || false, tag_name: params[:tag_name], - target_commitish: params[:target_commitish] || "master" #分支 + target_commitish: params[:target_commitish] || @project.default_branch #分支 } end From 0c4e3a1be7044cd751d34d42d7e801110ca594da Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 5 Jun 2024 11:59:18 +0800 Subject: [PATCH 16/24] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=BB=B6?= =?UTF-8?q?=E8=BF=9F10s=E5=8F=91=E9=80=81websocket=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/jobs/migrate_remote_repository_job.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/jobs/migrate_remote_repository_job.rb b/app/jobs/migrate_remote_repository_job.rb index cc3cdf4a9..9512b9413 100644 --- a/app/jobs/migrate_remote_repository_job.rb +++ b/app/jobs/migrate_remote_repository_job.rb @@ -33,6 +33,6 @@ class MigrateRemoteRepositoryJob < ApplicationJob end end # UpdateProjectTopicJob 中语言要延迟1S才能获取 - BroadcastMirrorRepoMsgJob.set(wait: 1.seconds).perform_later(repo.id) unless repo&.mirror.waiting? + BroadcastMirrorRepoMsgJob.set(wait: 10.seconds).perform_later(repo.id) unless repo&.mirror.waiting? end end From ac815ed9a259bc04414371b690c2349537b039ec Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 5 Jun 2024 15:08:06 +0800 Subject: [PATCH 17/24] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E9=A1=B9=E7=9B=AE=E5=A4=B1=E8=B4=A5=E4=B8=8D=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E9=A1=B9=E7=9B=AE=E6=B0=B8=E8=BF=9C=E8=BF=94=E5=9B=9E?= =?UTF-8?q?-1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 074225e43..45988da3b 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -318,12 +318,12 @@ class ProjectsController < ApplicationController Rails.logger.info "############ mirror status: #{@project&.repository&.mirror&.status} ############" end elsif !@project.common? && @project&.repository&.mirror&.failed? - Rails.logger.info "############ mirror status: #{@project&.repository&.mirror&.status}" - Gitea::Repository::DeleteService.new(@project.owner, @project.identifier,current_user.gitea_token).call - @project.destroy! - @project.forked_projects.update_all(forked_from_project_id: nil) - # 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量 - @project.project_category.decrement!(:private_projects_count, 1) if @project.project_category.present? && !@project.is_public + # Rails.logger.info "############ mirror status: #{@project&.repository&.mirror&.status}" + # Gitea::Repository::DeleteService.new(@project.owner, @project.identifier,current_user.gitea_token).call + # @project.destroy! + # @project.forked_projects.update_all(forked_from_project_id: nil) + # # 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量 + # @project.project_category.decrement!(:private_projects_count, 1) if @project.project_category.present? && !@project.is_public return render_error("导入失败,请重试!") end # 为了缓存活跃项目的基本信息,后续删除 From e8348194b73469e0001a5c7bc8fa3f97a2f19a6f Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 5 Jun 2024 15:48:26 +0800 Subject: [PATCH 18/24] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=A7=BB?= =?UTF-8?q?=E9=99=A4-1=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 45988da3b..e79ba542f 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -317,14 +317,14 @@ class ProjectsController < ApplicationController UpdateProjectTopicJob.set(wait: 1.seconds).perform_later(project_id) if project_id.present? Rails.logger.info "############ mirror status: #{@project&.repository&.mirror&.status} ############" end - elsif !@project.common? && @project&.repository&.mirror&.failed? + # elsif !@project.common? && @project&.repository&.mirror&.failed? # Rails.logger.info "############ mirror status: #{@project&.repository&.mirror&.status}" # Gitea::Repository::DeleteService.new(@project.owner, @project.identifier,current_user.gitea_token).call # @project.destroy! # @project.forked_projects.update_all(forked_from_project_id: nil) # # 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量 # @project.project_category.decrement!(:private_projects_count, 1) if @project.project_category.present? && !@project.is_public - return render_error("导入失败,请重试!") + # return render_error("导入失败,请重试!") end # 为了缓存活跃项目的基本信息,后续删除 Cache::V2::ProjectCommonService.new(@project.id).read From a0b4da4247d3f8bd7a8e231fc2774a964aaa04cb Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 5 Jun 2024 16:01:34 +0800 Subject: [PATCH 19/24] =?UTF-8?q?=E4=BF=AE=E5=BE=A9=EF=BC=9Adetail?= =?UTF-8?q?=E5=A0=B1=E9=8C=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/repositories/detail.json.jbuilder | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/repositories/detail.json.jbuilder b/app/views/repositories/detail.json.jbuilder index 0e5d850a5..236cb165d 100644 --- a/app/views/repositories/detail.json.jbuilder +++ b/app/views/repositories/detail.json.jbuilder @@ -1,4 +1,3 @@ -json.empty @result[:repo]["empty"] json.content @project.content json.website @project.website json.lesson_url @project.lesson_url @@ -47,6 +46,7 @@ json.fork_info do end end if @result[:repo] + json.empty @result[:repo]["empty"] json.size replace_bytes_to_b(number_to_human_size(@result[:repo]['size'].to_i*1024)) json.ssh_url @result[:repo]['ssh_url'] json.clone_url @project.educoder? ? "#{Rails.application.config_for(:configuration)['educoder']['git_site']}/#{@project&.project_educoder&.repo_name}.git" : @result[:repo]['clone_url'] @@ -55,6 +55,7 @@ if @result[:repo] json.full_name @result[:repo]['full_name'] json.private @result[:repo]['private'] else + json.empty true json.size 0 json.ssh_url nil json.clone_url nil From 2d113ff02a2cecdb1f287a6bcf2c77dd54a95c40 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 5 Jun 2024 17:08:53 +0800 Subject: [PATCH 20/24] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Afork=E9=A1=B9?= =?UTF-8?q?=E7=9B=AE=E5=8F=98=E6=9B=B4=E9=A1=B9=E7=9B=AE=E7=A7=81=E6=9C=89?= =?UTF-8?q?=E4=B8=8D=E5=8F=82=E4=B8=8E=E6=8E=92=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e79ba542f..6a21ad5f0 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -214,7 +214,7 @@ class ProjectsController < ApplicationController new_project_params = project_params.except(:private).merge(is_public: !private) @project.update_attributes!(new_project_params) - @project.forked_projects.update_all(is_public: @project.is_public) + @project.forked_projects.map{|p| p.update!(is_public: @project.is_public)} gitea_params = { private: private, default_branch: @project.default_branch, From 30a17f53b3cb07cdf9b0c475b7d09d6b8c682460 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 6 Jun 2024 08:34:54 +0800 Subject: [PATCH 21/24] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9Areadme?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/repositories_helper.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 360f7d03f..79e58346d 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -210,11 +210,13 @@ module RepositoriesHelper end end - after_ss_souces = content.to_s.scan(s_regex) + after_ss_souces = content.to_s.scan(s_regex).uniq after_ss_souces.each_with_index do |s, index| content = content.gsub("#{s[0]}","#{total_sources[:ss][index][0]}") end - after_ss_c_souces = content.to_s.scan(s_regex_c) + after_ss_c_souces = content.to_s.scan(s_regex_c).uniq + puts after_ss_c_souces + puts total_sources after_ss_c_souces.each_with_index do |s, index| content = content.gsub("#{s[0]}","#{total_sources[:ss_c][index][0]}") end From 9de04dba7e8ca4f6ff3303c161284c073c32cd8e Mon Sep 17 00:00:00 2001 From: xxq250 Date: Thu, 6 Jun 2024 09:45:37 +0800 Subject: [PATCH 22/24] =?UTF-8?q?fixed=20=E5=AF=BC=E5=85=A5=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E9=A1=B9=E7=9B=AE=E6=A0=87=E8=AE=B0=20projec?= =?UTF-8?q?t.status=3D0,=20=E5=9C=A8=E5=88=97=E8=A1=A8=E4=B8=AD=E4=B8=8D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 5 ++++- app/jobs/migrate_remote_repository_job.rb | 1 + app/queries/projects/list_query.rb | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 6a21ad5f0..88d847dad 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -317,7 +317,10 @@ class ProjectsController < ApplicationController UpdateProjectTopicJob.set(wait: 1.seconds).perform_later(project_id) if project_id.present? Rails.logger.info "############ mirror status: #{@project&.repository&.mirror&.status} ############" end - # elsif !@project.common? && @project&.repository&.mirror&.failed? + elsif !@project.common? && @project&.repository&.mirror&.failed? + # 导入失败的项目标记 project.status=0, 在列表中不显示 + @project&.update_columns(status: 0) if @project&.status == 1 + # Rails.logger.info "############ mirror status: #{@project&.repository&.mirror&.status}" # Gitea::Repository::DeleteService.new(@project.owner, @project.identifier,current_user.gitea_token).call # @project.destroy! diff --git a/app/jobs/migrate_remote_repository_job.rb b/app/jobs/migrate_remote_repository_job.rb index 9512b9413..1d6e41128 100644 --- a/app/jobs/migrate_remote_repository_job.rb +++ b/app/jobs/migrate_remote_repository_job.rb @@ -22,6 +22,7 @@ class MigrateRemoteRepositoryJob < ApplicationJob gitea_result = $gitea_client.get_repos_by_owner_repo(repo&.project&.owner&.login, repo&.project&.identifier) if gitea_result["empty"] repo&.mirror&.failed! + repo&.project&.update_columns(status: 0) else repo&.project&.update_columns(gpid: gitea_result["id"]) repo&.mirror&.succeeded! diff --git a/app/queries/projects/list_query.rb b/app/queries/projects/list_query.rb index c67feed61..09a02010c 100644 --- a/app/queries/projects/list_query.rb +++ b/app/queries/projects/list_query.rb @@ -38,7 +38,7 @@ class Projects::ListQuery < ApplicationQuery end def main_collection - collection = Project.visible + collection = Project.visible.where(status: 1) # 增加私有组织中项目过滤 collection = collection.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id") .where("organization_extensions.visibility is null or organization_extensions.visibility in (0,1)") From 0187851a048e88417ac0d70cc2c28b0f3ff579c1 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 6 Jun 2024 10:01:41 +0800 Subject: [PATCH 23/24] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=A4=B1=E8=B4=A5=E9=A1=B9=E7=9B=AE=E4=B8=8D=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E5=9C=A8=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 6a21ad5f0..fa4897899 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -36,6 +36,8 @@ class ProjectsController < ApplicationController def index scope = current_user.logged? ? Projects::ListQuery.call(params, current_user.id) : Projects::ListQuery.call(params) + scope = scope.joins(repository: :mirror).where.not(mirrors: {status: 2}) # 导入失败项目不显示 + @projects = kaminari_paginate(scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units, :project_topics)) # @projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units) From ace64f607166c8174ff9e2b6f33cf8422b1df01a Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 6 Jun 2024 10:04:30 +0800 Subject: [PATCH 24/24] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E7=A7=BB?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 696149583..fa83f6e5c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -36,7 +36,7 @@ class ProjectsController < ApplicationController def index scope = current_user.logged? ? Projects::ListQuery.call(params, current_user.id) : Projects::ListQuery.call(params) - scope = scope.joins(repository: :mirror).where.not(mirrors: {status: 2}) # 导入失败项目不显示 + # scope = scope.joins(repository: :mirror).where.not(mirrors: {status: 2}) # 导入失败项目不显示 @projects = kaminari_paginate(scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units, :project_topics)) # @projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :owner, :project_units)