From 839832436686b4df5744665c0ae5e0be8533d367 Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Thu, 2 Jan 2020 11:41:58 +0800 Subject: [PATCH 1/2] ADD api --- app/controllers/projects_controller.rb | 1 + app/controllers/repositories_controller.rb | 43 +++++++++++++---- app/controllers/users_controller.rb | 10 ++-- .../repositories/search_sub_entries_form.rb | 5 ++ .../repositories/entries_interactor.rb | 47 +++++++++++++++++++ app/models/repository.rb | 4 ++ app/services/gitea/client_service.rb | 8 +++- .../gitea/repository/commits/get_service.rb | 35 ++++++++++++++ .../gitea/repository/commits/list_service.rb | 39 +++++++++++++++ .../gitea/repository/entries/get_service.rb | 38 +++++++++++++++ .../gitea/repository/entries/list_service.rb | 35 ++++++++++++++ app/views/projects/branches.json.jbuilder | 14 ++++++ app/views/repositories/_author.json.jbuilder | 4 ++ .../repositories/_simple_entry.json.jbuilder | 7 +++ app/views/repositories/commits.json.jbuilder | 10 ++++ app/views/repositories/entries.json.jbuilder | 11 +++++ .../repositories/sub_entries.json.jbuilder | 7 +++ config/routes.rb | 44 +++++------------ 18 files changed, 317 insertions(+), 45 deletions(-) create mode 100644 app/forms/repositories/search_sub_entries_form.rb create mode 100644 app/interactors/repositories/entries_interactor.rb create mode 100644 app/services/gitea/repository/commits/get_service.rb create mode 100644 app/services/gitea/repository/commits/list_service.rb create mode 100644 app/services/gitea/repository/entries/get_service.rb create mode 100644 app/services/gitea/repository/entries/list_service.rb create mode 100644 app/views/repositories/_author.json.jbuilder create mode 100644 app/views/repositories/_simple_entry.json.jbuilder create mode 100644 app/views/repositories/commits.json.jbuilder create mode 100644 app/views/repositories/entries.json.jbuilder create mode 100644 app/views/repositories/sub_entries.json.jbuilder diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 9c65867a7..424b75515 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -1,4 +1,5 @@ class ProjectsController < ApplicationController + include ApplicationHelper before_action :require_login, except: %i[index branches group_type_list] before_action :find_project, only: %i[branches] diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 25c268bc7..b496d06ad 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,16 +1,43 @@ class RepositoriesController < ApplicationController - before_action :git_base + include ApplicationHelper + before_action :find_user, :find_repository, :authorizate! - def show - repo_path = Shixun.find_by_identifier(params[:identifier]).try(:repo_name) - {repo_path: repo_path, path: params[:path]} - @entries = @git.file_tree(params) + def entries + @entries = Gitea::Repository::Entries::ListService.new(@user, @repo.identifier, ref: params[:ref]).call + end + + def sub_entries + interactor = Repositories::EntriesInteractor.call(@user, @repo.identifier, params[:filepath], ref: params[:ref]) + if interactor.success? + @sub_entries = interactor.result + else + render_error(interactor.error) + end + end + + def commits + @hash_commit = Gitea::Repository::Commits::ListService.new(@user, @repo.identifier, sha: params[:sha], page: params[:page]).call + end + + def single_commit + @commit = Gitea::Repository::Commits::GetService.new(@user, @repo.identifier, params[:sha]).call end private - def git_base - @shixun = Shixun.find_by_identifier(params[:shixun_identifier]) - @repo_namespace = @shixun.repo_path + def find_repository + @repo = @user.repositories.find_by_identifier params[:repo_identifier] + render_not_found unless @repo + end + + def find_user + @user = User.find_by_login params[:login] + render_not_found unless @user + end + + def authorizate! + if @repo.hidden? && @repo.user != current_user + render_forbidden + end end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index a1f6a5495..f61099627 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -3,11 +3,6 @@ class UsersController < ApplicationController before_action :load_user, only: [:show, :homepage_info] before_action :check_user_exist, only: [:show, :homepage_info] - # 检查是否更新 - def system_update - @notice = SystemUpdateNotice.last - end - def show;end @@ -17,6 +12,11 @@ class UsersController < ApplicationController render_ok end + def me + @user = current_user + + end + # 贴吧获取用户信接口 def get_user_info begin diff --git a/app/forms/repositories/search_sub_entries_form.rb b/app/forms/repositories/search_sub_entries_form.rb new file mode 100644 index 000000000..876965a26 --- /dev/null +++ b/app/forms/repositories/search_sub_entries_form.rb @@ -0,0 +1,5 @@ +class Repositories::SearchSubEntriesForm < BaseForm + attr_accessor :filepath, :login, :repo_identifier + + validates :filepath, :login, :repo_identifier, presence: true +end diff --git a/app/interactors/repositories/entries_interactor.rb b/app/interactors/repositories/entries_interactor.rb new file mode 100644 index 000000000..6390aa72b --- /dev/null +++ b/app/interactors/repositories/entries_interactor.rb @@ -0,0 +1,47 @@ +module Repositories + class EntriesInteractor + def self.call(user, identifier, filepath, **args) + interactor = new(user, identifier, filepath, **args) + interactor.run + interactor + end + + attr_reader :error, :result + + def initialize(user, identifier, filepath, **args) + @user = user + @identifier = identifier + @filepath = filepath + @args = args + end + + def success? + @error.nil? + end + + def result + @result + end + + def run + Repositories::SearchSubEntriesForm.new({login: user.login, repo_identifier: identifier, filepath: filepath}).validate! + sub_entries = Gitea::Repository::Entries::GetService.new(@user, @identifier, @filepath, @args).call + render_result(sub_entries) + rescue Exception => exception + fail!(exception.message) + end + + + private + + attr_reader :user, :identifier, :filepath, :args + + def fail!(error) + @error = error + end + + def render_result(response) + @result = response + end + end +end diff --git a/app/models/repository.rb b/app/models/repository.rb index d21761af2..b51463c4b 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -4,4 +4,8 @@ class Repository < ApplicationRecord belongs_to :user validates :identifier, presence: true, uniqueness: true + + def to_param + self.identifier.parameterize + end end diff --git a/app/services/gitea/client_service.rb b/app/services/gitea/client_service.rb index 47483ec62..0d12c39ed 100644 --- a/app/services/gitea/client_service.rb +++ b/app/services/gitea/client_service.rb @@ -31,8 +31,14 @@ class Gitea::ClientService < ApplicationService auth_token = authen_params(params[:token]) conn(auth_token).get do |req| req.url full_url(url) - req.body = params[:data].to_json + params.except(:token).each_pair do |key, value| + req.params["#{key}"] = value + end end + + # response.headers.each do |k,v| + # puts "#{k}:#{v}" + # end #=> 响应头 end def delete(url, params={}) diff --git a/app/services/gitea/repository/commits/get_service.rb b/app/services/gitea/repository/commits/get_service.rb new file mode 100644 index 000000000..fea12493d --- /dev/null +++ b/app/services/gitea/repository/commits/get_service.rb @@ -0,0 +1,35 @@ +# Get a single commit from a repository +class Gitea::Repository::Commits::GetService < Gitea::ClientService + attr_reader :user, :repo_name, :sha + + # sha: the commit hash + def initialize(user, repo_name, sha) + @user = user + @sha = sha + @repo_name = repo_name + end + + def call + response = get(url, params) + render_result(response) + end + + private + def params + Hash.new.merge(token: user.gitea_token) + end + + def url + "/repos/#{user.login}/#{repo_name}/git/commits/#{sha}".freeze + end + + def render_result(response) + body = JSON.parse(response.body) + case response.status + when 200 + JSON.parse(response.body) + else + {status: -1, message: "#{body['message']}"} + end + end +end diff --git a/app/services/gitea/repository/commits/list_service.rb b/app/services/gitea/repository/commits/list_service.rb new file mode 100644 index 000000000..877f621ba --- /dev/null +++ b/app/services/gitea/repository/commits/list_service.rb @@ -0,0 +1,39 @@ +# Get a list of all commits from a repository +class Gitea::Repository::Commits::ListService < Gitea::ClientService + attr_reader :user, :repo_name, :args + + # sha: SHA or branch to start listing commits from (usually 'master') + def initialize(user, repo_name, **args) + @user = user + @repo_name = repo_name + @args = { sha: 'master', page: 1 }.merge(args.compact) + end + + def call + response = get(url, params) + render_result(response) + end + + private + def params + @args.merge(token: user.gitea_token) + end + + def url + "/repos/#{user.login}/#{repo_name}/commits".freeze + end + + def render_result(response) + body = JSON.parse(response.body) + case response.status + when 200 + result = {} + headers = response.headers.to_hash + body = JSON.parse(response.body) + total_count = headers["x-total"] + result.merge(total_count: total_count.to_i, body: body) + else + {status: -1, message: "#{body['message']}"} + end + end +end diff --git a/app/services/gitea/repository/entries/get_service.rb b/app/services/gitea/repository/entries/get_service.rb new file mode 100644 index 000000000..f0236a07d --- /dev/null +++ b/app/services/gitea/repository/entries/get_service.rb @@ -0,0 +1,38 @@ +class Gitea::Repository::Entries::GetService < Gitea::ClientService + attr_reader :user, :repo_name, :filepath, :args + + # ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master) + # filepath: path of the dir, file, symlink or submodule in the repo + # repo_name: the name of repository + # ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master) + def initialize(user, repo_name, filepath, **args) + @user = user + @repo_name = repo_name + @filepath = filepath + @args = {ref: 'master'}.merge(args.compact) + end + + def call + response = get(url, params) + render_result(response) + end + + private + def params + @args.merge(token: user.gitea_token) + end + + def url + "/repos/#{user.login}/#{repo_name}/contents/#{filepath}".freeze + end + + def render_result(response) + body = JSON.parse(response.body) + case response.status + when 200 + body + else + {status: -1, message: "#{body['message']}"} + end + end +end diff --git a/app/services/gitea/repository/entries/list_service.rb b/app/services/gitea/repository/entries/list_service.rb new file mode 100644 index 000000000..981061d3f --- /dev/null +++ b/app/services/gitea/repository/entries/list_service.rb @@ -0,0 +1,35 @@ +class Gitea::Repository::Entries::ListService < Gitea::ClientService + attr_reader :user, :repo_name, :args + + # ref: The name of the commit/branch/tag. Default the repository’s default branch (usually master) + # repo_name: the name of repository + def initialize(user, repo_name, **args) + @user = user + @repo_name = repo_name + @args = {ref: 'master'}.merge(args.compact) + end + + def call + response = get(url, params) + render_result(response) + end + + private + def params + @args.merge(token: user.gitea_token) + end + + def url + "/repos/#{user.login}/#{repo_name}/contents".freeze + end + + def render_result(response) + body = JSON.parse(response.body) + case response.status + when 200 + body + else + {status: -1, message: "#{body['message']}"} + end + end +end diff --git a/app/views/projects/branches.json.jbuilder b/app/views/projects/branches.json.jbuilder index c93b6fbe4..97ec057d2 100644 --- a/app/views/projects/branches.json.jbuilder +++ b/app/views/projects/branches.json.jbuilder @@ -1,3 +1,17 @@ json.array! @branches do |branch| json.name branch['name'] + json.user_can_push branch['user_can_push'] + json.user_can_merge branch['user_can_merge'] + json.protected branch['protected'] + json.last_commit do + json.id branch['commit']['id'] + json.message branch['commit']['message'] + json.timestamp render_unix_time(branch['commit']['timestamp']) + json.time_from_now time_from_now(branch['commit']['timestamp']) + end + json.author do + user = User.find_by_login branch['commit']['author']['name'] + json.login user.login + json.image_url url_to_avatar(user) + end end diff --git a/app/views/repositories/_author.json.jbuilder b/app/views/repositories/_author.json.jbuilder new file mode 100644 index 000000000..9c867354a --- /dev/null +++ b/app/views/repositories/_author.json.jbuilder @@ -0,0 +1,4 @@ +json.author do + json.name user.login + json.image_url url_to_avatar(user) +end diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder new file mode 100644 index 000000000..bb3589591 --- /dev/null +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -0,0 +1,7 @@ +json.name entry['name'] +json.sha entry['sha'] +json.path entry['path'] +json.type entry['type'] +json.size entry['size'] +json.content entry['content'] +json.target entry['target'] diff --git a/app/views/repositories/commits.json.jbuilder b/app/views/repositories/commits.json.jbuilder new file mode 100644 index 000000000..396efbfc0 --- /dev/null +++ b/app/views/repositories/commits.json.jbuilder @@ -0,0 +1,10 @@ +json.total_count @hash_commit[:total_count] +json.commits do + json.array! @hash_commit[:body] do |commit| + json.sha commit['sha'] + json.message commit['commit']['message'] + json.timestamp render_unix_time(commit['commit']['author']['date']) + json.time_from_now time_from_now(commit['commit']['author']['date']) + json.partial! 'author', user: @repo.user + end +end diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder new file mode 100644 index 000000000..6dc9b4320 --- /dev/null +++ b/app/views/repositories/entries.json.jbuilder @@ -0,0 +1,11 @@ +json.array! @entries do |entry| + json.name entry['name'] + json.path entry['path'] + json.sha entry['sha'] + json.type entry['type'] + json.size entry['size'] + json.content entry['content'] + json.target entry['target'] + json.content entry['content'] + json.commit entry['commit'] +end diff --git a/app/views/repositories/sub_entries.json.jbuilder b/app/views/repositories/sub_entries.json.jbuilder new file mode 100644 index 000000000..bbce2df50 --- /dev/null +++ b/app/views/repositories/sub_entries.json.jbuilder @@ -0,0 +1,7 @@ +if @sub_entries.is_a? Array + json.array! @sub_entries do |entry| + json.partial! 'repositories/simple_entry', locals: { entry: entry } + end +else + json.partial! 'repositories/simple_entry', locals: { entry: @sub_entries } +end diff --git a/config/routes.rb b/config/routes.rb index 6be06bbfc..19d41c18b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -59,7 +59,14 @@ Rails.application.routes.draw do end end - resources :repositories + resources :repositories, path: '/:login/:repo_identifier', only: [:index] do + collection do + get :entries + get :sub_entries + get :commits + get :single_commit + end + end # resources :memos do # member do @@ -129,38 +136,12 @@ Rails.application.routes.draw do member do get :homepage_info end - get 'me', on: :collection - - get :question_banks, on: :collection, to: 'users/question_banks#index' - - scope module: :users do - resources :courses, only: [:index] - resources :shixuns, only: [:index] - resources :projects, only: [:index] - resources :subjects, only: [:index] - # hacks :question_banks, only: [:index] - resource :experience_records, only: [:show] - resource :grade_records, only: [:show] - resource :watch, only: [:create, :destroy] - resources :project_packages, only: [:index] - # 私信 - resources :private_messages, only: [:index, :create, :destroy] - resources :recent_contacts, only: [:index] - resource :private_message_details, only: [:show] - resource :unread_message_info, only: [:show] - - # 视频 - resources :videos, only: [:index, :update] do - collection do - get :review - post :batch_publish - post :cancel - end - end - resource :video_auths, only: [:create, :update] - end + resources :repositories do + + end + collection do post :following post :unfollow @@ -173,6 +154,7 @@ Rails.application.routes.draw do post :brief_introduction post :attendance get :system_update + get :me resource :trial_apply, only: [:create] resources :projects, module: :users, only: [] do From 4024aa496241459f381df3b3efbb74ab2b12837d Mon Sep 17 00:00:00 2001 From: Jasder <2053003901@@qq.com> Date: Thu, 2 Jan 2020 11:56:55 +0800 Subject: [PATCH 2/2] Update api documents --- README.md | 511 ++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 364 insertions(+), 147 deletions(-) diff --git a/README.md b/README.md index 86dbefd0f..9b188c2fc 100644 --- a/README.md +++ b/README.md @@ -243,14 +243,13 @@ POST api/projects ``` curl -X POST \ -d "user_id=36401" \ --d "name=好项目" \ +-d "name=hnfl_demo" \ -d "description=my first project" \ --d "repository_name=gorails" \ +-d "repository_name=hnfl_demo" \ -d "project_category_id=1" \ -d "project_language_id=2" \ --d "ignore_id=2000" \ +-d "ignore_id=2" \ -d "license_id=1" \ --d "private=true" http://localhost:3000/api/projects/ | jq ``` *请求参数说明:* @@ -332,34 +331,23 @@ http://localhost:3000/api/projects/migrate | jq ``` --- -#### 项目详情 +#### 获取代码目录列表 ``` -POST api/projects/:identifier +POST api/:login/:repo_identifier/entries ``` *示例* ``` curl -X GET \ --d "user_id=36401" \ --d "clone_addr=https://gitea.com/CasperVector/slew.git" \ --d "name=ni项目" \ --d "description=my first project" \ --d "repository_name=mirror_demo" \ --d "project_category_id=1" \ --d "project_language_id=2" \ -http://localhost:3000/api/projects/migrate | jq +-d "ref=develop" \ +http://localhost:3000/api/18816895620/mirror_demo/entries | jq ``` *请求参数说明:* |参数名|必选|类型|说明| -|-|-|- -|user_id |是|int |用户id或者组织id | -|name |是|string |项目名称 | -|clone_addr |是|string |镜像项目clone地址 | -|description |否|string |项目描述 | -|repository_name |是|string |仓库名称, 只含有数字、字母、下划线不能以下划线开头和结尾,且唯一 | -|project_category_id|是|int |项目类别id | -|project_language_id|是|int |项目语言id | -|private |否|boolean|项目是否私有, true:为私有,false: 非私有,默认为公开 | +|login |是|string |用户标识(login) | +|repo_identifier |是|string |仓库标识(identifier) | +|ref |否|string |分支名称、tag名称或是提交记录id,默认为master分支 | *返回参数说明:* @@ -367,15 +355,127 @@ http://localhost:3000/api/projects/migrate | jq |参数名|类型|说明| -|-|- |id |int |id | -|name |string|项目名称| - +|name |string|文件夹或文件名称| +|path |string|文件夹或文件相对路径| +|type |string|文件类型, file:文件,dir:文件目录| +|size |int|文件夹或文件大小 单位KB| +|content |string|文件内容,| +|target |string|标签| 返回值 ``` +[ { - "id": 3263, - "name": "ni项目" + "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 } +] +``` +--- + +#### 获取子目录代码列表 +``` +POST api/:login/:repo_identifier/sub_entries +``` +*示例* +``` +curl -X GET \ +-d "ref=develop" \ +-d "filepath=lib/slew.rc" \ +http://localhost:3000/api/18816895620/mirror_demo/sub_entries | jq +``` +*请求参数说明:* + +|参数名|必选|类型|说明| +-|-|-|- +|login |是|string |用户标识(login) | +|repo_identifier |是|string |仓库标识(identifier) | +|filepath |是|string |文件夹、文件路径 | +|ref |否|string |分支名称、tag名称或是提交记录id,默认为master分支 | + + +*返回参数说明:* + +|参数名|类型|说明| +-|-|- +|id |int |id | +|name |string|文件夹或文件名称| +|path |string|文件夹或文件相对路径| +|type |string|文件类型, file:文件,dir:文件目录| +|size |int|文件夹或文件大小 单位KB| +|content |string|文件内容,| +|target |string|标签| +|url |string|文件访问链接,带分支| +|html_url |string|文件访问链接,未标识分支| +|git_url |string|文件夹或文件的git仓库访问链接| +|download_url |string|文件下载、文件内容访问链接| + +返回值 +``` +[ + { + "name": "build.rc", + "path": "lib/build.rc", + "type": "", + "size": 1268, + "content": null, + "target": null, + "url": "http://localhost:3003/api/v1/repos/18816895620/mirror_demo/contents/lib/build.rc?ref=master", + "html_url": "http://localhost:3003/18816895620/mirror_demo/src/branch/master/lib/build.rc", + "git_url": "http://localhost:3003/api/v1/repos/18816895620/mirror_demo/git/blobs/191fcf1a63b3777e2977fcede7dd5309efdd70fe", + "download_url": null + }, + { + "name": "cfg.rc", + "path": "lib/cfg.rc", + "type": "file", + "size": 107, + "content": null, + "target": null, + "url": "http://localhost:3003/api/v1/repos/18816895620/mirror_demo/contents/lib/cfg.rc?ref=master", + "html_url": "http://localhost:3003/18816895620/mirror_demo/src/branch/master/lib/cfg.rc", + "git_url": "http://localhost:3003/api/v1/repos/18816895620/mirror_demo/git/blobs/0b91ba0ed1c00e130c77bb9058af3787fea986a0", + "download_url": "http://localhost:3003/18816895620/mirror_demo/raw/branch/master/lib/cfg.rc" + }, + { + "name": "fn", + "path": "lib/fn", + "type": "dir", + "size": 0, + "content": null, + "target": null, + "url": "http://localhost:3003/api/v1/repos/18816895620/mirror_demo/contents/lib/fn?ref=master", + "html_url": "http://localhost:3003/18816895620/mirror_demo/src/branch/master/lib/fn", + "git_url": "http://localhost:3003/api/v1/repos/18816895620/mirror_demo/git/blobs/e33bd45949ef8f804471d0b6b2c59728eb445989", + "download_url": null + } +] ``` --- @@ -473,7 +573,7 @@ http://localhost:3000/api/projects | jq |limit |否|string |每页多少条数据,默认15条 | |sort_by |否|string |排序类型, 取值:updated_on \| created_on \| forked_count \| praises_count, updated_on: 更新时间排序,created_on: 创建时间排序,forked_count: fork数据排序,praises_count: 点赞数量排序,默认为updated_on更新时间排序 | |sort_direction|否|string |排序方式,取值为: desc \| asc; desc: 降序排序, asc: 升序排序, 默认为:desc | -|name |否|string |项目名称, 按照项目名称搜索 | +|search |否|string |按照项目名称搜索 | |category_id |否|int |项目类别id | |language_id |否|int |项目语言id | |project_type |否|string |项目类型, 取值为:common \| mirror; common:开源托管项目, mirror:开源镜像项目 | @@ -483,134 +583,148 @@ http://localhost:3000/api/projects | jq |参数名|类型|说明| -|-|- -|id |string |项目标识 | -|name |string|项目名称| -|description |string|项目简介| -|visits |int|流量数| -|forked_count |int|被fork的数量| -|is_public |boolean|是否公开, true:公开,false:未公开| -|mirror_url |string|镜像url| -|last_update_time |int|最后更新时间,为UNIX格式的时间戳| -|author |object|项目创建者| -|-- name |string|用户名,也是用户标识| -|category |object|项目类别| +|total_count |int |项目总条数 | +|id |string |项目标识 | +|name |string|项目名称| +|description |string|项目简介| +|visits |int|流量数| +|forked_count |int|被fork的数量| +|praises_count |int|star数量| +|is_public |boolean|是否公开, true:公开,false:未公开| +|mirror_url |string|镜像url| +|last_update_time|int|最后更新时间,为UNIX格式的时间戳| +|author |object|项目创建者| +|-- name |string|用户名,也是用户标识| +|category |object|项目类别| |-- id |int|项目类型id| -|-- name |string|项目类型名称| -|language |object|项目语言| +|-- name |string|项目类型名称| +|language |object|项目语言| |-- id |int|项目语言id| -|-- name |string|项目语言名称| - +|-- name |string|项目语言名称| 返回值 ``` -[ - { - "id": "tongjj", - "name": "统计局", - "description": "my first project", - "visits": 0, - "forked_count": 0, - "is_public": true, - "mirror_url": null, - "last_update_time": 1577415173, - "author": { - "name": "18816895620" - }, - "category": { - "id": 1, - "name": "大数据" - }, - "language": { - "id": 2, - "name": "C" - } - }, - { - "id": null, - "name": "开源同名", - "description": "my first project", - "visits": 0, - "forked_count": 0, - "is_public": false, - "mirror_url": "https://gitea.com/CasperVector/slew.git", - "last_update_time": 1577346228, - "author": { - "name": "18816895620" - }, - "category": { - "id": 1, - "name": "大数据" - }, - "language": { - "id": 2, - "name": "C" - } - }, - { - "id": "mvp_demo", - "name": "开源支持", - "description": "my first project", - "visits": 0, - "forked_count": 0, - "is_public": true, - "mirror_url": null, - "last_update_time": 1577341572, - "author": { - "name": "18816895620" - }, - "category": { - "id": 1, - "name": "大数据" - }, - "language": { - "id": 2, - "name": "C" - } - }, - { - "id": null, - "name": "ni项目1", - "description": "my first project", - "visits": 0, - "forked_count": 0, - "is_public": true, - "mirror_url": "https://gitea.com/CasperVector/slew.git", - "last_update_time": 1577092908, - "author": { - "name": "18816895620" +{ + "total_count": 3096, + "projects": [ + { + "id": "hnfl_demo1", + "name": "hnfl_demo1", + "description": "my first project", + "visits": 0, + "praises_count": 0, + "forked_count": 0, + "is_public": true, + "mirror_url": null, + "last_update_time": 1577697461, + "author": { + "name": "18816895620", + "image_url": "avatars/User/b" + }, + "category": { + "id": 1, + "name": "大数据" + }, + "language": { + "id": 2, + "name": "C" + } }, - "category": { - "id": 1, - "name": "大数据" + { + "id": "hnfl_demo", + "name": "hnfl_demo", + "description": "my first project", + "visits": 0, + "praises_count": 0, + "forked_count": 0, + "is_public": true, + "mirror_url": null, + "last_update_time": 1577697403, + "author": { + "name": "18816895620", + "image_url": "avatars/User/b" + }, + "category": { + "id": 1, + "name": "大数据" + }, + "language": { + "id": 2, + "name": "C" + } }, - "language": { - "id": 2, - "name": "C" - } - }, - { - "id": "mirror_demo", - "name": "ni项目", - "description": "my first project", - "visits": 0, - "forked_count": 0, - "is_public": false, - "mirror_url": "https://gitea.com/CasperVector/slew.git", - "last_update_time": 1577085412, - "author": { - "name": "18816895620" + { + "id": "tongjj", + "name": "统计局", + "description": "my first project", + "visits": 0, + "praises_count": 0, + "forked_count": 0, + "is_public": true, + "mirror_url": null, + "last_update_time": 1577415173, + "author": { + "name": "18816895620", + "image_url": "avatars/User/b" + }, + "category": { + "id": 1, + "name": "大数据" + }, + "language": { + "id": 2, + "name": "C" + } }, - "category": { - "id": 1, - "name": "大数据" + { + "id": null, + "name": "开源同名", + "description": "my first project", + "visits": 0, + "praises_count": 0, + "forked_count": 0, + "is_public": false, + "mirror_url": "https://gitea.com/CasperVector/slew.git", + "last_update_time": 1577346228, + "author": { + "name": "18816895620", + "image_url": "avatars/User/b" + }, + "category": { + "id": 1, + "name": "大数据" + }, + "language": { + "id": 2, + "name": "C" + } }, - "language": { - "id": 2, - "name": "C" + { + "id": "mvp_demo", + "name": "开源支持", + "description": "my first project", + "visits": 0, + "praises_count": 0, + "forked_count": 0, + "is_public": true, + "mirror_url": null, + "last_update_time": 1577341572, + "author": { + "name": "18816895620", + "image_url": "avatars/User/b" + }, + "category": { + "id": 1, + "name": "大数据" + }, + "language": { + "id": 2, + "name": "C" + } } - } -] + ] +} ``` --- @@ -633,22 +747,125 @@ curl -X GET http://localhost:3000/api/projects/mirror_demo/branches | jq |参数名|类型|说明| -|-|- -|name |string|分支名称| +|name |string|分支名称| +|user_can_push |boolean|用户是否可push| +|user_can_merge |boolean|用户是否客merge| +|protected |boolean|是否为保护分支| +|last_commit |object|最后提交记录| +|-- id |string|提交记录id| +|-- message |string|提交的说明信息| +|-- timestamp |int|提交时间,为UNIX时间戳| +|-- time_from_now|string|转换后的时间| +|author |object|提交用户| +|-- login |string|用户名称| +|-- image_url |string|用户头像| 返回值 ``` [ { - "name": "develop" + "name": "develop", + "user_can_push": true, + "user_can_merge": true, + "protected": false, + "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" + "name": "master", + "user_can_push": true, + "user_can_merge": true, + "protected": false, + "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/commits +``` +*示例* +``` +curl -X GET \ +-d "sha=develop" \ +-d "page=1" \ +http://localhost:3000/api/18816895620/mirror_demo/commits | jq +``` +*请求参数说明:* + +|参数名|必选|类型|说明| +-|-|-|- +|login |是|string |用户标识 | +|repo_identifier |是|string |仓库标识 | +|sha |否|string |分支名称、提交记录的sha标识,默认为master分支 | +|page |否|int |页数, 默认为1 | + + +*返回参数说明:* + +|参数名|类型|说明| +-|-|- +|total_count|int|总记录条数| +|commits |array|提交记录的数组| +|-- sha |string|提交记录sha标识| +|-- message |string|提交的备注说明| +|-- timestamp |int|提交UNIX时间戳| +|-- time_from_now|string|提交距离当前的时间| +|author |object|提交用户| +|-- login |string|用户名称| +|-- image_url |string|用户头像| + + +返回值 +``` +{ + "total_count": 63, + "commits": [ + { + "sha": "19ac3bc45f62cc87a94b8ecce61101d8fd2dafd2", + "message": "合并pull request测试", + "timestamp": 1577244567, + "time_from_now": "7天前", + "author": { + "name": "18816895620", + "image_url": "avatars/User/b" + } + }, + { + "sha": "2b33c5f55214db41879936312ee43611406c4dbd", + "message": "FIX .", + "timestamp": 1577244474, + "time_from_now": "7天前", + "author": { + "name": "18816895620", + "image_url": "avatars/User/b" + } + } + ] +} +``` +--- + ### 点赞 ``` POST /api/praise_tread/like