From f54c374c7858d44b10414a4e0736ea7260d9d826 Mon Sep 17 00:00:00 2001 From: "sylor_huang@126.com" Date: Tue, 2 Jun 2020 15:57:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9commit=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E7=9A=84=E7=94=A8=E6=88=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/repositories_controller.rb | 1 - app/models/user.rb | 2 ++ app/views/repositories/commits.json.jbuilder | 10 +++++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 8bc182dbf..8ae6b3b85 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -44,7 +44,6 @@ class RepositoriesController < ApplicationController end def commits - @project_owner = @project.owner @hash_commit = Gitea::Repository::Commits::ListService.new(@project_owner.login, @project.identifier, sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call end diff --git a/app/models/user.rb b/app/models/user.rb index 7e69e4b10..c62334906 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -96,6 +96,8 @@ class User < ApplicationRecord where("LOWER(concat(lastname, firstname, login, mail)) LIKE ?", "%#{keywords.split(" ").join('|')}%") unless keywords.blank? } + scope :simple_select, -> {select(:id, :login, :lastname,:firstname, :nickname)} + attr_accessor :password, :password_confirmation delegate :gender, :department_id, :school_id, :location, :location_city, :technical_title, to: :user_extension, allow_nil: true diff --git a/app/views/repositories/commits.json.jbuilder b/app/views/repositories/commits.json.jbuilder index 0c9442029..6e7f7b330 100644 --- a/app/views/repositories/commits.json.jbuilder +++ b/app/views/repositories/commits.json.jbuilder @@ -5,11 +5,19 @@ else json.total_count @hash_commit[:total_count] json.commits do json.array! @hash_commit[:body] do |commit| + commit_user = commit['committer']['name'] + if commit_user + forge_user = User.simple_select.find_by(login: commit_user) + end json.sha commit['sha'] json.message commit['commit']['message'] json.timestamp render_unix_time(commit['commit']['author']['date']) json.time_from_now time_from_now(commit['commit']['author']['date']) - json.partial! 'author', user: @project_owner + if forge_user + json.partial! 'author', user: forge_user + else + json.author nil + end end end end