diff --git a/README.md b/README.md index 9c50ad421..5ed0d3abf 100644 --- a/README.md +++ b/README.md @@ -809,6 +809,132 @@ curl -X GET http://localhost:3000/api/projects/mirror_demo/branches | jq ``` --- +### 获取版本列表 +``` +GET /api/:login/:repo_identifier/tags +``` +*示例* +``` +curl -X GET http://localhost:3000/api/18816895620/mirror_demo/tags | jq +``` +*请求参数说明:* + +|参数名|必选|类型|说明| +-|-|-|- +|identifier |是|string |项目标识 | + + +*返回参数说明:* + +|参数名|类型|说明| +-|-|- +|name |string|分支名称| +|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|提交的说明信息| +|-- timestamp |int|提交时间,为UNIX时间戳| +|-- time_from_now|string|转换后的时间| +|author |object|提交用户| +|-- login |string|用户名称| +|-- image_url |string|用户头像| + + +返回值 +``` +[ + { + "name": "develop", + "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", + "timestamp": 1577694074, + "time_from_now": "1天前" + }, + "author": { + "login": "18816895620", + "image_url": "avatars/User/b" + } + }, + { + "name": "master", + "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", + "timestamp": 1577244567, + "time_from_now": "6天前" + }, + "author": { + "login": "18816895620", + "image_url": "avatars/User/b" + } + } +] +``` +--- + +## 仓库详情 +``` +GET /api/:login/:repo_identifier/ +``` +*示例* +``` +curl -X GET \ +http://localhost:3000/api/18816895620/mirror_demo | jq +``` +*请求参数说明:* + +|参数名|必选|类型|说明| +-|-|-|- +|login |是|string |用户标识 | +|repo_identifier |是|string |仓库标识 | + + +*返回参数说明:* + +|参数名|类型|说明| +-|-|- +|identifier |string|仓库标识| +|praises_count |int|点赞数量| +|forked_count |int|fork数量| +|watchers_count |int|关注数量| +|author |object|提交用户| +|-- login |string|用户名称| +|-- image_url |string|用户头像| + + +返回值 +``` +{ + "identifier": "mirror_demo", + "praises_count": 0, + "forked_count": 0, + "watchers_count": 0, + "author": { + "name": "18816895620", + "image_url": "avatars/User/b" + } +} +``` +--- + ## 获取提交记录列表 ``` GET /api/:login/:repo_identifier/commits @@ -951,10 +1077,11 @@ 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 +curl -X POST \ +-d 'filepath=test_create_file.rb' \ +-d 'branch=master' \ +-d 'content=ZnNmc2FkZg==' \ +http://localhost:3000/api/18816895620/mirror_demo/contents | jq ``` *请求参数说明:* diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index d2624eebe..8e9412123 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -2,6 +2,9 @@ class RepositoriesController < ApplicationController include ApplicationHelper before_action :find_user, :find_repository, :authorizate! + def show + end + def entries @entries = Gitea::Repository::Entries::ListService.new(@user, @repo.identifier, ref: params[:ref]).call end @@ -23,6 +26,10 @@ class RepositoriesController < ApplicationController @commit = Gitea::Repository::Commits::GetService.new(@user, @repo.identifier, params[:sha]).call end + def tags + @tags = Gitea::Repository::Tags::ListService.new(@user, @repo.identifier).call + end + private def authorizate! if @repo.hidden? && @repo.user != current_user diff --git a/app/models/project.rb b/app/models/project.rb index 7a3df8e2b..02ecd7a79 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1,6 +1,7 @@ class Project < ApplicationRecord include Matchable include Publicable + include Watchable enum project_type: { mirror: 1, common: 0 } # common:开源托管项目, mirror:开源镜像项目 diff --git a/app/models/watcher.rb b/app/models/watcher.rb index d9426e03c..3b613b9f0 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -1,4 +1,4 @@ class Watcher < ApplicationRecord belongs_to :user - belongs_to :watchable, polymorphic: true -end \ No newline at end of file + belongs_to :watchable, polymorphic: true, counter_cache: :watchers_count +end diff --git a/app/views/repositories/show.json.jbuilder b/app/views/repositories/show.json.jbuilder new file mode 100644 index 000000000..a515a9509 --- /dev/null +++ b/app/views/repositories/show.json.jbuilder @@ -0,0 +1,5 @@ +json.identifier @repo.identifier +json.praises_count @repo.project.praises_count +json.forked_count @repo.project.forked_count +json.watchers_count @repo.project.watchers_count +json.partial! 'author', locals: { user: @repo.user } diff --git a/config/routes.rb b/config/routes.rb index 5cc9a565e..5126e2ad0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,4 +1,5 @@ Rails.application.routes.draw do + require 'sidekiq/web' require 'admin_constraint' mount Sidekiq::Web => '/sidekiq', :constraints => AdminConstraint.new @@ -72,12 +73,22 @@ Rails.application.routes.draw do end end + get '/:login/:repo_identifier', to: 'repositories#show' resources :repositories, path: '/:login/:repo_identifier', only: [:index] do collection do get :entries get :sub_entries get :commits get :single_commit + post :files + get :tags + end + end + + resources :contents, path: '/:login/:repo_identifier/contents', only: [:create] do + collection do + put 'files/update', :action => 'update_file' + delete 'files/delete', :action => 'delete_file' end end diff --git a/db/migrate/20200106022235_add_watchers_count_to_projects.rb b/db/migrate/20200106022235_add_watchers_count_to_projects.rb new file mode 100644 index 000000000..551e9e5b6 --- /dev/null +++ b/db/migrate/20200106022235_add_watchers_count_to_projects.rb @@ -0,0 +1,5 @@ +class AddWatchersCountToProjects < ActiveRecord::Migration[5.2] + def change + add_column :projects, :watchers_count, :integer, :default => 0 + end +end diff --git a/public/react/src/forge/Branch/CloneAddress.js b/public/react/src/forge/Branch/CloneAddress.js new file mode 100644 index 000000000..a983612d5 --- /dev/null +++ b/public/react/src/forge/Branch/CloneAddress.js @@ -0,0 +1,32 @@ +import React , { Component } from 'react'; +import { Dropdown , Icon , Menu } from 'antd'; + +import "./branch.css" + +// 点击按钮复制功能 +function jsCopy(){ + var e = document.getElementById("copy_rep_content"); + e.select(); + document.execCommand("Copy"); +} +class CloneAddress extends Component{ + + render(){ + const { http_url , downloadUrl } = this.props; + return( +
+ this.changeAddress("http")}>HTTP + {/* this.changeAddress("ssh")}>SSH */} + + jsCopy()}> + + + + + + +
+ ) + } +} +export default CloneAddress; \ No newline at end of file diff --git a/public/react/src/forge/Branch/SelectBranch.js b/public/react/src/forge/Branch/SelectBranch.js index ca5ee9413..a3fcff973 100644 --- a/public/react/src/forge/Branch/SelectBranch.js +++ b/public/react/src/forge/Branch/SelectBranch.js @@ -1,6 +1,8 @@ import React , { Component } from 'react'; import { Dropdown , Icon , Menu } from 'antd'; +import "./branch.css" + class SelectBranch extends Component{ render(){ diff --git a/public/react/src/forge/Branch/branch.css b/public/react/src/forge/Branch/branch.css new file mode 100644 index 000000000..f54901088 --- /dev/null +++ b/public/react/src/forge/Branch/branch.css @@ -0,0 +1,9 @@ +.branchDropdown{ + border:1px solid #eee; + border-radius: 4px; + display: flex; + justify-content: center; + padding:0px 10px; + height: 35px; + line-height: 35px; +} \ No newline at end of file diff --git a/public/react/src/forge/Main/CoderRootDirectory.js b/public/react/src/forge/Main/CoderRootDirectory.js index 038f841a8..5e6be652e 100644 --- a/public/react/src/forge/Main/CoderRootDirectory.js +++ b/public/react/src/forge/Main/CoderRootDirectory.js @@ -6,13 +6,9 @@ import { getImageUrl } from 'educoder'; import axios from 'axios'; import SelectBranch from '../Branch/SelectBranch' +import CloneAddress from '../Branch/CloneAddress' + -// 点击按钮复制功能 -function jsCopy(){ - var e = document.getElementById("copy_rep_content"); - e.select(); - document.execCommand("Copy"); -} class CoderRootDirectory extends Component{ constructor(props){ super(props); @@ -163,18 +159,7 @@ class CoderRootDirectory extends Component{
-
- this.changeAddress("http")}>HTTP - {/* this.changeAddress("ssh")}>SSH */} - - jsCopy()}> - - - - - - -
+