dev_forge
SylorHuang 5 years ago
commit c1988ef6b3

@ -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
```
*请求参数说明:*

@ -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

@ -1,6 +1,7 @@
class Project < ApplicationRecord
include Matchable
include Publicable
include Watchable
enum project_type: { mirror: 1, common: 0 } # common:开源托管项目, mirror:开源镜像项目

@ -1,4 +1,4 @@
class Watcher < ApplicationRecord
belongs_to :user
belongs_to :watchable, polymorphic: true
end
belongs_to :watchable, polymorphic: true, counter_cache: :watchers_count
end

@ -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 }

@ -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

@ -0,0 +1,5 @@
class AddWatchersCountToProjects < ActiveRecord::Migration[5.2]
def change
add_column :projects, :watchers_count, :integer, :default => 0
end
end

@ -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(
<div className="gitAddressClone">
<span className={"addressType active"} onClick={()=>this.changeAddress("http")}>HTTP</span>
{/* <span className={address ==="ssh" ? "addressType active":"addressType"} onClick={()=>this.changeAddress("ssh")}>SSH</span> */}
<input type="text" id="copy_rep_content" value={ http_url }/>
<span onClick={()=>jsCopy()}><i className="iconfont icon-fuzhi"></i></span>
<span>
<Dropdown overlay={downloadUrl} trigger={['click']} placement="bottomRight">
<a className="ant-dropdown-link">
<Icon type="cloud-download" className="font-18 fl"/>
</a>
</Dropdown></span>
</div>
)
}
}
export default CloneAddress;

@ -1,6 +1,8 @@
import React , { Component } from 'react';
import { Dropdown , Icon , Menu } from 'antd';
import "./branch.css"
class SelectBranch extends Component{
render(){

@ -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;
}

@ -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{
<div className="f-wrap-between mt20">
<SelectBranch branch={branch} branchs={branchs} changeBranch={this.changeBranch}></SelectBranch>
<div className="gitAddressClone">
<span className={"addressType active"} onClick={()=>this.changeAddress("http")}>HTTP</span>
{/* <span className={address ==="ssh" ? "addressType active":"addressType"} onClick={()=>this.changeAddress("ssh")}>SSH</span> */}
<input type="text" id="copy_rep_content" value={ http_url }/>
<span onClick={()=>jsCopy()}><i className="iconfont icon-fuzhi"></i></span>
<span>
<Dropdown overlay={downloadUrl} trigger={['click']} placement="bottomRight">
<a className="ant-dropdown-link">
<Icon type="cloud-download" className="font-18 fl"/>
</a>
</Dropdown></span>
</div>
<CloneAddress http_url={http_url} downloadUrl={downloadUrl}></CloneAddress>
</div>
<Table
className="mt20 wrap-commit-table"

@ -203,15 +203,7 @@ body,#root{
.branch-wrapper span:hover{
color: #4CACFF;
}
.branchDropdown{
border:1px solid #eee;
border-radius: 4px;
display: flex;
justify-content: center;
padding:0px 10px;
height: 35px;
line-height: 35px;
}
.gitAddressClone{
display: flex;

Loading…
Cancel
Save