From 6a7ef2a1a72bbda89abe310ad3cbd6e7ecbcc658 Mon Sep 17 00:00:00 2001 From: "vilet.yy" Date: Thu, 18 Mar 2021 16:35:40 +0800 Subject: [PATCH] add: repo contributors --- app/controllers/repositories_controller.rb | 4 ++++ .../repositories/contributors.json.jbuilder | 17 +++++++++++++++++ config/routes.rb | 1 + 3 files changed, 22 insertions(+) create mode 100644 app/views/repositories/contributors.json.jbuilder diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 3410ddb3e..cd07803d6 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -106,6 +106,10 @@ class RepositoriesController < ApplicationController @tags = Gitea::Repository::Tags::ListService.call(current_user&.gitea_token, @owner.login, @project.identifier, {page: params[:page], limit: params[:limit]}) end + def contributors + @contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier) + end + def edit return render_forbidden if !@project.manager?(current_user) && !current_user.admin? end diff --git a/app/views/repositories/contributors.json.jbuilder b/app/views/repositories/contributors.json.jbuilder new file mode 100644 index 000000000..a5edb37e0 --- /dev/null +++ b/app/views/repositories/contributors.json.jbuilder @@ -0,0 +1,17 @@ +total_count = @contributors.size +json.contributors @contributors.each do |contributor| + user = User.find_by(gitea_uid: contributor["id"]) + if contributor["login"] == "root" + total_count -= 1 + next + end + json.contributions contributor["contributions"] + json.gid contributor["id"] + json.login user.login + json.type user&.type + json.name user.real_name + json.image_url url_to_avatar(user) +end +json.total_count total_count + + diff --git a/config/routes.rb b/config/routes.rb index fd3b22ec9..9e9e3d7a8 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -389,6 +389,7 @@ Rails.application.routes.draw do match :sub_entries, :via => [:get, :put] get :commits get :tags + get :contributors post :create_file put :update_file delete :delete_file