Merge branch 'pre_trustie_server' into trustie_server

This commit is contained in:
xxq250 2023-04-17 11:09:16 +08:00
commit 7b64813471
8 changed files with 283 additions and 242 deletions

View File

@ -19,9 +19,10 @@ 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

View File

@ -1,6 +1,6 @@
class ProjectTrendsController < ApplicationController
before_action :load_repository
before_action :check_project_public
before_action :load_repository, except: [:last]
before_action :check_project_public, except: [:last]
def index
project_trends = @project.project_trends.preload(:user, trend: :user, project: :owner)
@ -42,6 +42,14 @@ class ProjectTrendsController < ApplicationController
@project_trends = project_trends.page(@page).per(@limit)
end
def last
project_trends = ProjectTrend.preload(:user, trend: :user, project: :owner).order("id desc")
@page = params[:page] || 1
@limit = params[:limit] || 20
@project_trends_count = project_trends.count
@project_trends = project_trends.page(@page).per(@limit)
end
private
def check_project_public

View File

@ -3,4 +3,10 @@ class CommitLog < ApplicationRecord
belongs_to :project
belongs_to :repository
has_many :project_trends, as: :trend, dependent: :destroy
def title
self.message
end
end

View File

@ -18,6 +18,15 @@ if trend.trend_type == "Issue"
json.partial! "issues/simple_issue_item", locals: {issue: trend.trend}
elsif trend.trend_type == "VersionRelease"
json.partial! "version_releases/simple_version_release", locals: {version: trend.trend}
elsif trend.trend_type == "CommitLog"
json.commit_log do
commit_log = trend.trend
json.user do
json.partial! 'users/user_simple', locals: {user: commit_log.user}
end
json.ref commit_log.ref.to_s.gsub("refs/heads/", "")
json.extract! commit_log, :id,:name,:full_name,:message, :commit_id,:created_at,:updated_at
end
else
json.name trend.trend&.title
json.created_at format_time(trend.trend&.created_at)

View File

@ -0,0 +1,8 @@
json.partial! "commons/success"
json.total_count @project_trends_count
json.project_trends do
json.array! @project_trends.to_a.each do |trend|
json.partial! "detail", trend: trend
end
end

View File

@ -18,6 +18,7 @@ zh-CN:
Issue: 疑修(Issue)
PullRequest: 合并请求(PR)
VersionRelease: 版本发布
CommitLog: 代码(Commit)
create: 创建了
journal: 回复了
close: 关闭了

View File

@ -117,6 +117,7 @@ Rails.application.routes.draw do
get 'home/index'
get 'home/search'
get 'main/first_stamp'
get 'activity/last', to: 'project_trends#last'
get 'search', to: 'searchs#index'
put 'commons/hidden', to: 'commons#hidden'
@ -763,6 +764,7 @@ Rails.application.routes.draw do
end
end
end
# Project Area END
scope module: :helps do

View File

@ -0,0 +1,6 @@
class UpdateCommitLogUtf8 < ActiveRecord::Migration[5.2]
def change
execute("ALTER TABLE `commit_logs` MODIFY `name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
execute("ALTER TABLE `commit_logs` MODIFY `full_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;")
end
end