From 98fa2bbb9944c5c77cdfa5e0862a7b7a169ef19a Mon Sep 17 00:00:00 2001
From: Jasder <2053003901@@qq.com>
Date: Fri, 3 Jan 2020 18:01:24 +0800
Subject: [PATCH 1/2] ADD repository url

---
 app/helpers/projects_helper.rb            | 16 ++++++++++++++++
 app/views/projects/branches.json.jbuilder |  3 +++
 2 files changed, 19 insertions(+)

diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb
index 8a860eca8..ee77ed698 100644
--- a/app/helpers/projects_helper.rb
+++ b/app/helpers/projects_helper.rb
@@ -6,4 +6,20 @@ module ProjectsHelper
     when 'mirror' then "开源镜像项目"
     end
   end
+
+  def render_zip_url(project, archive_name)
+    [gitea_domain, project.owner.login, project.identifier, "#{archive_name}.zip"].join('/')
+  end
+
+  def render_tar_url(project, archive_name)
+    [gitea_domain, project.owner.login, project.identifier, "#{archive_name}.tar.gz"].join('/')
+  end
+
+  def render_http_url(project)
+    [gitea_domain, project.owner.login, "#{project.identifier}.git"].join('/')
+  end
+
+  def gitea_domain
+    Gitea.gitea_config[:domain]
+  end
 end
diff --git a/app/views/projects/branches.json.jbuilder b/app/views/projects/branches.json.jbuilder
index 7b04f4ced..3e0981d68 100644
--- a/app/views/projects/branches.json.jbuilder
+++ b/app/views/projects/branches.json.jbuilder
@@ -3,6 +3,9 @@ json.array! @branches do |branch|
   json.user_can_push branch['user_can_push']
   json.user_can_merge branch['user_can_merge']
   json.protected branch['protected']
+  json.http_url render_http_url(@project)
+  json.zip_url render_zip_url(@project, branch['name'])
+  json.tar_url render_tar_url(@project, branch['name'])
   json.last_commit do
     json.id branch['commit']['id']
     json.message branch['commit']['message']

From c00a5bc5ca5491e59a1530ff680e335969ec8658 Mon Sep 17 00:00:00 2001
From: Jasder <2053003901@@qq.com>
Date: Fri, 3 Jan 2020 18:01:44 +0800
Subject: [PATCH 2/2] Update README.md

---
 README.md | 193 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 161 insertions(+), 32 deletions(-)

diff --git a/README.md b/README.md
index 9b188c2fc..9c50ad421 100644
--- a/README.md
+++ b/README.md
@@ -292,8 +292,8 @@ POST api/projects/migrate
 ```
 curl -X POST \
 -d "user_id=36401" \
--d "clone_addr=https://gitea.com/CasperVector/slew.git" \
--d "name=ni项目" \
+-d "clone_addr=https://gitee.com/openeuler/A-Tune.git" \
+-d "name=A-Tune" \
 -d "description=my first project" \
 -d "repository_name=mirror_demo" \
 -d "project_category_id=1" \
@@ -365,36 +365,36 @@ http://localhost:3000/api/18816895620/mirror_demo/entries  | jq
 返回值
 ```
 [
-{
-  "name": "Manual",
-  "path": "Manual",
-  "sha": "c2f18765235076b4c835b3e31262b3ee65176a75",
-  "type": "file",
-  "size": 12579,
-  "content": null,
-  "target": null,
-  "commit": null
-},
-{
-  "name": "README",
-  "path": "README",
-  "sha": "91a29176828eba5c5598f5d4a95458e861f271ec",
-  "type": "file",
-  "size": 1767,
-  "content": null,
-  "target": null,
-  "commit": null
-},
-{
-  "name": "base",
-  "path": "base",
-  "sha": "7adbe5698e02dba062216333d5e1d16b36ae1cbd",
-  "type": "dir",
-  "size": 0,
-  "content": null,
-  "target": null,
-  "commit": null
-}
+  {
+    "name": "Manual",
+    "path": "Manual",
+    "sha": "c2f18765235076b4c835b3e31262b3ee65176a75",
+    "type": "file",
+    "size": 12579,
+    "content": null,
+    "target": null,
+    "commit": null
+  },
+  {
+    "name": "README",
+    "path": "README",
+    "sha": "91a29176828eba5c5598f5d4a95458e861f271ec",
+    "type": "file",
+    "size": 1767,
+    "content": null,
+    "target": null,
+    "commit": null
+  },
+  {
+    "name": "base",
+    "path": "base",
+    "sha": "7adbe5698e02dba062216333d5e1d16b36ae1cbd",
+    "type": "dir",
+    "size": 0,
+    "content": null,
+    "target": null,
+    "commit": null
+  }
 ]
 ```
 ---
@@ -751,6 +751,9 @@ curl -X GET http://localhost:3000/api/projects/mirror_demo/branches | jq
 |user_can_push   |boolean|用户是否可push|
 |user_can_merge  |boolean|用户是否客merge|
 |protected       |boolean|是否为保护分支|
+|http_url        |boolean|http链接|
+|zip_url         |boolean|zip包下载链接|
+|tar_url         |boolean|tar.gz下载链接|
 |last_commit     |object|最后提交记录|
 |-- id           |string|提交记录id|
 |-- message      |string|提交的说明信息|
@@ -769,6 +772,9 @@ curl -X GET http://localhost:3000/api/projects/mirror_demo/branches | jq
     "user_can_push": true,
     "user_can_merge": true,
     "protected": false,
+    "http_url": "http://localhost:3003/18816895620/mirror_demo.git",
+    "zip_url": "http://localhost:3003/18816895620/mirror_demo/develop.zip",
+    "tar_url": "http://localhost:3003/18816895620/mirror_demo/develop.tar.gz",
     "last_commit": {
       "id": "735674d6696bddbafa993db9c67b40c41246c77f",
       "message": "FIX test branch content\n",
@@ -785,6 +791,9 @@ curl -X GET http://localhost:3000/api/projects/mirror_demo/branches | jq
     "user_can_push": true,
     "user_can_merge": true,
     "protected": false,
+    "http_url": "http://localhost:3003/18816895620/mirror_demo.git",
+    "zip_url": "http://localhost:3003/18816895620/mirror_demo/master.zip",
+    "tar_url": "http://localhost:3003/18816895620/mirror_demo/master.tar.gz",
     "last_commit": {
       "id": "19ac3bc45f62cc87a94b8ecce61101d8fd2dafd2",
       "message": "合并pull request测试\n\n该功能很不错,感谢你的建议\n",
@@ -927,6 +936,126 @@ http://localhost:3000/api/praise_tread/unlike | jq
 |status           |int|0:点赞成功,-1:操作失败,2:表示还未点赞|
 
 
+返回值
+```
+{
+  "status": 0,
+  "message": "响应成功"
+}
+```
+---
+
+### 仓库新建文件
+```
+DELETE /api/:login/:repo_identifier/contents
+```
+*示例*
+```
+curl -X DELETE \
+-d 'filepath=1' \
+-d 'object_type=project' \
+http://localhost:3000/api/118816895620/mirror_demo/contents | jq
+```
+*请求参数说明:*
+
+|参数名|必选|类型|说明|
+-|-|-|-
+|login          |是|string |用户标识  |
+|repo_identifier|是|string |仓库标识  |
+|filepath       |是|string |文件相对于仓库的路径 |
+|content        |否|string |内容  |
+|message        |否|string |提交说明 |
+|branch         |否|string |分支名称, branch和new_branch必须存在一个 |
+|new_branch     |否|string |新的分支名称 |
+
+
+*返回参数说明:*
+
+|参数名|类型|说明|
+-|-|-
+|status           |int|0:点赞成功,-1:操作失败,2:表示还未点赞|
+
+
+返回值
+```
+{
+  "status": 0,
+  "message": "响应成功"
+}
+```
+---
+
+### 更新仓库中的文件
+```
+DELETE /api/:login/:repo_identifier/contents/files/update
+```
+*示例*
+```
+curl -X DELETE \
+-d 'filepath=1' \
+-d 'object_type=project' \
+http://localhost:3000/api/118816895620/mirror_demo/contents | jq
+```
+*请求参数说明:*
+
+|参数名|必选|类型|说明|
+-|-|-|-
+|login          |是|string |用户标识  |
+|repo_identifier|是|string |仓库标识  |
+|filepath       |是|string |文件相对于仓库的路径 |
+|content        |否|string |内容  |
+|message        |否|string |提交说明 |
+|branch         |否|string |分支名称, branch和new_branch必须存在一个 |
+|new_branch     |否|string |新的分支名称 |
+
+
+*返回参数说明:*
+
+|参数名|类型|说明|
+-|-|-
+|status           |int|0:点赞成功,-1:操作失败,2:表示还未点赞|
+
+
+返回值
+```
+{
+  "status": 0,
+  "message": "响应成功"
+}
+```
+---
+
+### 删除仓库中的文件
+```
+DELETE /api/:login/:repo_identifier/contents/files/delete
+```
+*示例*
+```
+curl -X DELETE \
+-d 'filepath=1' \
+-d 'object_type=project' \
+http://localhost:3000/api/118816895620/mirror_demo/contents | jq
+```
+*请求参数说明:*
+
+|参数名|必选|类型|说明|
+-|-|-|-
+|login          |是|string |用户标识  |
+|repo_identifier|是|string |仓库标识  |
+|filepath       |是|string |文件相对于仓库的路径 |
+|content        |否|string |内容  |
+|message        |否|string |提交说明 |
+|branch         |否|string |分支名称, branch和new_branch必须存在一个 |
+|new_branch     |否|string |新的分支名称 |
+
+
+*返回参数说明:*
+
+|参数名|类型|说明|
+-|-|-
+|status           |int|0:点赞成功,-1:操作失败,2:表示还未点赞|
+
+
 返回值
 ```
 {