Browse Source

commit加入到项目动态

pull/342/head
xxq250 3 years ago
parent
commit
5c563db6e4
2 changed files with 13 additions and 1 deletions
  1. +11
    -1
      app/controllers/commit_logs_controller.rb
  2. +2
    -0
      app/models/commit_log.rb

+ 11
- 1
app/controllers/commit_logs_controller.rb View File

@@ -19,12 +19,22 @@ class CommitLogsController < ApplicationController
params[:commits].each do |commit|
commit_id = commit[:id]
message = commit[:message]
CommitLog.create(user: user, project: project, repository_id: repository_id,
commit_log = CommitLog.create(user: user, project: project, repository_id: repository_id,
name: repository_name, full_name: repository_full_name,
ref: ref, commit_id: commit_id, message: message)
commit_log.project_trends.create(user_id: user.id, project_id: project&.id, action_type: "create")
# 统计数据新增
CacheAsyncSetJob.perform_later("project_common_service", {commits: 1}, project.id)
end

end

def activity
commit_sql = CommitLog.select("user_id,project_id, '' as ref").order(id: :desc).limit(10).to_sql
project_sql = Project.select("user_id,id as project_id, '' as ref").order(id: :desc).limit(10).to_sql
project_sql = Issue.select("user_id,project_id, '' as ref").order(id: :desc).limit(10).to_sql
project_sql = Issue.select("user_id,project_id, '' as ref").order(id: :desc).limit(10).to_sql
privacy_organizations_sql = Project.with_visibility("privacy").joins(:organization_users).where(organization_users: {user_id: current_user.id}).to_sql
@organizations = Organization.from("( #{ logged_organizations_sql } UNION #{ privacy_organizations_sql } ) AS users")
end
end

+ 2
- 0
app/models/commit_log.rb View File

@@ -3,4 +3,6 @@ class CommitLog < ApplicationRecord
belongs_to :project
belongs_to :repository

has_many :project_trends, as: :trend, dependent: :destroy

end

Loading…
Cancel
Save