| @@ -216,6 +216,12 @@ class IssuesController < ApplicationController | |||
| if @issue.previous_changes[:due_date].present? | |||
| previous_changes.merge!(due_date: [@issue.previous_changes[:due_date][0].to_s, @issue.previous_changes[:due_date][1].to_s]) | |||
| end | |||
| if @issue.previous_changes[:status_id].present? && @issue.previous_changes[:status_id][1] == 5 | |||
| @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) | |||
| end | |||
| if @issue.previous_changes[:status_id].present? && @issue.previous_changes[:status_id][0] == 5 | |||
| @issue.project_trends.where(action_type: ProjectTrend::CLOSE).destroy_all | |||
| end | |||
| SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes) | |||
| SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if @issue.previous_changes[:assigned_to_id].present? | |||
| end | |||
| @@ -338,6 +344,12 @@ class IssuesController < ApplicationController | |||
| if i.previous_changes[:due_date].present? | |||
| previous_changes.merge!(due_date: [i.previous_changes[:due_date][0].to_s, i.previous_changes[:due_date][1].to_s]) | |||
| end | |||
| if i.previous_changes[:status_id].present? && i.previous_changes[:status_id][1] == 5 | |||
| i.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) | |||
| end | |||
| if i.previous_changes[:status_id].present? && i.previous_changes[:status_id][0] == 5 | |||
| i.project_trends.where(action_type: ProjectTrend::CLOSE).destroy_all | |||
| end | |||
| SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, i&.id, previous_changes) | |||
| SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, i&.id) if i.previous_changes[:assigned_to_id].present? | |||
| end | |||
| @@ -3,7 +3,7 @@ class ProjectTrendsController < ApplicationController | |||
| before_action :check_project_public | |||
| def index | |||
| project_trends = @project.project_trends.includes(:user, trend: :user) | |||
| project_trends = @project.project_trends.preload(:user, trend: :user) | |||
| check_time = params[:time] #时间的筛选 | |||
| check_type = params[:type] #动态类型的筛选,目前已知的有 Issue, PullRequest, Version | |||
| @@ -14,20 +14,25 @@ class ProjectTrendsController < ApplicationController | |||
| project_trends = project_trends.where("created_at between ? and ?",(Time.now.beginning_of_day - check_time.days), Time.now.end_of_day) | |||
| end | |||
| @project_open_issues_count = project_trends.where(trend_type: "Issue", action_type: "create").size | |||
| @project_close_issues_count = project_trends.where(trend_type: "Issue", action_type: "close").size | |||
| @project_issues_count = @project_open_issues_count + @project_close_issues_count | |||
| @project_pr_count = project_trends.where(trend_type: "PullRequest", action_type: "close").size | |||
| @project_new_pr_count = project_trends.where(trend_type: "PullRequest", action_type: "create").size | |||
| @project_pr_all_count = @project_pr_count + @project_new_pr_count | |||
| @project_issues_count = project_trends.where(trend_type: "Issue", action_type: "create").size | |||
| @project_open_issues_count = @project_issues_count - @project_close_issues_count | |||
| @project_pr_count = project_trends.where(trend_type: "PullRequest", action_type: ["close", "merge"]).size | |||
| @project_pr_all_count = project_trends.where(trend_type: "PullRequest", action_type: "create").size | |||
| @project_new_pr_count = @project_pr_all_count - @project_pr_count | |||
| if check_type.present? | |||
| project_trends = project_trends.where(trend_type: check_type.to_s.strip) | |||
| end | |||
| if check_status.present? | |||
| project_trends = project_trends.where(action_type: check_status.to_s.strip) | |||
| if check_status == "delay" || check_status == "close" | |||
| project_trends = project_trends.where(action_type: ["close", "merge"]) | |||
| else | |||
| project_trends = project_trends.where(action_type: ["create"]).where.not(trend_id: project_trends.where(action_type: ["close", "merge"]).pluck(:trend_id)) | |||
| end | |||
| else | |||
| project_trends = project_trends.where(action_type: "create") | |||
| end | |||
| project_trends = project_trends.order("created_at desc") | |||
| @@ -127,9 +127,9 @@ class ProjectsController < ApplicationController | |||
| Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) | |||
| else | |||
| validate_params = project_params.slice(:name, :description, | |||
| :project_category_id, :project_language_id, :private) | |||
| :project_category_id, :project_language_id, :private, :identifier) | |||
| Projects::UpdateForm.new(validate_params).validate! | |||
| Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id)).validate! | |||
| private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : params[:private] || false | |||
| @@ -139,12 +139,11 @@ class ProjectsController < ApplicationController | |||
| gitea_params = { | |||
| private: private, | |||
| default_branch: @project.default_branch, | |||
| website: @project.website | |||
| website: @project.website, | |||
| name: @project.identifier | |||
| } | |||
| if [true, false].include? private | |||
| Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) | |||
| @project.repository.update_column(:hidden, private) | |||
| end | |||
| gitea_repo = Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params) | |||
| @project.repository.update_attributes({hidden: gitea_repo["private"], identifier: gitea_repo["name"]}) | |||
| end | |||
| SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, @project.previous_changes.slice(:name, :description, :project_category_id, :project_language_id, :is_public)) | |||
| end | |||
| @@ -229,7 +228,7 @@ class ProjectsController < ApplicationController | |||
| private | |||
| def project_params | |||
| params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, | |||
| params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, :identifier, | |||
| :project_category_id, :project_language_id, :license_id, :ignore_id, :private) | |||
| end | |||
| @@ -130,6 +130,7 @@ class PullRequestsController < ApplicationController | |||
| begin | |||
| colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user) | |||
| if colsed === true | |||
| @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::CLOSE) | |||
| SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) | |||
| normal_status(1, "已拒绝") | |||
| else | |||
| @@ -171,7 +172,8 @@ class PullRequestsController < ApplicationController | |||
| end | |||
| if success_condition && @pull_request.merge! | |||
| @pull_request.project_trend_status! | |||
| # @pull_request.project_trend_status! | |||
| @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::MERGE) | |||
| @issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id) | |||
| SendTemplateMessageJob.perform_later('PullRequestMerged', current_user.id, @pull_request.id) | |||
| normal_status(1, "合并成功") | |||
| @@ -1,11 +1,12 @@ | |||
| class Projects::UpdateForm < BaseForm | |||
| attr_accessor :name, :description, :project_category_id, :project_language_id, :private | |||
| attr_accessor :name, :description, :project_category_id, :project_language_id, :private, :identifier, :user_id | |||
| validates :name, presence: true | |||
| validates :name, length: { maximum: 50 } | |||
| validates :description, length: { maximum: 200 } | |||
| validate do | |||
| check_project_category(project_category_id) | |||
| check_project_language(project_language_id) | |||
| check_repository_name(user_id, identifier) unless identifier.blank? | |||
| end | |||
| end | |||
| @@ -20,7 +20,8 @@ | |||
| class ProjectTrend < ApplicationRecord | |||
| CLOSE = 'close' | |||
| CREATE = 'create' | |||
| MERGE = 'merge' | |||
| belongs_to :project | |||
| belongs_to :trend, polymorphic: true, optional: true | |||
| belongs_to :user | |||
| @@ -19,7 +19,8 @@ class Gitea::Repository::UpdateService < Gitea::ClientService | |||
| end | |||
| def call | |||
| patch(url, data_params) | |||
| response = patch(url, data_params) | |||
| render_200_response(response) | |||
| end | |||
| private | |||
| @@ -0,0 +1,30 @@ | |||
| namespace :refactor_project_trend do | |||
| desc "refactor project trend data record" | |||
| task issue_and_pull_request: :environment do | |||
| puts "========DELETE all old data begin========" | |||
| old_data_count = ProjectTrend.where(trend_type: ["PullRequest","Issue"]).destroy_all.size | |||
| puts "========DELETE all old data #{old_data_count}========" | |||
| puts "========DELETE all old data end========" | |||
| puts "========CREATE new issue data begin========" | |||
| issue_count = 0 | |||
| Issue.issue_issue.find_each do |issue| | |||
| issue_count += 1 | |||
| issue.project_trends.create(user_id: issue.assigned_to_id || issue.author_id, project_id: issue.project_id, action_type: ProjectTrend::CLOSE, created_at: issue.updated_on) if issue.status_id == 5 | |||
| issue.project_trends.create(user_id: issue.author_id, project_id: issue.project_id, action_type: ProjectTrend::CREATE, created_at: issue.created_on) | |||
| end | |||
| puts "========CREATE new issue data #{issue_count}========" | |||
| puts "========CREATE new issue data end========" | |||
| puts "========CREATE new pull_request data begin========" | |||
| pull_request_count = 0 | |||
| PullRequest.find_each do |pull_request| | |||
| pull_request_count += 1 | |||
| pull_request.project_trends.create(user_id: pull_request.user_id, project_id: pull_request.project_id, action_type: ProjectTrend::MERGE, created_at: pull_request.updated_at) if pull_request.status == PullRequest::MERGED | |||
| pull_request.project_trends.create(user_id: pull_request.user_id, project_id: pull_request.project_id, action_type: ProjectTrend::CLOSE, created_at: pull_request.updated_at) if pull_request.status == PullRequest::CLOSED | |||
| pull_request.project_trends.create(user_id: pull_request.user_id, project_id: pull_request.project_id, action_type: ProjectTrend::CREATE, created_at: pull_request.created_at) | |||
| end | |||
| puts "========CREATE new pull_request data #{pull_request_count}========" | |||
| puts "========CREATE new pull_request data end========" | |||
| end | |||
| end | |||