commit加入到项目动态

This commit is contained in:
xxq250 2023-04-17 10:13:23 +08:00
parent d2b4b500b6
commit 5c563db6e4
2 changed files with 13 additions and 1 deletions

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

View File

@ -3,4 +3,6 @@ class CommitLog < ApplicationRecord
belongs_to :project
belongs_to :repository
has_many :project_trends, as: :trend, dependent: :destroy
end