From f17f7306a9702e181d66d97aa68f5f43b0e76ab2 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Fri, 17 Jan 2020 10:39:50 +0800 Subject: [PATCH] Update repository api --- README.md | 27 +++++++++++++++++----- app/controllers/repositories_controller.rb | 4 ++++ app/views/repositories/show.json.jbuilder | 8 +++++++ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9d456b372..46e79e556 100644 --- a/README.md +++ b/README.md @@ -453,11 +453,11 @@ curl -X GET http://localhost:3000/api/projects/3263 | jq #### 修改项目信息 ``` -PUT api/projects/:id +PATCH api/projects/:id ``` *示例* ``` -curl -X PUT \ +curl -X PATCH \ -d "name=hnfl_demo" \ -d "description=my first project" \ -d "repository_name=hnfl_demo" \ @@ -720,7 +720,7 @@ http://localhost:3000/api/18816895620/mirror_demo/entries | jq |name |string|文件夹或文件名称| |path |string|文件夹或文件相对路径| |type |string|文件类型, file:文件,dir:文件目录| -|size |int|文件夹或文件大小 单位KB| +|size |int|文件夹或文件大小 单位B| |content |string|文件内容,| |target |string|标签| @@ -1284,7 +1284,14 @@ http://localhost:3000/api/18816895620/mirror_demo | jq |praised |boolean|当前登录用户是否已点赞,true:已点赞,fasle:未点赞, 用户未登录状态为null| |watched |boolean|当前登录用户是否已关注,true:已关注,fasle:未关注, 用户未登录状态为null| |permission |string|当前登录用户对该仓库的操作权限, Manager:管理员,可以在线编辑文件、在线新建文件、可以设置仓库的基本信息; Developer:开发人员,可在线编辑文件、在线新建文件、不能设置仓库信息; Reporter: 报告人员,只能查看信息,不能设置仓库信息、不能在线编辑文件、不能在线新建文件;用户未登录时也会返回Reporter, 说明也只有读取文件的权限 | +|size |int|仓库文件大小,单位:KB| |mirror_url |string|镜像地址, 只有通过镜像过来的项目才会有这个地址| +|ssh_url |string|仓库ssh地址| +|clone_url |string|仓库克隆地址| +|empty |boolean|仓库是否为空,true: 空仓库;false: 非空仓库| +|private |boolean|仓库是否私有,true: 私有仓库;fasle: 非私有的| +|default_branch |string|仓库默认分支| +|full_name |string|仓库全名(带用户名)| |author |object|提交用户| |-- login |string|用户名称| |-- image_url |string|用户头像| @@ -1293,18 +1300,26 @@ http://localhost:3000/api/18816895620/mirror_demo | jq 返回值 ``` { + "identifier": "mirror_demo", "project_id": 3263, "project_identifier": "mirror_demo", - "identifier": "mirror_demo", "praises_count": 1, "forked_count": 0, "watchers_count": 1, "branches_count": 6, - "commits_count": 105, + "commits_count": 107, "permission": "Manager", + "mirror_url": "https://gitea.com/CasperVector/slew.git", "watched": true, "praised": true, - "mirror_url": "https://gitea.com/CasperVector/slew.git", + "size": 446, + "ssh_url": "jasder@localhost:18816895620/mirror_demo.git", + "clone_url": "http://localhost:3003/18816895620/mirror_demo.git", + "default_branch": "master", + "empty": false, + "full_name": "18816895620/mirror_demo", + "mirror": false, + "private": false, "author": { "name": "18816895620", "image_url": "avatars/User/b" diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9a53d6191..c971e41e1 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -6,6 +6,10 @@ class RepositoriesController < ApplicationController @project = @repo.project @branches_count = Gitea::Repository::BranchesService.new(@user, @repo.identifier).call.size @commits_count = Gitea::Repository::Commits::ListService.new(@user, @repo.identifier).call[:total_count] + @result = Gitea::Repository::GetService.new(@user, @repo.identifier).call + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) end def entries diff --git a/app/views/repositories/show.json.jbuilder b/app/views/repositories/show.json.jbuilder index 7b1a5abe1..33f23c106 100644 --- a/app/views/repositories/show.json.jbuilder +++ b/app/views/repositories/show.json.jbuilder @@ -10,4 +10,12 @@ json.permission render_edit_project_permission(current_user, @project) json.mirror_url @repo.mirror_url json.watched current_user&.watched?(@project) json.praised current_user&.liked?(@project) +json.size @result['size'] +json.ssh_url @result['ssh_url'] +json.clone_url @result['clone_url'] +json.default_branch @result['default_branch'] +json.empty @result['empty'] +json.full_name @result['full_name'] +json.mirror @result['mirror'] +json.private @result['private'] json.partial! 'author', locals: { user: @repo.user }