新增: 项目详情

This commit is contained in:
yystopf 2022-06-22 19:08:14 +08:00
parent aefd6c08dc
commit d7dd3901b8
11 changed files with 125 additions and 10 deletions

View File

@ -135,4 +135,4 @@ gem 'doorkeeper'
gem 'doorkeeper-jwt'
gem 'gitea-client', '~> 0.5.1'
gem 'gitea-client', '~> 0.6.2'

View File

@ -135,7 +135,7 @@ GEM
fugit (1.4.1)
et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.4)
gitea-client (0.5.1)
gitea-client (0.6.2)
rest-client (~> 2.1.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
@ -478,7 +478,7 @@ DEPENDENCIES
enumerize
faraday (~> 0.15.4)
font-awesome-sass (= 4.7.0)
gitea-client (~> 0.5.1)
gitea-client (~> 0.6.2)
grape-entity (~> 0.7.1)
groupdate (~> 4.1.0)
harmonious_dictionary (~> 0.0.1)

View File

@ -1,2 +1,6 @@
class Api::V1::BaseController < ApplicationController
include Api::ProjectHelper
skip_before_action :user_setup
end

View File

@ -0,0 +1,11 @@
class Api::V1::ProjectsController < Api::V1::BaseController
before_action :load_project, only: [:show]
def index
render_ok
end
def show
@result_object = Api::V1::Projects::GetService.call(@project, current_user.gitea_token)
end
end

View File

@ -1,6 +0,0 @@
class Api::V1::ReposController < Api::V1::BaseController
def index
render_ok
end
end

View File

@ -0,0 +1,20 @@
module Api::ProjectHelper
extend ActiveSupport::Concern
def load_project
namespace = params[:owner]
repo = params[:repo]
@project, @owner = Project.find_with_namespace(namespace, repo)
if @project
logger.info "###########project not founded"
@project
else
logger.info "###########project not found"
@project = nil
render_not_found and return
end
@project
end
end

View File

@ -0,0 +1,48 @@
class Api::V1::Projects::GetService < ApplicationService
attr_reader :project, :token, :owner, :repo
attr_accessor :gitea_data, :gitea_branch_tag_count
def initialize(project, token=nil)
@project = project
@owner = project&.owner.login
@repo = project&.identifier
@token = token
end
def call
$gitea_client.token = token unless token.blank?
load_gitea_data
load_gitea_branch_tag_count
$gitea_client.token = nil unless token.blank?
result_object
rescue
raise Error, "服务器错误,请联系系统管理员!"
end
private
def result_object
{
full_name: "#{owner}/#{repo}",
owner: project&.owner,
ssh_url: gitea_data["ssh_url"],
clone_url: gitea_data["clone_url"],
size: gitea_data["size"],
default_branch: gitea_data["default_branch"],
empty: gitea_data["empty"],
branch_count: gitea_branch_tag_count["branch_count"],
tag_count: gitea_branch_tag_count["tag_count"],
}
end
def load_gitea_data
@gitea_data = $gitea_client.get_repos_by_owner_repo(owner, repo)
end
def load_gitea_branch_tag_count
@gitea_branch_tag_count = $gitea_client.get_repos_branch_tag_count_by_owner_repo(owner, repo)
end
end

View File

@ -0,0 +1,10 @@
if project.present?
json.type @project.project_type
json.(project,
:description, :forked_count, :forked_from_project_id, :identifier,
:issues_count, :pull_requests_count, :invite_code, :website, :platform,
:name, :open_devops, :praises_count, :is_public, :status, :watchers_count,
:ignore_id, :license_id, :project_category_id, :project_language_id)
else
json.nil!
end

View File

@ -0,0 +1,5 @@
json.owner do
json.partial! "api/v1/users/simple_user", user: @result_object[:owner]
end
json.(@result_object, :full_name, :ssh_url, :clone_url, :default_branch, :empty, :branch_count, :tag_count)
json.partial! "api/v1/projects/simple_detail", project: @project

View File

@ -0,0 +1,9 @@
if user.present?
json.id user.id
json.type user.type
json.name user.real_name
json.login user.login
json.image_url url_to_avatar(user)
else
json.nil!
end

View File

@ -1,7 +1,21 @@
defaults format: :json do
namespace :api do
namespace :v1 do
resources :repos
resources :projects, only: [:index]
# 项目相关的api
scope ':owner/:repo' do
# projects
resource :projects, path: '/', only: [:show, :update, :edit, :destroy]
# projects文件夹下的
scope module: :projects do
resources :issues
resources :pull_requests
resources :versions
resources :release_versions
end
end
end
end
end