diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 3b5952459..0f672b5ab 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -9,6 +9,7 @@ class RepositoriesController < ApplicationController before_action :authorizate_user_can_edit_repo!, only: %i[sync_mirror] before_action :get_ref, only: %i[entries sub_entries top_counts] before_action :get_statistics, only: %i[top_counts] + before_action :get_latest_commit, %i[entries sub_entries top_counts] def show @user = current_user @@ -126,7 +127,7 @@ class RepositoriesController < ApplicationController end # TODO 获取最新commit信息 - def get_latest_commit + def project_commits Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier, sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call end @@ -134,16 +135,18 @@ class RepositoriesController < ApplicationController def get_statistics @branches_count = Gitea::Repository::Branches::ListService.new(@project.owner, @project.identifier).call&.size @tags_count = Gitea::Repository::Tags::ListService.new(current_user&.gitea_token, @project.owner.login, @project.identifier).call&.size - - latest_commit = get_latest_commit - @latest_commit = latest_commit[:body][0] if latest_commit.present? - @commits_count = latest_commit[:total_count] if latest_commit.present? end def get_ref @ref = params[:ref] || "master" end + def get_latest_commit + latest_commit = project_commits + @latest_commit = latest_commit[:body][0] if latest_commit.present? + @commits_count = latest_commit[:total_count] if latest_commit.present? + end + def content_params { filepath: params[:filepath],