| @@ -141,4 +141,4 @@ gem 'doorkeeper' | |||
| gem 'doorkeeper-jwt' | |||
| gem 'gitea-client', '~> 1.4.6' | |||
| gem 'gitea-client', '~> 1.5.7' | |||
| @@ -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 | |||
| @message_template.attributes = message_template_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 | |||
| @@ -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) | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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 = format("%.2f", 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 = format("%.2f", 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 = 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 = 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 | |||
| 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 = 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 | |||
| end | |||
| @@ -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) | |||
| @@ -214,7 +216,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, | |||
| @@ -255,7 +257,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 +307,30 @@ 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 | |||
| 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? | |||
| Rails.logger.info "############ mirror status: #{@project&.repository&.mirror&.status} ############" | |||
| end | |||
| 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! | |||
| # @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 | |||
| # 为了缓存活跃项目的基本信息,后续删除 | |||
| Cache::V2::ProjectCommonService.new(@project.id).read | |||
| # 项目名称,标识,所有者变化时重置缓存 | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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, | |||
| @@ -19,9 +19,21 @@ 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! | |||
| repo&.project&.update_columns(status: 0) | |||
| 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? | |||
| BroadcastMirrorRepoMsgJob.set(wait: 10.seconds).perform_later(repo.id) unless repo&.mirror.waiting? | |||
| end | |||
| end | |||
| @@ -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 | |||
| @@ -216,4 +216,9 @@ class Organization < Owner | |||
| ids.uniq.size | |||
| end | |||
| # user容错处理 | |||
| def get_letter_avatar_url | |||
| "" | |||
| end | |||
| end | |||
| @@ -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? | |||
| @@ -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)") | |||
| @@ -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.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 | |||
| 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 | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -96,6 +97,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 | |||
| @@ -159,6 +163,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 | |||
| @@ -16,4 +16,11 @@ create_daily_project_statistics: | |||
| daily_platform_statistics: | |||
| cron: "0 1 * * *" | |||
| class: "DailyPlatformStatisticsJob" | |||
| queue: default | |||
| queue: default | |||
| cache_async_reset: | |||
| cron: "0 2 * * *" | |||
| class: "CacheAsyncResetJob" | |||
| queue: cache | |||
| args: | |||
| - "platform_statistic_service" | |||
| @@ -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 | |||
| @@ -0,0 +1,5 @@ | |||
| require 'rails_helper' | |||
| RSpec.describe GitlinkCompetitionApply, type: :model do | |||
| pending "add some examples to (or delete) #{__FILE__}" | |||
| end | |||