From 91feb8cf89fb9d127a5e0365a52f76bf11a4dd87 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 7 Sep 2021 18:39:11 +0800 Subject: [PATCH 01/34] add: project branch_slice --- app/controllers/projects_controller.rb | 7 ++++++ .../repository/branches/list_slice_service.rb | 22 +++++++++++++++++++ app/services/repositories/detail_service.rb | 9 +++++++- .../projects/branches_slice.json.jbuilder | 20 +++++++++++++++++ app/views/repositories/detail.json.jbuilder | 9 ++++++++ config/routes.rb | 1 + 6 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 app/services/gitea/repository/branches/list_slice_service.rb create mode 100644 app/views/projects/branches_slice.json.jbuilder diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 78056beed..b19d2b633 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -86,6 +86,13 @@ class ProjectsController < ApplicationController @branches = result.is_a?(Hash) && result.key?(:status) ? [] : result end + def branches_slice + return @branches = [] unless @project.forge? + + slice_result = Gitea::Repository::Branches::ListSliceService.call(@owner, @project.identifier) + @branches_slice = slice_result.is_a?(Hash) && slice_result.key?(:status) ? [] : slice_result + end + def group_type_list project_statics = ProjectStatistic.first diff --git a/app/services/gitea/repository/branches/list_slice_service.rb b/app/services/gitea/repository/branches/list_slice_service.rb new file mode 100644 index 000000000..6b643831a --- /dev/null +++ b/app/services/gitea/repository/branches/list_slice_service.rb @@ -0,0 +1,22 @@ +class Gitea::Repository::Branches::ListSliceService < Gitea::ClientService + attr_reader :user, :repo + + def initialize(user, repo) + @user = user + @repo = repo + end + + def call + response = get(url, params) + render_200_response(response) + end + + private + def params + Hash.new.merge(token: user.gitea_token) + end + + def url + "/repos/#{user.login}/#{repo}/branches/branches_slice".freeze + end +end diff --git a/app/services/repositories/detail_service.rb b/app/services/repositories/detail_service.rb index d8853cf45..7488ce24d 100644 --- a/app/services/repositories/detail_service.rb +++ b/app/services/repositories/detail_service.rb @@ -13,6 +13,7 @@ class Repositories::DetailService < ApplicationService repo: {}, release: [], branch: [], + branch_type: [], tag: [], contributor: [], language: {}, @@ -23,6 +24,7 @@ class Repositories::DetailService < ApplicationService repo: repo_suitable, release: release_suitable, branch: branch_suitable, + branch_slice: branch_slice_suitable, tag: tag_suitable, contributor: contributor_suitable, language: language_suitable, @@ -43,7 +45,12 @@ class Repositories::DetailService < ApplicationService def branch_suitable branches = Gitea::Repository::Branches::ListService.call(@owner, @repo.identifier) - branches.is_a?(Hash) && branches[:status] == :error ? [] : branches + branches.is_a?(Hash) && branches.key?(:status) ? [] : branches + end + + def branch_slice_suitable + branches = Gitea::Repository::Branches::ListSliceService.call(@owner, @repo.identifier) + branches.is_a?(Hash) && branches.key?(:status) == :error ? [] : branches end def tag_suitable diff --git a/app/views/projects/branches_slice.json.jbuilder b/app/views/projects/branches_slice.json.jbuilder new file mode 100644 index 000000000..2731b1513 --- /dev/null +++ b/app/views/projects/branches_slice.json.jbuilder @@ -0,0 +1,20 @@ +json.array! @branches_slice do |branch_slice| + json.branch_type branch_slice['branch_name'] + json.list branch_slice['branches'].each 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.http_url render_http_url(@project) + json.zip_url render_zip_url(@owner, @repository, branch['name']) + json.tar_url render_tar_url(@owner, @repository, branch['name']) + json.last_commit do + json.sha 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']) + json.author branch['commit']['author'] + json.committer branch['commit']['committer'] + end + end +end \ No newline at end of file diff --git a/app/views/repositories/detail.json.jbuilder b/app/views/repositories/detail.json.jbuilder index c00ae3462..18b5dd887 100644 --- a/app/views/repositories/detail.json.jbuilder +++ b/app/views/repositories/detail.json.jbuilder @@ -72,6 +72,15 @@ json.branches do end json.total_count @result[:branch].size end +json.branches_slice do + json.list @result[:branch_slice].each do |branch_slice| + json.branch_type branch_slice["branch_name"] + json.list branch_slice["branches"].each do |branch| + json.name branch["name"] + end + end + json.total_count @result[:branch_slice].size +end json.tags do json.list @result[:tag].each do |tag| json.name tag["name"] diff --git a/config/routes.rb b/config/routes.rb index 9c6dda1b0..1f029db3a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -416,6 +416,7 @@ Rails.application.routes.draw do member do get :menu_list get :branches + get :branches_slice get :simple get :watchers, to: 'projects#watch_users' get :stargazers, to: 'projects#praise_users' From af7488505db2c5ccc2be7f1a7b730238b11e16a8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 8 Sep 2021 09:45:15 +0800 Subject: [PATCH 02/34] add: project commit_slice --- app/controllers/repositories_controller.rb | 5 +++ .../repository/commits/list_slice_service.rb | 42 +++++++++++++++++++ .../repositories/commits_slice.json.jbuilder | 38 +++++++++++++++++ config/routes.rb | 1 + 4 files changed, 86 insertions(+) create mode 100644 app/services/gitea/repository/commits/list_slice_service.rb create mode 100644 app/views/repositories/commits_slice.json.jbuilder diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9ef440903..db7be5c72 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -107,6 +107,11 @@ class RepositoriesController < ApplicationController sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call end + def commits_slice + @hash_commit = Gitea::Repository::Commits::ListSliceService.call(@owner.login, @project.identifier, + sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token) + end + def commit @sha = params[:sha] @commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token) diff --git a/app/services/gitea/repository/commits/list_slice_service.rb b/app/services/gitea/repository/commits/list_slice_service.rb new file mode 100644 index 000000000..04f45f55b --- /dev/null +++ b/app/services/gitea/repository/commits/list_slice_service.rb @@ -0,0 +1,42 @@ +# Get a list of all commits from a repository +class Gitea::Repository::Commits::ListSliceService < Gitea::ClientService + attr_reader :owner, :repo_name, :args + + # sha: SHA or branch to start listing commits from (usually 'master') + # ex: + # Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier, + # sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call + def initialize(owner, repo_name, **args) + @owner = owner + @repo_name = repo_name + @args = args + end + + def call + response = get(url, params) + render_result(response) + end + + private + def params + { sha: args[:sha] || 'master', page: args[:page] || PAGINATE_DEFAULT_PAGE, limit: args[:limit] || PAGINATE_DEFAULT_LIMIT, token: args[:token] || "" } + end + + def url + "/repos/#{owner}/#{repo_name}/commits_slice".freeze + end + + def render_result(response) + 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 + nil + # {status: -1, message: "#{body['message']}"} + end + end +end diff --git a/app/views/repositories/commits_slice.json.jbuilder b/app/views/repositories/commits_slice.json.jbuilder new file mode 100644 index 000000000..e252cda69 --- /dev/null +++ b/app/views/repositories/commits_slice.json.jbuilder @@ -0,0 +1,38 @@ +if @hash_commit.blank? #如果有状态值,则表示报错了 + json.total_count 0 + json.commits [] +else + json.total_count @hash_commit[:total_count] + json.commit_dates do + json.array! @hash_commit[:body] do |commit_date| + json.commit_date commit_date["commit_date"] + json.commits do + json.array! commit_date["Commits"] do |commit| + commiter = commit['committer'] + + forge_user = + if commiter.present? + User.simple_select.find_by(gitea_uid: commiter['id']) + end + + 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']) + if forge_user + json.partial! 'author', user: forge_user + else + json.author do + json.id nil + json.login commit['commit']['author']['name'] + json.type nil + json.name commit['commit']['author']['name'] + json.image_url User::Avatar.get_letter_avatar_url(commit['commit']['author']['name']) + end + end + end + end + end + end + +end diff --git a/config/routes.rb b/config/routes.rb index 1f029db3a..2a935b896 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -432,6 +432,7 @@ Rails.application.routes.draw do get :entries match :sub_entries, :via => [:get, :put] get :commits + get :commits_slice get :tags get :contributors post :create_file From 333d6a8ea475eaeb3265c7ced60293602e445ea6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 14 Sep 2021 10:59:01 +0800 Subject: [PATCH 03/34] add: branch commiter user info --- app/helpers/repositories_helper.rb | 10 +++++++--- app/views/projects/branches.json.jbuilder | 8 ++++++-- app/views/projects/branches_slice.json.jbuilder | 8 ++++++-- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index 7057ac581..d9679cb80 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -26,9 +26,13 @@ module RepositoriesHelper end def render_commit_author(author_json) - return nil if author_json.blank? || author_json["id"].blank? - # find_user_by_login author_json['name'] - find_user_by_gitea_uid author_json['id'] + return nil if author_json.blank? || (author_json["id"].blank? && author_json['name'].blank?) + if author_json["id"].present? + return find_user_by_gitea_uid author_json['id'] + end + if author_json["id"].nil? && author_json["name"].present? + return find_user_by_login author_json['name'] + end end def readme_render_decode64_content(str, path) diff --git a/app/views/projects/branches.json.jbuilder b/app/views/projects/branches.json.jbuilder index dd722c9d9..ad4f4328a 100644 --- a/app/views/projects/branches.json.jbuilder +++ b/app/views/projects/branches.json.jbuilder @@ -11,7 +11,11 @@ json.array! @branches do |branch| json.message branch['commit']['message'] json.timestamp render_unix_time(branch['commit']['timestamp']) json.time_from_now time_from_now(branch['commit']['timestamp']) - json.author branch['commit']['author'] - json.committer branch['commit']['committer'] + json.author do + json.partial! 'repositories/commit_author', user: render_commit_author(branch['commit']['author']), name: branch['commit']['author']['name'] + end + json.committer do + json.partial! 'repositories/commit_author', user: render_commit_author(branch['commit']['committer']), name: branch['commit']['committer']['name'] + end end end diff --git a/app/views/projects/branches_slice.json.jbuilder b/app/views/projects/branches_slice.json.jbuilder index 2731b1513..31c662a13 100644 --- a/app/views/projects/branches_slice.json.jbuilder +++ b/app/views/projects/branches_slice.json.jbuilder @@ -13,8 +13,12 @@ json.array! @branches_slice do |branch_slice| json.message branch['commit']['message'] json.timestamp render_unix_time(branch['commit']['timestamp']) json.time_from_now time_from_now(branch['commit']['timestamp']) - json.author branch['commit']['author'] - json.committer branch['commit']['committer'] + json.author do + json.partial! 'repositories/commit_author', user: render_commit_author(branch['commit']['author']), name: branch['commit']['author']['name'] + end + json.committer do + json.partial! 'repositories/commit_author', user: render_commit_author(branch['commit']['committer']), name: branch['commit']['committer']['name'] + end end end end \ No newline at end of file From 6466ef523b785bd9741d24779a1ac5107ea232b7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 15 Sep 2021 11:47:16 +0800 Subject: [PATCH 04/34] fix --- app/services/repositories/detail_service.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/services/repositories/detail_service.rb b/app/services/repositories/detail_service.rb index 7488ce24d..984f10d51 100644 --- a/app/services/repositories/detail_service.rb +++ b/app/services/repositories/detail_service.rb @@ -50,7 +50,7 @@ class Repositories::DetailService < ApplicationService def branch_slice_suitable branches = Gitea::Repository::Branches::ListSliceService.call(@owner, @repo.identifier) - branches.is_a?(Hash) && branches.key?(:status) == :error ? [] : branches + branches.is_a?(Hash) && branches.key?(:status) ? [] : branches end def tag_suitable From ec221240042a9bb775fe19ae6f05d822e5744ca6 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Sep 2021 18:07:46 +0800 Subject: [PATCH 05/34] add: readme by filepath --- app/controllers/repositories_controller.rb | 18 +- .../slate/source/includes/_repositories.md | 57 ++ .../gitea/repository/readme/dir_service.rb | 34 + .../repositories/contributors.json.jbuilder | 2 +- public/docs/api.html | 692 ++++++++++-------- 5 files changed, 510 insertions(+), 293 deletions(-) create mode 100644 app/services/gitea/repository/readme/dir_service.rb diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index db7be5c72..a7e909eb8 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -125,7 +125,11 @@ class RepositoriesController < ApplicationController end def contributors - @contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier) + if params[:filepath].present? + @contributors = [] + else + @contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier) + end end def edit @@ -188,10 +192,16 @@ class RepositoriesController < ApplicationController end def readme - result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token) - + if params[:filepath].present? + result = Gitea::Repository::Readme::DirService.call(@owner.login, @repository.identifier, params[:filepath], params[:ref], current_user&.gitea_token) + else + result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token) + end @readme = result[:status] === :success ? result[:body] : nil - render json: @readme + + render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha") + rescue + render json: nil end def languages diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index 1552655e4..c27243da6 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -868,6 +868,63 @@ await octokit.request('GET /api/jasder/jasder_test/sub_entries.json') Success Data. +## 获取仓库README文件 +获取仓库README文件 + +> 示例: + +```shell +curl -X GET \ +-d "ref=master" \ +-d "filepath=lib" \ +http://localhost:3000/api/yystopf/csfjkkj/readme.json +``` + +```javascript +await octokit.request('GET /api/yystopf/csfjkkj/readme.json') +``` + +### HTTP 请求 +`GET /api/:owner/:repo/readme.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | +|ref |否| | string |分支名称、tag名称或是提交记录id,默认为默认分支 | +|filepath |否| | string |子目录名称,默认为空 | + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|type |string|文件类型, file:文件,dir:文件目录 +|encoding |string |编码 | +|size |int|文件夹或文件大小 单位B +|name |string|文件夹或文件名称| +|path |string|文件夹或文件相对路径| +|content |string|文件内容 +|sha |string|文件commitid + + +> 返回的JSON示例: + +```json +{ + "type": "file", + "encoding": "base64", + "size": 24, + "name": "README.md", + "path": "lib/README.md", + "content": "ZGZhc2RhZGpmIGRrZnNsCgpzZGZkZnMK", + "sha": "860962cd21c60b1a9e07d723080c87c32c18d44a" +} +``` + + + ## 获取仓库webhooks列表 获取仓库webhooks列表 diff --git a/app/services/gitea/repository/readme/dir_service.rb b/app/services/gitea/repository/readme/dir_service.rb new file mode 100644 index 000000000..587fb5d55 --- /dev/null +++ b/app/services/gitea/repository/readme/dir_service.rb @@ -0,0 +1,34 @@ +class Gitea::Repository::Readme::DirService < Gitea::ClientService + attr_reader :owner, :repo, :ref, :dir, :token + + def initialize(owner, repo, dir, ref='', token=nil) + @owner = owner + @repo = repo + @dir = dir + @ref = ref + @token = token + end + + def call + response = get(url, params) + status, message, body = render_response(response) + json_format(status, message, body) + end + + private + def params + Hash.new.merge(token: token, ref: ref) + end + + def url + "/repos/#{owner}/#{repo}/readme/#{dir}".freeze + end + + def json_format(status, message, body) + case status + when 200 then success(body) + when 404 then error(message, 404) + else error(message, status) + end + end +end \ No newline at end of file diff --git a/app/views/repositories/contributors.json.jbuilder b/app/views/repositories/contributors.json.jbuilder index a5edb37e0..9165cf948 100644 --- a/app/views/repositories/contributors.json.jbuilder +++ b/app/views/repositories/contributors.json.jbuilder @@ -6,7 +6,7 @@ json.contributors @contributors.each do |contributor| next end json.contributions contributor["contributions"] - json.gid contributor["id"] + # json.gid contributor["id"] json.login user.login json.type user&.type json.name user.real_name diff --git a/public/docs/api.html b/public/docs/api.html index c77c08988..5e3baed1c 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -499,6 +499,9 @@
  • 获取仓库代码子目录或者文件
  • +
  • + 获取仓库README文件 +
  • 获取仓库webhooks列表
  • @@ -7247,17 +7250,19 @@ http://localhost:3000//api/jasder/jasder_test/sub_entries.json -

    获取仓库webhooks列表

    -

    获取仓库webhooks列表

    +

    获取仓库README文件

    +

    获取仓库README文件

    示例:

    curl -X GET \
    -http://localhost:3000/api/yystopf/ceshi/webhooks.json
    -
    await octokit.request('GET /api/yystopf/ceshi/webhooks.json')
    +-d "ref=master" \
    +-d "filepath=lib" \
    +http://localhost:3000/api/yystopf/csfjkkj/readme.json
    +
    await octokit.request('GET /api/yystopf/csfjkkj/readme.json')
     

    HTTP 请求

    -

    GET /api/:owner/:repo/webhooks.json

    +

    GET /api/:owner/:repo/readme.json

    请求参数:

    @@ -7282,6 +7287,20 @@ http://localhost:3000/api/yystopf/ceshi/webhooks.json + + + + + + + + + + + + + +
    string 项目标识identifier
    refstring分支名称、tag名称或是提交记录id,默认为默认分支
    filepathstring子目录名称,默认为空

    返回字段说明:

    @@ -7292,6 +7311,103 @@ http://localhost:3000/api/yystopf/ceshi/webhooks.json + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    typestring文件类型, file:文件,dir:文件目录
    encodingstring编码
    sizeint文件夹或文件大小 单位B
    namestring文件夹或文件名称
    pathstring文件夹或文件相对路径
    contentstring文件内容
    shastring文件commitid
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "type": "file",
    +    "encoding": "base64",
    +    "size": 24,
    +    "name": "README.md",
    +    "path": "lib/README.md",
    +    "content": "ZGZhc2RhZGpmIGRrZnNsCgpzZGZkZnMK",
    +    "sha": "860962cd21c60b1a9e07d723080c87c32c18d44a"
    +}
    +
    + +

    获取仓库webhooks列表

    +

    获取仓库webhooks列表

    + +
    +

    示例:

    +
    +
    curl -X GET \
    +http://localhost:3000/api/yystopf/ceshi/webhooks.json
    +
    await octokit.request('GET /api/yystopf/ceshi/webhooks.json')
    +

    HTTP 请求

    +

    GET /api/:owner/:repo/webhooks.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    +

    返回字段说明:

    + + + + + + + + @@ -7385,9 +7501,9 @@ http://localhost:3000/api/yystopf/ceshi/webhooks.json
    curl -X GET \
     http://localhost:3000/api/yystopf/ceshi/webhooks/3/edit.json
     
    await octokit.request('GET /api/yystopf/ceshi/webhooks/3/edit.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/webhooks/:id/edit.json

    -

    请求参数:

    +

    请求参数:

    参数类型字段说明
    id int id
    @@ -7419,7 +7535,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/edit.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -7620,266 +7736,8 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/edit.json
    curl -X POST \
     http://localhost:3000/api/yystopf/ceshi/webhooks.json
     
    await octokit.request('POST /api/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    -

    POST /api/:owner/:repo/webhooks.json

    -

    请求参数:

    -
    参数
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    webhook.urlstring目标url
    webhook.typestring类型
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    - -

    触发事件字段说明

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数含义
    create创建分支或标签
    delete分支或标签删除
    fork仓库被fork
    pushgit仓库推送
    issue易修已打开、已关闭、已重新打开或编辑
    issue_assign易修被指派
    issue_label易修标签被更新或删除
    issue_milestone易修被收入里程碑
    issue_comment易修评论
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_label合并请求被贴上标签
    pull_request_milestone合并请求被记录于里程碑中
    pull_request_comment合并请求被评论
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    pull_request_review_comment合并请求被提出审查意见
    pull_request_sync合并请求被同步
    repository创建或删除仓库
    release版本发布
    - -
    -

    请求的JSON示例:

    -
    -
    {
    -    "active": true, 
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "secret": "123456",
    -    "url": "http://localhost:10000",
    -    "branch_filter": "*",
    -    "events": ["push"]
    -}
    -

    返回字段说明:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -    "id": 18,
    -    "type": "gitea",
    -    "content_type": "json",
    -    "url": "http://localhost:10000",
    -    "events": [
    -        "push"
    -    ],
    -    "active": true,
    -    "create_time": "2021-07-26 18:53:43"
    -}
    -
    - -

    更新仓库webhook

    -

    更新仓库webhook

    - -
    -

    示例:

    -
    -
    curl -X PATCH \
    -http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    -
    await octokit.request('PATCH /api/yystopf/ceshi/webhooks/7.json')
     

    HTTP 请求

    -

    PATCH /api/:owner/:repo/webhooks/:id.json

    +

    POST /api/:owner/:repo/webhooks.json

    请求参数:

    @@ -7905,13 +7763,6 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json - - - - - - - @@ -8072,28 +7923,79 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json "events": ["push"] }

    返回字段说明:

    +
    项目标识identifier
    idstringwebhook id
    webhook.url
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    +

    返回的JSON示例:

    {
    -    "status": 0,
    -    "message": "success"
    +    "id": 18,
    +    "type": "gitea",
    +    "content_type": "json",
    +    "url": "http://localhost:10000",
    +    "events": [
    +        "push"
    +    ],
    +    "active": true,
    +    "create_time": "2021-07-26 18:53:43"
     }
     
    -

    删除仓库webhook

    -

    删除仓库webhook

    +

    更新仓库webhook

    +

    更新仓库webhook

    示例:

    -
    curl -X DELETE \
    +
    curl -X PATCH \
     http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    -
    await octokit.request('DELETE /api/yystopf/ceshi/webhooks/7.json')
    +
    await octokit.request('PATCH /api/yystopf/ceshi/webhooks/7.json')
     

    HTTP 请求

    -

    DELETE /api/:owner/:repo/webhooks/:id.json

    +

    PATCH /api/:owner/:repo/webhooks/:id.json

    请求参数:

    @@ -8125,8 +8027,222 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    string webhook id
    webhook.urlstring目标url
    webhook.typestring类型
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    -

    返回字段说明:

    + +

    触发事件字段说明

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数含义
    create创建分支或标签
    delete分支或标签删除
    fork仓库被fork
    pushgit仓库推送
    issue易修已打开、已关闭、已重新打开或编辑
    issue_assign易修被指派
    issue_label易修标签被更新或删除
    issue_milestone易修被收入里程碑
    issue_comment易修评论
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_label合并请求被贴上标签
    pull_request_milestone合并请求被记录于里程碑中
    pull_request_comment合并请求被评论
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    pull_request_review_comment合并请求被提出审查意见
    pull_request_sync合并请求被同步
    repository创建或删除仓库
    release版本发布
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "active": true, 
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "secret": "123456",
    +    "url": "http://localhost:10000",
    +    "branch_filter": "*",
    +    "events": ["push"]
    +}
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +
    + +

    删除仓库webhook

    +

    删除仓库webhook

    + +
    +

    示例:

    +
    +
    curl -X DELETE \
    +http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    +
    await octokit.request('DELETE /api/yystopf/ceshi/webhooks/7.json')
    +

    HTTP 请求

    +

    DELETE /api/:owner/:repo/webhooks/:id.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    idstringwebhook id
    +

    返回字段说明:

    返回的JSON示例:

    @@ -8147,9 +8263,9 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    curl -X GET \
     http://localhost:3000/api/yystopf/ceshi/webhooks/3/tasks.json
     
    await octokit.request('GET /api/yystopf/ceshi/webhooks/3/tasks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/webhooks/:id/tasks.json

    -

    请求参数:

    +

    请求参数:

    @@ -8181,7 +8297,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/tasks.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -8418,9 +8534,9 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/tasks.json
    curl -X POST \
     http://localhost:3000/api/yystopf/ceshi/webhooks/3/test.json
     
    await octokit.request('POST /api/yystopf/ceshi/webhooks/3/test.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/:owner/:repo/webhooks/:id/test.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -8452,7 +8568,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/test.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    From 206bba1c4939d728ddce3e6d8d9083ba880f79bb Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Sep 2021 18:17:52 +0800 Subject: [PATCH 06/34] add: contributors by filepath --- .../slate/source/includes/_repositories.md | 65 ++ public/docs/api.html | 697 ++++++++++-------- 2 files changed, 474 insertions(+), 288 deletions(-) diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index c27243da6..eaae10746 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -924,6 +924,71 @@ await octokit.request('GET /api/yystopf/csfjkkj/readme.json') Success Data. +## 获取仓库贡献者 +获取仓库贡献者 + +> 示例: + +```shell +curl -X GET \ +-d "ref=master" \ +-d "filepath=lib" \ +http://localhost:3000/api/yystopf/csfjkkj/contributors.json +``` + +```javascript +await octokit.request('GET /api/yystopf/csfjkkj/contributors.json') +``` + +### HTTP 请求 +`GET /api/:owner/:repo/contributors.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | +|ref |否| | string |分支名称、tag名称或是提交记录id,默认为整个仓库 | +|filepath |否| | string |子目录名称,默认为空 | + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|total_count |integer|贡献者数量| +|contributions |integer|贡献数量| +|login |string |用户登录名 | +|type |string|用户类型 | +|name |string|用户昵称| +|image_url |string|用户头像| + + +> 返回的JSON示例: + +```json +{ + "contributors": [ + { + "contributions": 5, + "login": "testforge2", + "type": "User", + "name": "testforge2", + "image_url": "system/lets/letter_avatars/2/T/236_177_85/120.png" + }, + { + "contributions": 79, + "login": "yystopf", + "type": "User", + "name": "yystopf", + "image_url": "system/lets/letter_avatars/2/Y/241_125_89/120.png" + } + ], + "total_count": 2 +} +``` + + ## 获取仓库webhooks列表 获取仓库webhooks列表 diff --git a/public/docs/api.html b/public/docs/api.html index 5e3baed1c..4ec491b4f 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -502,6 +502,9 @@
  • 获取仓库README文件
  • +
  • + 获取仓库贡献者 +
  • 获取仓库webhooks列表
  • @@ -7363,17 +7366,19 @@ http://localhost:3000/api/yystopf/csfjkkj/readme.json -

    获取仓库webhooks列表

    -

    获取仓库webhooks列表

    +

    获取仓库贡献者

    +

    获取仓库贡献者

    示例:

    curl -X GET \
    -http://localhost:3000/api/yystopf/ceshi/webhooks.json
    -
    await octokit.request('GET /api/yystopf/ceshi/webhooks.json')
    +-d "ref=master" \
    +-d "filepath=lib" \
    +http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    +
    await octokit.request('GET /api/yystopf/csfjkkj/contributors.json')
     

    HTTP 请求

    -

    GET /api/:owner/:repo/webhooks.json

    +

    GET /api/:owner/:repo/contributors.json

    请求参数:

    @@ -7398,6 +7403,20 @@ http://localhost:3000/api/yystopf/ceshi/webhooks.json + + + + + + + + + + + + + +
    string 项目标识identifier
    refstring分支名称、tag名称或是提交记录id,默认为整个仓库
    filepathstring子目录名称,默认为空

    返回字段说明:

    @@ -7408,6 +7427,108 @@ http://localhost:3000/api/yystopf/ceshi/webhooks.json + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    total_countinteger贡献者数量
    contributionsinteger贡献数量
    loginstring用户登录名
    typestring用户类型
    namestring用户昵称
    image_urlstring用户头像
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "contributors": [
    +        {
    +            "contributions": 5,
    +            "login": "testforge2",
    +            "type": "User",
    +            "name": "testforge2",
    +            "image_url": "system/lets/letter_avatars/2/T/236_177_85/120.png"
    +        },
    +        {
    +            "contributions": 79,
    +            "login": "yystopf",
    +            "type": "User",
    +            "name": "yystopf",
    +            "image_url": "system/lets/letter_avatars/2/Y/241_125_89/120.png"
    +        }
    +    ],
    +    "total_count": 2
    +}
    +
    + +

    获取仓库webhooks列表

    +

    获取仓库webhooks列表

    + +
    +

    示例:

    +
    +
    curl -X GET \
    +http://localhost:3000/api/yystopf/ceshi/webhooks.json
    +
    await octokit.request('GET /api/yystopf/ceshi/webhooks.json')
    +

    HTTP 请求

    +

    GET /api/:owner/:repo/webhooks.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    +

    返回字段说明:

    + + + + + + + + @@ -7501,9 +7622,9 @@ http://localhost:3000/api/yystopf/ceshi/webhooks.json
    curl -X GET \
     http://localhost:3000/api/yystopf/ceshi/webhooks/3/edit.json
     
    await octokit.request('GET /api/yystopf/ceshi/webhooks/3/edit.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/webhooks/:id/edit.json

    -

    请求参数:

    +

    请求参数:

    参数类型字段说明
    id int id
    @@ -7535,7 +7656,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/edit.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -7736,266 +7857,8 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/edit.json
    curl -X POST \
     http://localhost:3000/api/yystopf/ceshi/webhooks.json
     
    await octokit.request('POST /api/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    -

    POST /api/:owner/:repo/webhooks.json

    -

    请求参数:

    -
    参数
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    webhook.urlstring目标url
    webhook.typestring类型
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    - -

    触发事件字段说明

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数含义
    create创建分支或标签
    delete分支或标签删除
    fork仓库被fork
    pushgit仓库推送
    issue易修已打开、已关闭、已重新打开或编辑
    issue_assign易修被指派
    issue_label易修标签被更新或删除
    issue_milestone易修被收入里程碑
    issue_comment易修评论
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_label合并请求被贴上标签
    pull_request_milestone合并请求被记录于里程碑中
    pull_request_comment合并请求被评论
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    pull_request_review_comment合并请求被提出审查意见
    pull_request_sync合并请求被同步
    repository创建或删除仓库
    release版本发布
    - -
    -

    请求的JSON示例:

    -
    -
    {
    -    "active": true, 
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "secret": "123456",
    -    "url": "http://localhost:10000",
    -    "branch_filter": "*",
    -    "events": ["push"]
    -}
    -

    返回字段说明:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -    "id": 18,
    -    "type": "gitea",
    -    "content_type": "json",
    -    "url": "http://localhost:10000",
    -    "events": [
    -        "push"
    -    ],
    -    "active": true,
    -    "create_time": "2021-07-26 18:53:43"
    -}
    -
    - -

    更新仓库webhook

    -

    更新仓库webhook

    - -
    -

    示例:

    -
    -
    curl -X PATCH \
    -http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    -
    await octokit.request('PATCH /api/yystopf/ceshi/webhooks/7.json')
     

    HTTP 请求

    -

    PATCH /api/:owner/:repo/webhooks/:id.json

    +

    POST /api/:owner/:repo/webhooks.json

    请求参数:

    @@ -8021,13 +7884,6 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json - - - - - - - @@ -8188,28 +8044,79 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json "events": ["push"] }

    返回字段说明:

    +
    项目标识identifier
    idstringwebhook id
    webhook.url
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    +

    返回的JSON示例:

    {
    -    "status": 0,
    -    "message": "success"
    +    "id": 18,
    +    "type": "gitea",
    +    "content_type": "json",
    +    "url": "http://localhost:10000",
    +    "events": [
    +        "push"
    +    ],
    +    "active": true,
    +    "create_time": "2021-07-26 18:53:43"
     }
     
    -

    删除仓库webhook

    -

    删除仓库webhook

    +

    更新仓库webhook

    +

    更新仓库webhook

    示例:

    -
    curl -X DELETE \
    +
    curl -X PATCH \
     http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    -
    await octokit.request('DELETE /api/yystopf/ceshi/webhooks/7.json')
    +
    await octokit.request('PATCH /api/yystopf/ceshi/webhooks/7.json')
     

    HTTP 请求

    -

    DELETE /api/:owner/:repo/webhooks/:id.json

    +

    PATCH /api/:owner/:repo/webhooks/:id.json

    请求参数:

    @@ -8241,8 +8148,222 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    string webhook id
    webhook.urlstring目标url
    webhook.typestring类型
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    -

    返回字段说明:

    + +

    触发事件字段说明

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数含义
    create创建分支或标签
    delete分支或标签删除
    fork仓库被fork
    pushgit仓库推送
    issue易修已打开、已关闭、已重新打开或编辑
    issue_assign易修被指派
    issue_label易修标签被更新或删除
    issue_milestone易修被收入里程碑
    issue_comment易修评论
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_label合并请求被贴上标签
    pull_request_milestone合并请求被记录于里程碑中
    pull_request_comment合并请求被评论
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    pull_request_review_comment合并请求被提出审查意见
    pull_request_sync合并请求被同步
    repository创建或删除仓库
    release版本发布
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "active": true, 
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "secret": "123456",
    +    "url": "http://localhost:10000",
    +    "branch_filter": "*",
    +    "events": ["push"]
    +}
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +
    + +

    删除仓库webhook

    +

    删除仓库webhook

    + +
    +

    示例:

    +
    +
    curl -X DELETE \
    +http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    +
    await octokit.request('DELETE /api/yystopf/ceshi/webhooks/7.json')
    +

    HTTP 请求

    +

    DELETE /api/:owner/:repo/webhooks/:id.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    idstringwebhook id
    +

    返回字段说明:

    返回的JSON示例:

    @@ -8263,9 +8384,9 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    curl -X GET \
     http://localhost:3000/api/yystopf/ceshi/webhooks/3/tasks.json
     
    await octokit.request('GET /api/yystopf/ceshi/webhooks/3/tasks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/webhooks/:id/tasks.json

    -

    请求参数:

    +

    请求参数:

    @@ -8297,7 +8418,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/tasks.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -8534,9 +8655,9 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/tasks.json
    curl -X POST \
     http://localhost:3000/api/yystopf/ceshi/webhooks/3/test.json
     
    await octokit.request('POST /api/yystopf/ceshi/webhooks/3/test.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/:owner/:repo/webhooks/:id/test.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -8568,7 +8689,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/test.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    From bbcca413c6a379e778107c9319dd886f35ddf7cf Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 23 Sep 2021 18:57:16 +0800 Subject: [PATCH 07/34] add: tags commiter message --- .../slate/source/includes/_repositories.md | 78 ++ app/helpers/application_helper.rb | 4 + app/helpers/repositories_helper.rb | 4 +- app/views/repositories/tags.json.jbuilder | 5 + public/docs/api.html | 920 ++++++++++-------- 5 files changed, 615 insertions(+), 396 deletions(-) diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index eaae10746..81dbe1441 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -274,6 +274,84 @@ await octokit.request('GET /api/yystopf/ceshi/detail.json') } ``` +## 仓库标签列表 +仓库标签列表 + +> 示例: + +```shell +curl -X GET http://localhost:3000/api/yystopf/csfjkkj/tags.json +``` + +```javascript +await octokit.request('GET /api/yystopf/csfjkkj/tags.json') +``` + +### HTTP 请求 +`GET /api/:owner/:repo/tags.json` + +### 请求参数: +参数 | 必选 | 默认 | 类型 | 字段说明 +--------- | ------- | ------- | -------- | ---------- +|owner |是| |string |用户登录名 | +|repo |是| |string |项目标识identifier | + + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|id |int |标签id | +|name |string|标签名称| +|zipball_url |string|标签zip包下载地址| +|tarball_url |string|标签tar包下载地址| +|commit |object|标签最后一个commit| +|commit.sha |string|commit的id| +|commit.message |string|commit的提交信息| +|commit.time_ago|string|commit的提交时间| +|commit.commiter|object|commit的提交者| + + +> 返回的JSON示例: + +```json +[ + { + "name": "v2.0.0", + "id": "c7d0873ee41796d1a0e193063095ccf539a9bf31", + "zipball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v2.0.0.zip", + "tarball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v2.0.0.tar.gz", + "commit": { + "sha": "08fe383f1e5ebe2e2a384a8ea3ee890a758c7cd7", + "message": "add\n", + "time_ago": "4小时前", + "committer": { + "id": 4, + "login": "testforge1", + "name": "testforge1", + "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png" + } + } + }, + { + "name": "v1.0.0", + "id": "12168ad39c3ef201a445a2db181a3e43d50e40dd", + "zipball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v1.0.0.zip", + "tarball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v1.0.0.tar.gz", + "commit": { + "sha": "5291b5e45a377c1f7710cc6647259887ed7aaccf", + "message": "ADD file via upload\n", + "time_ago": "9天前", + "committer": { + "id": 2, + "login": "yystopf", + "name": "heh", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + } + } + } +] +``` + ## 编辑仓库信息 编辑仓库信息 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 72f3f3415..c37fd59da 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -434,6 +434,10 @@ module ApplicationHelper User.find_by_login login end + def find_user_by_login_and_mail(login, mail) + User.find_by(login: login, mail: mail) + end + def find_user_by_gitea_uid(gitea_uid) User.find_by(gitea_uid: gitea_uid) end diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index d9679cb80..ee60b64a4 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -30,8 +30,8 @@ module RepositoriesHelper if author_json["id"].present? return find_user_by_gitea_uid author_json['id'] end - if author_json["id"].nil? && author_json["name"].present? - return find_user_by_login author_json['name'] + if author_json["id"].nil? && (author_json["name"].present? && author_json["email"].present?) + return find_user_by_login_and_mail(author_json['name'], author_json["email"]) end end diff --git a/app/views/repositories/tags.json.jbuilder b/app/views/repositories/tags.json.jbuilder index 9db3ff93e..011fad46a 100644 --- a/app/views/repositories/tags.json.jbuilder +++ b/app/views/repositories/tags.json.jbuilder @@ -6,6 +6,11 @@ json.array! @tags do |tag| json.tarball_url render_tar_url(@owner, @repository, tag['name']) json.commit do json.sha tag['commit']['sha'] + json.message tag['commit_message'] + json.time_ago time_from_now(tag['commit_time'].to_time) + json.committer do + json.partial! 'commit_author', user: render_commit_author(tag['commiter']), name: tag['commiter']['name'] + end end end end diff --git a/public/docs/api.html b/public/docs/api.html index 4ec491b4f..763134f4e 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -469,6 +469,9 @@
  • 仓库详情(新版)
  • +
  • + 仓库标签列表 +
  • 编辑仓库信息
  • @@ -6185,16 +6188,16 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat "Shell": "0.1%" } } -

    编辑仓库信息

    -

    编辑仓库信息

    +

    仓库标签列表

    +

    仓库标签列表

    示例:

    -
    curl -X GET http://localhost:3000/api/jasder/jasder_test/edit.json
    -
    await octokit.request('GET /api/jasder/jasder_test/edit.json')
    +
    curl -X GET http://localhost:3000/api/yystopf/csfjkkj/tags.json
    +
    await octokit.request('GET /api/yystopf/csfjkkj/tags.json')
     

    HTTP 请求

    -

    GET /api/:owner/:repo/edit.json

    +

    GET /api/:owner/:repo/tags.json

    请求参数:

    @@ -6229,6 +6232,135 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    idint标签id
    namestring标签名称
    zipball_urlstring标签zip包下载地址
    tarball_urlstring标签tar包下载地址
    commitobject标签最后一个commit
    commit.shastringcommit的id
    commit.messagestringcommit的提交信息
    commit.time_agostringcommit的提交时间
    commit.commiterobjectcommit的提交者
    + +
    +

    返回的JSON示例:

    +
    +
    [
    +    {
    +        "name": "v2.0.0",
    +        "id": "c7d0873ee41796d1a0e193063095ccf539a9bf31",
    +        "zipball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v2.0.0.zip",
    +        "tarball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v2.0.0.tar.gz",
    +        "commit": {
    +            "sha": "08fe383f1e5ebe2e2a384a8ea3ee890a758c7cd7",
    +            "message": "add\n",
    +            "time_ago": "4小时前",
    +            "committer": {
    +                "id": 4,
    +                "login": "testforge1",
    +                "name": "testforge1",
    +                "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png"
    +            }
    +        }
    +    },
    +    {
    +        "name": "v1.0.0",
    +        "id": "12168ad39c3ef201a445a2db181a3e43d50e40dd",
    +        "zipball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v1.0.0.zip",
    +        "tarball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v1.0.0.tar.gz",
    +        "commit": {
    +            "sha": "5291b5e45a377c1f7710cc6647259887ed7aaccf",
    +            "message": "ADD file via upload\n",
    +            "time_ago": "9天前",
    +            "committer": {
    +                "id": 2,
    +                "login": "yystopf",
    +                "name": "heh",
    +                "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +            }
    +        }
    +    }
    +]
    +

    编辑仓库信息

    +

    编辑仓库信息

    + +
    +

    示例:

    +
    +
    curl -X GET http://localhost:3000/api/jasder/jasder_test/edit.json
    +
    await octokit.request('GET /api/jasder/jasder_test/edit.json')
    +

    HTTP 请求

    +

    GET /api/:owner/:repo/edit.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    +

    返回字段说明:

    + + + + + + + + @@ -6297,9 +6429,9 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat -d"private=true"\ http://localhost:3000/api/jasder/jasder_test.json
    await octokit.request('PATCH /api/jasder/jasder_test.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH /api/:owner/:repo

    -

    请求参数:

    +

    请求参数:

    参数类型字段说明
    identifier string 仓库标识
    @@ -6359,7 +6491,7 @@ http://localhost:3000/api/jasder/jasder_test.json
    参数项目是否私有, true:为私有,false: 公开,默认为公开
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -6424,9 +6556,9 @@ http://localhost:3000/api/jasder/jasder_test.json
    curl -X DELETE http://localhost:3000/api/jasder/jasder_test.json
     
    await octokit.request('DELETE /api/jasder/jasder_test.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH /api/:owner/:repo

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -6451,7 +6583,7 @@ http://localhost:3000/api/jasder/jasder_test.json
    参数项目标识identifier
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -6492,83 +6624,8 @@ http://localhost:3000/api/jasder/jasder_test.json -d"user_id=12"\ http://localhost:3000/api/jasder/jasder_test/collaborators.json
    await octokit.request('POST /api/jasder/jasder_test/collaborators.json')
    -

    HTTP 请求

    -

    POST /api/:owner/:repo/collaborators.json

    -

    请求参数:

    -
    参数
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    user_idint用户id
    -

    返回字段说明:

    - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    statusint返回状态, 0: 表示操作成功
    messagestring返回信息说明
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -  "status": 0,
    -  "message": "success"
    -}
    -
    - -

    删除仓库成员

    -

    仓库中删除成员操作

    - -
    -

    示例:

    -
    -
    curl -X DELETE \
    --d "user_id=12" \
    -http://localhost:3000/api/jasder/jasder_test/collaborators.json
    -
    await octokit.request('DELETE /api/jasder/jasder_test/collaborators.json')
     

    HTTP 请求

    -

    DELETE /api/:owner/:repo/collaborators.json

    +

    POST /api/:owner/:repo/collaborators.json

    请求参数:

    @@ -6621,6 +6678,81 @@ http://localhost:3000/api/jasder/jasder_test/collaborators.json
    +
    +

    返回的JSON示例:

    +
    +
    {
    +  "status": 0,
    +  "message": "success"
    +}
    +
    + +

    删除仓库成员

    +

    仓库中删除成员操作

    + +
    +

    示例:

    +
    +
    curl -X DELETE \
    +-d "user_id=12" \
    +http://localhost:3000/api/jasder/jasder_test/collaborators.json
    +
    await octokit.request('DELETE /api/jasder/jasder_test/collaborators.json')
    +

    HTTP 请求

    +

    DELETE /api/:owner/:repo/collaborators.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    user_idint用户id
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    statusint返回状态, 0: 表示操作成功
    messagestring返回信息说明
    +

    返回的JSON示例:

    @@ -6643,9 +6775,9 @@ http://localhost:3000/api/jasder/jasder_test/collaborators.json -d "role=Developer" \ http://localhost:3000/api/jasder/jasder_test/change_role.json
    await octokit.request('PUT /api/jasder/jasder_test/change_role.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PUT /api/:owner/:repo/change_role.json

    -

    请求参数:

    +

    请求参数:

    @@ -6684,7 +6816,7 @@ http://localhost:3000/api/jasder/jasder_test/change_role.json
    参数取值范围:"Manager", "Developer", "Reporter";分别为项目管理人员(拥有所有操作权限)、项目开发人员(只拥有读写权限)、项目报告人员(只拥有读权限)
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -6726,9 +6858,9 @@ http://localhost:3000/api/jasder/jasder_test/change_role.json -d"limit=5"\ http://localhost:3000/api/jasder/jasder_test/collaborators.json
    await octokit.request('GET /api/jasder/jasder_test/collaborators.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/collaborators.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -6767,7 +6899,7 @@ http://localhost:3000/api/jasder/jasder_test/collaborators.json
    参数每页多少条数据,默认15条
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -6855,9 +6987,9 @@ http://localhost:3000/api/jasder/jasder_test/collaborators.json -d"ref=develop"\ http://localhost:3000/api/yystopf/ceshi/files.json
    await octokit.request('GET /api/yystopf/ceshi/files.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/files

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -6896,7 +7028,7 @@ http://localhost:3000/api/yystopf/ceshi/files.json
    参数分支名,默认为仓库默认分支
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -6978,9 +7110,9 @@ http://localhost:3000/api/yystopf/ceshi/files.json -d"ref=develop"\ http://localhost:3000//api/jasder/jasder_test/entries.json
    await octokit.request('GET /api/jasder/jasder_test/entries.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/entries.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -7012,7 +7144,7 @@ http://localhost:3000//api/jasder/jasder_test/entries.json
    参数分支名称、tag名称或是提交记录id,默认为master分支
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -7126,9 +7258,9 @@ http://localhost:3000//api/jasder/jasder_test/entries.json -d"filepath=file"\ http://localhost:3000//api/jasder/jasder_test/sub_entries.json
    await octokit.request('GET /api/jasder/jasder_test/sub_entries.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/sub_entries.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -7167,7 +7299,7 @@ http://localhost:3000//api/jasder/jasder_test/sub_entries.json
    参数分支名称、tag名称或是提交记录id,默认为master分支
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -7264,9 +7396,9 @@ http://localhost:3000//api/jasder/jasder_test/sub_entries.json -d"filepath=lib"\ http://localhost:3000/api/yystopf/csfjkkj/readme.json
    await octokit.request('GET /api/yystopf/csfjkkj/readme.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/readme.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -7305,7 +7437,7 @@ http://localhost:3000/api/yystopf/csfjkkj/readme.json
    参数子目录名称,默认为空
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -7377,9 +7509,9 @@ http://localhost:3000/api/yystopf/csfjkkj/readme.json -d"filepath=lib"\ http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    await octokit.request('GET /api/yystopf/csfjkkj/contributors.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/contributors.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -7418,7 +7550,7 @@ http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    参数子目录名称,默认为空
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -7493,9 +7625,9 @@ http://localhost:3000/api/yystopf/csfjkkj/contributors.json
    curl -X GET \
     http://localhost:3000/api/yystopf/ceshi/webhooks.json
     
    await octokit.request('GET /api/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/webhooks.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -7520,7 +7652,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks.json
    参数项目标识identifier
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -7622,9 +7754,9 @@ http://localhost:3000/api/yystopf/ceshi/webhooks.json
    curl -X GET \
     http://localhost:3000/api/yystopf/ceshi/webhooks/3/edit.json
     
    await octokit.request('GET /api/yystopf/ceshi/webhooks/3/edit.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/webhooks/:id/edit.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -7656,7 +7788,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/edit.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -7857,266 +7989,8 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/edit.json
    curl -X POST \
     http://localhost:3000/api/yystopf/ceshi/webhooks.json
     
    await octokit.request('POST /api/yystopf/ceshi/webhooks.json')
    -

    HTTP 请求

    -

    POST /api/:owner/:repo/webhooks.json

    -

    请求参数:

    -
    参数
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    webhook.urlstring目标url
    webhook.typestring类型
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    - -

    触发事件字段说明

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数含义
    create创建分支或标签
    delete分支或标签删除
    fork仓库被fork
    pushgit仓库推送
    issue易修已打开、已关闭、已重新打开或编辑
    issue_assign易修被指派
    issue_label易修标签被更新或删除
    issue_milestone易修被收入里程碑
    issue_comment易修评论
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_label合并请求被贴上标签
    pull_request_milestone合并请求被记录于里程碑中
    pull_request_comment合并请求被评论
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    pull_request_review_comment合并请求被提出审查意见
    pull_request_sync合并请求被同步
    repository创建或删除仓库
    release版本发布
    - -
    -

    请求的JSON示例:

    -
    -
    {
    -    "active": true, 
    -    "content_type": "json",
    -    "http_method": "GET",
    -    "secret": "123456",
    -    "url": "http://localhost:10000",
    -    "branch_filter": "*",
    -    "events": ["push"]
    -}
    -

    返回字段说明:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -    "id": 18,
    -    "type": "gitea",
    -    "content_type": "json",
    -    "url": "http://localhost:10000",
    -    "events": [
    -        "push"
    -    ],
    -    "active": true,
    -    "create_time": "2021-07-26 18:53:43"
    -}
    -
    - -

    更新仓库webhook

    -

    更新仓库webhook

    - -
    -

    示例:

    -
    -
    curl -X PATCH \
    -http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    -
    await octokit.request('PATCH /api/yystopf/ceshi/webhooks/7.json')
     

    HTTP 请求

    -

    PATCH /api/:owner/:repo/webhooks/:id.json

    +

    POST /api/:owner/:repo/webhooks.json

    请求参数:

    @@ -8142,13 +8016,6 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json - - - - - - - @@ -8309,28 +8176,79 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json "events": ["push"] }

    返回字段说明:

    +
    项目标识identifier
    idstringwebhook id
    webhook.url
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    idintid
    urlstring地址
    content_typestringPOST Content Type
    is_activebool是否激活
    typestring类型
    eventsarray触发事件
    create_timestring创建时间
    +

    返回的JSON示例:

    {
    -    "status": 0,
    -    "message": "success"
    +    "id": 18,
    +    "type": "gitea",
    +    "content_type": "json",
    +    "url": "http://localhost:10000",
    +    "events": [
    +        "push"
    +    ],
    +    "active": true,
    +    "create_time": "2021-07-26 18:53:43"
     }
     
    -

    删除仓库webhook

    -

    删除仓库webhook

    +

    更新仓库webhook

    +

    更新仓库webhook

    示例:

    -
    curl -X DELETE \
    +
    curl -X PATCH \
     http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    -
    await octokit.request('DELETE /api/yystopf/ceshi/webhooks/7.json')
    +
    await octokit.request('PATCH /api/yystopf/ceshi/webhooks/7.json')
     

    HTTP 请求

    -

    DELETE /api/:owner/:repo/webhooks/:id.json

    +

    PATCH /api/:owner/:repo/webhooks/:id.json

    请求参数:

    @@ -8362,8 +8280,222 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    string webhook id
    webhook.urlstring目标url
    webhook.typestring类型
    webhook.http_methodstringhttp方法, POST和GET
    webhook.content_typestringPOST Content Type
    webhook.secretstring密钥文本
    webhook.activebool是否激活
    webhook.branch_filterstring分支过滤
    webhook.eventsarray触发事件
    -

    返回字段说明:

    + +

    触发事件字段说明

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数含义
    create创建分支或标签
    delete分支或标签删除
    fork仓库被fork
    pushgit仓库推送
    issue易修已打开、已关闭、已重新打开或编辑
    issue_assign易修被指派
    issue_label易修标签被更新或删除
    issue_milestone易修被收入里程碑
    issue_comment易修评论
    pull_request合并请求
    pull_request_assign合并请求被指派
    pull_request_label合并请求被贴上标签
    pull_request_milestone合并请求被记录于里程碑中
    pull_request_comment合并请求被评论
    pull_request_review_approved合并请求被批准
    pull_request_review_rejected合并请求被拒绝
    pull_request_review_comment合并请求被提出审查意见
    pull_request_sync合并请求被同步
    repository创建或删除仓库
    release版本发布
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "active": true, 
    +    "content_type": "json",
    +    "http_method": "GET",
    +    "secret": "123456",
    +    "url": "http://localhost:10000",
    +    "branch_filter": "*",
    +    "events": ["push"]
    +}
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +
    + +

    删除仓库webhook

    +

    删除仓库webhook

    + +
    +

    示例:

    +
    +
    curl -X DELETE \
    +http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    +
    await octokit.request('DELETE /api/yystopf/ceshi/webhooks/7.json')
    +

    HTTP 请求

    +

    DELETE /api/:owner/:repo/webhooks/:id.json

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    ownerstring用户登录名
    repostring项目标识identifier
    idstringwebhook id
    +

    返回字段说明:

    返回的JSON示例:

    @@ -8384,9 +8516,9 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
    curl -X GET \
     http://localhost:3000/api/yystopf/ceshi/webhooks/3/tasks.json
     
    await octokit.request('GET /api/yystopf/ceshi/webhooks/3/tasks.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/:owner/:repo/webhooks/:id/tasks.json

    -

    请求参数:

    +

    请求参数:

    @@ -8418,7 +8550,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/tasks.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -8655,9 +8787,9 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/tasks.json
    curl -X POST \
     http://localhost:3000/api/yystopf/ceshi/webhooks/3/test.json
     
    await octokit.request('POST /api/yystopf/ceshi/webhooks/3/test.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/:owner/:repo/webhooks/:id/test.json

    -

    请求参数:

    +

    请求参数:

    参数
    @@ -8689,7 +8821,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/test.json
    参数webhook ID
    -

    返回字段说明:

    +

    返回字段说明:

    返回的JSON示例:

    From 33473eecc27b34a3df0a70b0eef1712b4c00f7f8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Sep 2021 18:06:29 +0800 Subject: [PATCH 08/34] fix: tag addition message --- app/controllers/projects_controller.rb | 2 +- .../slate/source/includes/_repositories.md | 41 ++++++++++-- app/views/repositories/tags.json.jbuilder | 13 +++- public/docs/api.html | 65 +++++++++++++++++-- 4 files changed, 107 insertions(+), 14 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index b19d2b633..bea2b429c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -4,7 +4,7 @@ class ProjectsController < ApplicationController include ProjectsHelper include Acceleratorable - before_action :require_login, except: %i[index branches group_type_list simple show fork_users praise_users watch_users recommend about menu_list] + before_action :require_login, except: %i[index branches branches_slice group_type_list simple show fork_users praise_users watch_users recommend about menu_list] before_action :require_profile_completed, only: [:create, :migrate] before_action :load_repository, except: %i[index group_type_list migrate create recommend] before_action :authorizate_user_can_edit_project!, only: %i[update] diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index 81dbe1441..1ebb45361 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -295,6 +295,8 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') --------- | ------- | ------- | -------- | ---------- |owner |是| |string |用户登录名 | |repo |是| |string |项目标识identifier | +|page |否| 1 | integer | 页码 | +|limit |否| 20| integer | 每页个数 | ### 返回字段说明: @@ -304,11 +306,14 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') |name |string|标签名称| |zipball_url |string|标签zip包下载地址| |tarball_url |string|标签tar包下载地址| +|tagger |object|打标签的人| +|message |string|标签信息| |commit |object|标签最后一个commit| |commit.sha |string|commit的id| |commit.message |string|commit的提交信息| |commit.time_ago|string|commit的提交时间| |commit.commiter|object|commit的提交者| +|commit.author|object|commit的作者| > 返回的JSON示例: @@ -320,15 +325,28 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') "id": "c7d0873ee41796d1a0e193063095ccf539a9bf31", "zipball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v2.0.0.zip", "tarball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v2.0.0.tar.gz", + "tagger": { + "id": 4, + "login": "testforge1", + "name": "testforge1", + "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png" + }, + "message": "jdfkls", "commit": { "sha": "08fe383f1e5ebe2e2a384a8ea3ee890a758c7cd7", "message": "add\n", - "time_ago": "4小时前", + "time_ago": "1天前", "committer": { "id": 4, "login": "testforge1", "name": "testforge1", "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png" + }, + "author": { + "id": 4, + "login": "testforge1", + "name": "testforge1", + "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png" } } }, @@ -337,15 +355,28 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') "id": "12168ad39c3ef201a445a2db181a3e43d50e40dd", "zipball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v1.0.0.zip", "tarball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v1.0.0.tar.gz", + "tagger": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "message": "dfks", "commit": { "sha": "5291b5e45a377c1f7710cc6647259887ed7aaccf", "message": "ADD file via upload\n", - "time_ago": "9天前", + "time_ago": "21天前", "committer": { - "id": 2, + "id": null, "login": "yystopf", - "name": "heh", - "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + "name": "yystopf", + "image_url": "system/lets/letter_avatars/2/Y/241_125_89/120.png" + }, + "author": { + "id": null, + "login": "yystopf", + "name": "yystopf", + "image_url": "system/lets/letter_avatars/2/Y/241_125_89/120.png" } } } diff --git a/app/views/repositories/tags.json.jbuilder b/app/views/repositories/tags.json.jbuilder index 011fad46a..8ae5f94cd 100644 --- a/app/views/repositories/tags.json.jbuilder +++ b/app/views/repositories/tags.json.jbuilder @@ -4,12 +4,19 @@ json.array! @tags do |tag| json.id tag['id'] json.zipball_url render_zip_url(@owner, @repository, tag['name']) json.tarball_url render_tar_url(@owner, @repository, tag['name']) + json.tagger do + json.partial! 'commit_author', user: render_commit_author(tag['tagger']), name: tag['tagger']['name'] + end + json.message tag['message'] json.commit do json.sha tag['commit']['sha'] - json.message tag['commit_message'] - json.time_ago time_from_now(tag['commit_time'].to_time) + json.message tag['commit']['message'] + json.time_ago time_from_now(tag['commit']['commiter']['date'].to_time) json.committer do - json.partial! 'commit_author', user: render_commit_author(tag['commiter']), name: tag['commiter']['name'] + json.partial! 'commit_author', user: render_commit_author(tag['commit']['commiter']), name: tag['commit']['commiter']['name'] + end + json.author do + json.partial! 'commit_author', user: render_commit_author(tag['commit']['author']), name: tag['commit']['author']['name'] end end end diff --git a/public/docs/api.html b/public/docs/api.html index 763134f4e..6bd5c592e 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -6222,6 +6222,20 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat string 项目标识identifier + +page +否 +1 +integer +页码 + + +limit +否 +20 +integer +每页个数 +

    返回字段说明:

    @@ -6252,6 +6266,16 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat + + + + + + + + + + @@ -6276,6 +6300,11 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat + + + + +
    标签tar包下载地址
    taggerobject打标签的人
    messagestring标签信息
    commit object 标签最后一个commitobject commit的提交者
    commit.authorobjectcommit的作者
    @@ -6287,15 +6316,28 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat "id": "c7d0873ee41796d1a0e193063095ccf539a9bf31", "zipball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v2.0.0.zip", "tarball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v2.0.0.tar.gz", + "tagger": { + "id": 4, + "login": "testforge1", + "name": "testforge1", + "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png" + }, + "message": "jdfkls", "commit": { "sha": "08fe383f1e5ebe2e2a384a8ea3ee890a758c7cd7", "message": "add\n", - "time_ago": "4小时前", + "time_ago": "1天前", "committer": { "id": 4, "login": "testforge1", "name": "testforge1", "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png" + }, + "author": { + "id": 4, + "login": "testforge1", + "name": "testforge1", + "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png" } } }, @@ -6304,15 +6346,28 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat "id": "12168ad39c3ef201a445a2db181a3e43d50e40dd", "zipball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v1.0.0.zip", "tarball_url": "http://localhost:3000/api/yystopf/csfjkkj/archive/v1.0.0.tar.gz", + "tagger": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" + }, + "message": "dfks", "commit": { "sha": "5291b5e45a377c1f7710cc6647259887ed7aaccf", "message": "ADD file via upload\n", - "time_ago": "9天前", + "time_ago": "21天前", "committer": { - "id": 2, + "id": null, "login": "yystopf", - "name": "heh", - "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + "name": "yystopf", + "image_url": "system/lets/letter_avatars/2/Y/241_125_89/120.png" + }, + "author": { + "id": null, + "login": "yystopf", + "name": "yystopf", + "image_url": "system/lets/letter_avatars/2/Y/241_125_89/120.png" } } } From ab6b597d7b1209efc8681e915b9422cb2ef1787a Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 24 Sep 2021 18:28:01 +0800 Subject: [PATCH 09/34] fix --- app/docs/slate/source/includes/_repositories.md | 3 +++ app/views/repositories/tags.json.jbuilder | 1 + public/docs/api.html | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index 1ebb45361..9669d456a 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -307,6 +307,7 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') |zipball_url |string|标签zip包下载地址| |tarball_url |string|标签tar包下载地址| |tagger |object|打标签的人| +|time_ago |string|打标签的时间| |message |string|标签信息| |commit |object|标签最后一个commit| |commit.sha |string|commit的id| @@ -331,6 +332,7 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') "name": "testforge1", "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png" }, + "time_ago": "1天前", "message": "jdfkls", "commit": { "sha": "08fe383f1e5ebe2e2a384a8ea3ee890a758c7cd7", @@ -361,6 +363,7 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') "name": "viletyy", "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" }, + "time_ago": "10天前", "message": "dfks", "commit": { "sha": "5291b5e45a377c1f7710cc6647259887ed7aaccf", diff --git a/app/views/repositories/tags.json.jbuilder b/app/views/repositories/tags.json.jbuilder index 8ae5f94cd..2feab91ed 100644 --- a/app/views/repositories/tags.json.jbuilder +++ b/app/views/repositories/tags.json.jbuilder @@ -7,6 +7,7 @@ json.array! @tags do |tag| json.tagger do json.partial! 'commit_author', user: render_commit_author(tag['tagger']), name: tag['tagger']['name'] end + json.time_ago time_from_now(tag['tagger']['date'].to_time) json.message tag['message'] json.commit do json.sha tag['commit']['sha'] diff --git a/public/docs/api.html b/public/docs/api.html index 6bd5c592e..33f9e72b7 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -6271,6 +6271,11 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat 打标签的人 +time_ago +string +打标签的时间 + + message string 标签信息 @@ -6322,6 +6327,7 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat "name": "testforge1", "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png" }, + "time_ago": "1天前", "message": "jdfkls", "commit": { "sha": "08fe383f1e5ebe2e2a384a8ea3ee890a758c7cd7", @@ -6352,6 +6358,7 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat "name": "viletyy", "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" }, + "time_ago": "10天前", "message": "dfks", "commit": { "sha": "5291b5e45a377c1f7710cc6647259887ed7aaccf", From 133713ae7f575214bc883ac4b162412e73ebf3e7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sun, 26 Sep 2021 11:36:34 +0800 Subject: [PATCH 10/34] add: tag created at unix --- app/docs/slate/source/includes/_repositories.md | 6 ++++++ app/views/repositories/tags.json.jbuilder | 2 ++ public/docs/api.html | 14 ++++++++++++++ 3 files changed, 22 insertions(+) diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index 9669d456a..642a4cc34 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -308,11 +308,13 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') |tarball_url |string|标签tar包下载地址| |tagger |object|打标签的人| |time_ago |string|打标签的时间| +|created_at_unix|string|打标签的时间戳| |message |string|标签信息| |commit |object|标签最后一个commit| |commit.sha |string|commit的id| |commit.message |string|commit的提交信息| |commit.time_ago|string|commit的提交时间| +|commit.created_at_unix|string|commit的提交时间戳| |commit.commiter|object|commit的提交者| |commit.author|object|commit的作者| @@ -333,11 +335,13 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png" }, "time_ago": "1天前", + "created_at_unix": 1632376903, "message": "jdfkls", "commit": { "sha": "08fe383f1e5ebe2e2a384a8ea3ee890a758c7cd7", "message": "add\n", "time_ago": "1天前", + "created_at_unix": 1632376186, "committer": { "id": 4, "login": "testforge1", @@ -364,11 +368,13 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" }, "time_ago": "10天前", + "created_at_unix": 1631588042, "message": "dfks", "commit": { "sha": "5291b5e45a377c1f7710cc6647259887ed7aaccf", "message": "ADD file via upload\n", "time_ago": "21天前", + "created_at_unix": 1630648417, "committer": { "id": null, "login": "yystopf", diff --git a/app/views/repositories/tags.json.jbuilder b/app/views/repositories/tags.json.jbuilder index 2feab91ed..d1ee3671e 100644 --- a/app/views/repositories/tags.json.jbuilder +++ b/app/views/repositories/tags.json.jbuilder @@ -8,11 +8,13 @@ json.array! @tags do |tag| json.partial! 'commit_author', user: render_commit_author(tag['tagger']), name: tag['tagger']['name'] end json.time_ago time_from_now(tag['tagger']['date'].to_time) + json.created_at_unix tag['tagger']['date'].to_time.to_i json.message tag['message'] json.commit do json.sha tag['commit']['sha'] json.message tag['commit']['message'] json.time_ago time_from_now(tag['commit']['commiter']['date'].to_time) + json.created_at_unix tag['commit']['commiter']['date'].to_time.to_i json.committer do json.partial! 'commit_author', user: render_commit_author(tag['commit']['commiter']), name: tag['commit']['commiter']['name'] end diff --git a/public/docs/api.html b/public/docs/api.html index 33f9e72b7..fc9427033 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -6276,6 +6276,11 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat 打标签的时间 +created_at_unix +string +打标签的时间戳 + + message string 标签信息 @@ -6301,6 +6306,11 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat commit的提交时间 +commit.created_at_unix +string +commit的提交时间戳 + + commit.commiter object commit的提交者 @@ -6328,11 +6338,13 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat "image_url": "system/lets/letter_avatars/2/T/19_237_174/120.png" }, "time_ago": "1天前", + "created_at_unix": 1632376903, "message": "jdfkls", "commit": { "sha": "08fe383f1e5ebe2e2a384a8ea3ee890a758c7cd7", "message": "add\n", "time_ago": "1天前", + "created_at_unix": 1632376186, "committer": { "id": 4, "login": "testforge1", @@ -6359,11 +6371,13 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat "image_url": "system/lets/letter_avatars/2/V/39_141_222/120.png" }, "time_ago": "10天前", + "created_at_unix": 1631588042, "message": "dfks", "commit": { "sha": "5291b5e45a377c1f7710cc6647259887ed7aaccf", "message": "ADD file via upload\n", "time_ago": "21天前", + "created_at_unix": 1630648417, "committer": { "id": null, "login": "yystopf", From 46a083239b20a488b6389c2615a45e78fdb4d963 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sun, 26 Sep 2021 14:32:24 +0800 Subject: [PATCH 11/34] add: release show api --- .../version_releases_controller.rb | 6 ++- app/services/gitea/versions/get_service.rb | 37 +++++++++++++++++++ .../_version_release.json.jbuilder | 14 +++++++ .../version_releases/index.json.jbuilder | 30 +-------------- app/views/version_releases/show.json.jbuilder | 2 + config/routes.rb | 2 +- 6 files changed, 61 insertions(+), 30 deletions(-) create mode 100644 app/services/gitea/versions/get_service.rb create mode 100644 app/views/version_releases/_version_release.json.jbuilder create mode 100644 app/views/version_releases/show.json.jbuilder diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 618eb0735..045785334 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -2,7 +2,7 @@ class VersionReleasesController < ApplicationController before_action :load_repository before_action :set_user before_action :require_login, except: [:index] - before_action :find_version , only: [:edit, :update, :destroy] + before_action :find_version , only: [:show, :edit, :update, :destroy] def index version_releases = Gitea::Versions::ListService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier)).call @@ -22,6 +22,10 @@ class VersionReleasesController < ApplicationController end end + def show + @release = Gitea::Versions::GetService.call(current_user.gitea_token, @user&.login, @repository&.identifier, @version&.version_gid) + end + def create if params[:name].nil? normal_status(-1, "名称不能为空") diff --git a/app/services/gitea/versions/get_service.rb b/app/services/gitea/versions/get_service.rb new file mode 100644 index 000000000..b3c6cf9cc --- /dev/null +++ b/app/services/gitea/versions/get_service.rb @@ -0,0 +1,37 @@ +# Get a list of all commits from a repository +class Gitea::Versions::GetService < Gitea::ClientService + attr_reader :token, :user_name, :repo, :gid, :args + + # sha: SHA or branch to start listing commits from (usually 'master') + def initialize(token, user_name, repo, gid, args={}) + @token = token + @user_name = user_name + @repo = repo + @gid = gid + @args = args + end + + def call + response = get(url, params) + render_result(response) + end + + private + def params + args.merge(token: token) + end + + def url + "/repos/#{@user_name}/#{@repo}/releases/#{@gid}".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/version_releases/_version_release.json.jbuilder b/app/views/version_releases/_version_release.json.jbuilder new file mode 100644 index 000000000..23c275184 --- /dev/null +++ b/app/views/version_releases/_version_release.json.jbuilder @@ -0,0 +1,14 @@ +json.version_id version.try(:id) +json.id re["id"] +json.tag_name re["tag_name"] +json.target_commitish re["target_commitish"] +json.name re["name"] +json.body re["body"] +json.url re["url"] +json.tarball_url render_tar_url(@owner, @repository, re["tag_name"]) +json.zipball_url render_zip_url(@owner, @repository, re["tag_name"]) +json.draft re["draft"] ? "草稿" : (re["prerelease"] ? "预发行" : "稳定") +json.created_at format_time(version.created_at.to_s.to_time) +json.published_at format_time(version.created_at.to_s.to_time) +json.user_name user.present? ? user.try(:show_real_name) : "" +json.image_url user.present? ? url_to_avatar(user) : "" \ No newline at end of file diff --git a/app/views/version_releases/index.json.jbuilder b/app/views/version_releases/index.json.jbuilder index 88ae36f26..29cc4fd2c 100644 --- a/app/views/version_releases/index.json.jbuilder +++ b/app/views/version_releases/index.json.jbuilder @@ -7,36 +7,10 @@ json.releases do user = User.select(:id, :gitea_uid, :login, :lastname,:firstname, :nickname).find_by_gitea_uid(re["author"]["id"]) version = @forge_releases.find_by(version_gid: re["id"]) if @user_permission && re["draft"] - json.version_id version.try(:id) - json.id re["id"] - json.tag_name re["tag_name"] - json.target_commitish re["target_commitish"] - json.name re["name"] - json.body re["body"] - json.url re["url"] - json.tarball_url render_tar_url(@owner, @repository, re["tag_name"]) - json.zipball_url render_zip_url(@owner, @repository, re["tag_name"]) - json.draft re["draft"] ? "草稿" : (re["prerelease"] ? "预发行" : "稳定") - json.created_at format_time(version.created_at.to_s.to_time) - json.published_at format_time(version.created_at.to_s.to_time) - json.user_name user.present? ? user.try(:show_real_name) : "" - json.image_url user.present? ? url_to_avatar(user) : "" + json.partial! "version_release", locals: {version: version, user: user, re: re} else unless re["draft"] - json.version_id version.try(:id) - json.id re["id"] - json.tag_name re["tag_name"] - json.target_commitish re["target_commitish"] - json.name re["name"] - json.body re["body"] - json.url re["url"] - json.tarball_url render_tar_url(@owner, @repository, re["tag_name"]) - json.zipball_url render_zip_url(@owner, @repository, re["tag_name"]) - json.draft re["draft"] ? "草稿" : (re["prerelease"] ? "预发行" : "稳定") - json.created_at format_time(version.created_at.to_s.to_time) - json.published_at format_time(version.created_at.to_s.to_time) - json.user_name user.present? ? user.try(:show_real_name) : "" - json.image_url user.present? ? url_to_avatar(user) : "" + json.partial! "version_release", locals: {version: version, user: user, re: re} end end diff --git a/app/views/version_releases/show.json.jbuilder b/app/views/version_releases/show.json.jbuilder new file mode 100644 index 000000000..803ae477a --- /dev/null +++ b/app/views/version_releases/show.json.jbuilder @@ -0,0 +1,2 @@ +user = User.select(:id, :gitea_uid, :login, :lastname,:firstname, :nickname).find_by_gitea_uid(@release["author"]["id"]) +json.partial! "version_release", locals: {version: @version, user: user, re: @release} \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2a935b896..005bd926a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -528,7 +528,7 @@ Rails.application.routes.draw do resources :forks, only: [:create] resources :project_trends, :path => :activity, only: [:index, :create] resources :issue_tags, :path => :labels, only: [:create, :edit, :update, :destroy, :index] - resources :version_releases, :path => :releases, only: [:index,:new, :create, :edit, :update, :destroy] + resources :version_releases, :path => :releases, only: [:index,:new, :show, :create, :edit, :update, :destroy] scope module: :ci do scope do From 24e77300adee735ac7d9cf430703b238b30b2e55 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sun, 26 Sep 2021 14:42:29 +0800 Subject: [PATCH 12/34] fix: relase attachments --- app/views/version_releases/_version_release.json.jbuilder | 7 ++++++- app/views/version_releases/index.json.jbuilder | 6 ------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/app/views/version_releases/_version_release.json.jbuilder b/app/views/version_releases/_version_release.json.jbuilder index 23c275184..498e05eef 100644 --- a/app/views/version_releases/_version_release.json.jbuilder +++ b/app/views/version_releases/_version_release.json.jbuilder @@ -11,4 +11,9 @@ json.draft re["draft"] ? "草稿" : (re["prerelease"] ? "预发行" : "稳定") json.created_at format_time(version.created_at.to_s.to_time) json.published_at format_time(version.created_at.to_s.to_time) json.user_name user.present? ? user.try(:show_real_name) : "" -json.image_url user.present? ? url_to_avatar(user) : "" \ No newline at end of file +json.image_url user.present? ? url_to_avatar(user) : "" +json.attachments do + json.array! version.try(:attachments) do |attachment| + json.partial! "attachments/attachment_simple", locals: {attachment: attachment} + end +end \ No newline at end of file diff --git a/app/views/version_releases/index.json.jbuilder b/app/views/version_releases/index.json.jbuilder index 29cc4fd2c..cfafb200f 100644 --- a/app/views/version_releases/index.json.jbuilder +++ b/app/views/version_releases/index.json.jbuilder @@ -13,12 +13,6 @@ json.releases do json.partial! "version_release", locals: {version: version, user: user, re: re} end end - - json.attachments do - json.array! version.try(:attachments) do |attachment| - json.partial! "attachments/attachment_simple", locals: {attachment: attachment} - end - end end end From f013ddcb7277ea63d955f500cabb6abacb821bb3 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sun, 26 Sep 2021 14:44:26 +0800 Subject: [PATCH 13/34] fix --- app/controllers/version_releases_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 045785334..c3aed1461 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -1,7 +1,7 @@ class VersionReleasesController < ApplicationController before_action :load_repository before_action :set_user - before_action :require_login, except: [:index] + before_action :require_login, except: [:index, :show] before_action :find_version , only: [:show, :edit, :update, :destroy] def index From 1d0255440aeb4bb9208a90aa5226c286161de2b7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 27 Sep 2021 16:58:14 +0800 Subject: [PATCH 14/34] add: release list sha --- app/views/version_releases/_version_release.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/version_releases/_version_release.json.jbuilder b/app/views/version_releases/_version_release.json.jbuilder index 498e05eef..86165d5af 100644 --- a/app/views/version_releases/_version_release.json.jbuilder +++ b/app/views/version_releases/_version_release.json.jbuilder @@ -3,6 +3,7 @@ json.id re["id"] json.tag_name re["tag_name"] json.target_commitish re["target_commitish"] json.name re["name"] +json.sha re["sha"] json.body re["body"] json.url re["url"] json.tarball_url render_tar_url(@owner, @repository, re["tag_name"]) From cae59383b4df35c8b50daed77269aa81afeae6ec Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 29 Sep 2021 09:18:07 +0800 Subject: [PATCH 15/34] add: commit show committer --- .../repositories/_commit_author.json.jbuilder | 2 ++ app/views/repositories/commits.json.jbuilder | 34 +++++++++++-------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/app/views/repositories/_commit_author.json.jbuilder b/app/views/repositories/_commit_author.json.jbuilder index 1478cca0e..c63edf9b1 100644 --- a/app/views/repositories/_commit_author.json.jbuilder +++ b/app/views/repositories/_commit_author.json.jbuilder @@ -2,10 +2,12 @@ if user json.id user.id json.login user.login json.name user.real_name + json.type user&.type json.image_url url_to_avatar(user) else json.id nil json.login name json.name name + json.type nil json.image_url User::Avatar.get_letter_avatar_url(name) end diff --git a/app/views/repositories/commits.json.jbuilder b/app/views/repositories/commits.json.jbuilder index 9dd90446e..cf4a409f5 100644 --- a/app/views/repositories/commits.json.jbuilder +++ b/app/views/repositories/commits.json.jbuilder @@ -7,25 +7,31 @@ else json.array! @hash_commit[:body] do |commit| commiter = commit['committer'] - forge_user = - if commiter.present? - User.simple_select.find_by(gitea_uid: commiter['id']) - end + # forge_user = + # if commiter.present? + # User.simple_select.find_by(gitea_uid: commiter['id']) + # end 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']) - if forge_user - json.partial! 'author', user: forge_user - else - json.author do - json.id nil - json.login commit['commit']['author']['name'] - json.type nil - json.name commit['commit']['author']['name'] - json.image_url User::Avatar.get_letter_avatar_url(commit['commit']['author']['name']) - end + # if forge_user + # json.partial! 'author', user: forge_user + # else + # json.author do + # json.id nil + # json.login commit['commit']['author']['name'] + # json.type nil + # json.name commit['commit']['author']['name'] + # json.image_url User::Avatar.get_letter_avatar_url(commit['commit']['author']['name']) + # end + # end + json.author do + json.partial! 'commit_author', user: render_commit_author(commit['commit']['author']), name: commit['commit']['author']['name'] + end + json.committer do + json.partial! 'commit_author', user: render_commit_author(commit['commit']['committer']), name: commit['commit']['committer']['name'] end end end From c39990fff3c7ce47bce5262bd0953ed9bf8c9a16 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 29 Sep 2021 09:20:28 +0800 Subject: [PATCH 16/34] fix: doc --- app/docs/slate/source/includes/_repositories.md | 2 +- public/docs/api.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index 642a4cc34..3604689c8 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -315,7 +315,7 @@ await octokit.request('GET /api/yystopf/csfjkkj/tags.json') |commit.message |string|commit的提交信息| |commit.time_ago|string|commit的提交时间| |commit.created_at_unix|string|commit的提交时间戳| -|commit.commiter|object|commit的提交者| +|commit.committer|object|commit的提交者| |commit.author|object|commit的作者| diff --git a/public/docs/api.html b/public/docs/api.html index fc9427033..ef03d978f 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -6311,7 +6311,7 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat commit的提交时间戳 -commit.commiter +commit.committer object commit的提交者 From c9bd81af4e15d559b6989f87fe8a74251e144353 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 29 Sep 2021 10:01:46 +0800 Subject: [PATCH 17/34] fix: lastcommit author and committer --- app/views/repositories/_commit.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/repositories/_commit.json.jbuilder b/app/views/repositories/_commit.json.jbuilder index 3f3dd5544..95cb03412 100644 --- a/app/views/repositories/_commit.json.jbuilder +++ b/app/views/repositories/_commit.json.jbuilder @@ -26,9 +26,9 @@ if @project.forge? end json.author do - json.partial! 'commit_author', user: render_commit_author(commit['author']), name: commit['commit']['author']['name'] + json.partial! 'commit_author', user: render_commit_author(commit['commit']['author']), name: commit['commit']['author']['name'] end json.committer do - json.partial! 'commit_author', user: render_commit_author(commit['committer']), name: commit['commit']['committer']['name'] + json.partial! 'commit_author', user: render_commit_author(commit['commit']['committer']), name: commit['commit']['committer']['name'] end end From d1f5c32f688b79c26e2e38a3742be141bb2b5b58 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 29 Sep 2021 10:37:21 +0800 Subject: [PATCH 18/34] fix --- app/views/repositories/commit.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/repositories/commit.json.jbuilder b/app/views/repositories/commit.json.jbuilder index 77f6e3f1b..b15abef77 100644 --- a/app/views/repositories/commit.json.jbuilder +++ b/app/views/repositories/commit.json.jbuilder @@ -9,3 +9,4 @@ json.parents @commit['parents'] do |parent| json.sha parent['sha'] # json.url EduSetting.get('host_name') + commit_repository_path(@repo, parent['sha']) end +json.branch @commit['branch'] From 520b0ef1bee2d33e80f56e5c12f9e23556f45ba9 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 29 Sep 2021 11:43:04 +0800 Subject: [PATCH 19/34] fix: release creator token --- app/controllers/version_releases_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index c3aed1461..b397a2bc9 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -41,7 +41,7 @@ class VersionReleasesController < ApplicationController version_params = releases_params version_release = VersionRelease.new(version_params.merge(user_id: current_user.id, repository_id: @repository.id)) if version_release.save! - git_version_release = Gitea::Versions::CreateService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier), version_params).call + git_version_release = Gitea::Versions::CreateService.new(current_user.gitea_token, @user.try(:login), @repository.try(:identifier), version_params).call if git_version_release update_params = { tarball_url: git_version_release["tarball_url"], @@ -85,7 +85,7 @@ class VersionReleasesController < ApplicationController if @version.update_attributes!(version_params) create_attachments(params[:attachment_ids], @version) if params[:attachment_ids].present? - git_version_release = Gitea::Versions::UpdateService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier), version_params, @version.try(:version_gid)).call + git_version_release = Gitea::Versions::UpdateService.new(current_user.gitea_token, @user.try(:login), @repository.try(:identifier), version_params, @version.try(:version_gid)).call unless git_version_release raise Error, "更新失败" end @@ -106,7 +106,7 @@ class VersionReleasesController < ApplicationController ActiveRecord::Base.transaction do begin if @version.destroy - git_version_release = Gitea::Versions::DeleteService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier), @version.try(:version_gid)).call + git_version_release = Gitea::Versions::DeleteService.new(current_user.gitea_token, @user.try(:login), @repository.try(:identifier), @version.try(:version_gid)).call if git_version_release.status == 204 normal_status(0, "删除成功") From 69b8e0710c310a947c58046b213ddd520aceaab7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 29 Sep 2021 17:09:30 +0800 Subject: [PATCH 20/34] add: organization info --- .../organizations/_simple.json.jbuilder | 14 +++++++++----- app/views/organizations/teams/show.json.jbuilder | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/app/views/organizations/organizations/_simple.json.jbuilder b/app/views/organizations/organizations/_simple.json.jbuilder index 12792b125..7fed762a2 100644 --- a/app/views/organizations/organizations/_simple.json.jbuilder +++ b/app/views/organizations/organizations/_simple.json.jbuilder @@ -1,5 +1,9 @@ -json.id organization.id -json.name organization.login -json.nickname organization.nickname.blank? ? organization.name : organization.nickname -json.description organization.description -json.avatar_url url_to_avatar(organization) +if organization.present? + json.id organization.id + json.name organization.login + json.nickname organization.nickname.blank? ? organization.name : organization.nickname + json.description organization.description + json.avatar_url url_to_avatar(organization) +else + nil +end \ No newline at end of file diff --git a/app/views/organizations/teams/show.json.jbuilder b/app/views/organizations/teams/show.json.jbuilder index d0290897a..c86f9b546 100644 --- a/app/views/organizations/teams/show.json.jbuilder +++ b/app/views/organizations/teams/show.json.jbuilder @@ -1,3 +1,6 @@ json.partial! "detail", team: @team, organization: @organization json.is_admin @is_admin -json.is_member @is_member \ No newline at end of file +json.is_member @is_member +json.organization do + json.partial! "organizations/organizations/simple", organization: @organization +end \ No newline at end of file From c1db02171acf608e466862200aedd9353c5d61e0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 29 Sep 2021 17:16:21 +0800 Subject: [PATCH 21/34] add: release admin permission field --- app/controllers/version_releases_controller.rb | 1 + app/views/version_releases/index.json.jbuilder | 1 + 2 files changed, 2 insertions(+) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index b397a2bc9..ade2d07ec 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -8,6 +8,7 @@ class VersionReleasesController < ApplicationController version_releases = Gitea::Versions::ListService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier)).call @version_releases = version_releases @user_permission = current_user.present? && (@repository.project.all_developers.include?(current_user) || current_user.admin?) + @user_admin_permission = current_user.present? && (@repository.project.all_managers.include?(current_user) || current_user.admin?) @forge_releases = @repository.version_releases.select(:id,:version_gid, :created_at).includes(:attachments) end diff --git a/app/views/version_releases/index.json.jbuilder b/app/views/version_releases/index.json.jbuilder index cfafb200f..8efb88bc1 100644 --- a/app/views/version_releases/index.json.jbuilder +++ b/app/views/version_releases/index.json.jbuilder @@ -1,5 +1,6 @@ json.partial! "commons/success" json.user_permission @user_permission +json.user_admin_permission @user_admin_permission # json.releases @version_releases json.releases do json.array! @version_releases.to_a.each do |re| From b07781a514ee76fd8e7d24b3f3f96ad99607244f Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 29 Sep 2021 18:50:51 +0800 Subject: [PATCH 22/34] fix: some issues --- app/controllers/repositories_controller.rb | 2 +- app/helpers/repositories_helper.rb | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index a7e909eb8..db1db604a 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -229,7 +229,7 @@ class RepositoriesController < ApplicationController file_path = [domain, api_url, url].join file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&") if @repository.hidden? - redirect_to file_path + redirect_to URI.escape(file_path) end private diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index ee60b64a4..d34e3a8d9 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -10,12 +10,12 @@ module RepositoriesHelper end def download_type(str) - default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb png jpg gif tif psd svg RData rdata doc docx mpp vsdx dot otf eot ttf woff woff2) + default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb RData rdata doc docx mpp vsdx dot otf eot ttf woff woff2) default_type.include?(str&.downcase) end def image_type?(str) - default_type = %w(png jpg gif tif psd svg gif bmp webp jpeg) + default_type = %w(png jpg gif tif psd svg bmp webp jpeg) default_type.include?(str&.downcase) end @@ -83,12 +83,15 @@ module RepositoriesHelper def decode64_content(entry, owner, repo, ref, path=nil) if is_readme?(entry['type'], entry['name']) - content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, entry['path'], ref: ref)['content'] + content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] readme_render_decode64_content(content, path) else file_type = File.extname(entry['name'].to_s)[1..-1] + if image_type?(file_type) + return entry['content'].nil? ? Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content'] : entry['content'] + end if download_type(file_type) - return entry['content'].nil? ? Gitea::Repository::Entries::GetService.call(owner, repo.identifier, entry['path'], ref: ref)['content'] : entry['content'] + return entry['content'] end render_decode64_content(entry['content']) end From aabfaad458615c65e65c25ec594eb4cf71864763 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 30 Sep 2021 11:09:13 +0800 Subject: [PATCH 23/34] add: release use database data --- .../version_releases_controller.rb | 7 +++---- app/models/version_release.rb | 6 ++++++ .../_version_release.json.jbuilder | 20 +++++++++---------- .../version_releases/index.json.jbuilder | 18 +++++++---------- app/views/version_releases/show.json.jbuilder | 4 ++-- ...10930025555_add_sha_to_version_releases.rb | 5 +++++ 6 files changed, 33 insertions(+), 27 deletions(-) create mode 100644 db/migrate/20210930025555_add_sha_to_version_releases.rb diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index ade2d07ec..c66a4bf0d 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -5,11 +5,9 @@ class VersionReleasesController < ApplicationController before_action :find_version , only: [:show, :edit, :update, :destroy] def index - version_releases = Gitea::Versions::ListService.new(@user.gitea_token, @user.try(:login), @repository.try(:identifier)).call - @version_releases = version_releases + @version_releases = kaminari_paginate(@repository.version_releases.order(created_at: :desc)) @user_permission = current_user.present? && (@repository.project.all_developers.include?(current_user) || current_user.admin?) @user_admin_permission = current_user.present? && (@repository.project.all_managers.include?(current_user) || current_user.admin?) - @forge_releases = @repository.version_releases.select(:id,:version_gid, :created_at).includes(:attachments) end def new @@ -24,7 +22,7 @@ class VersionReleasesController < ApplicationController end def show - @release = Gitea::Versions::GetService.call(current_user.gitea_token, @user&.login, @repository&.identifier, @version&.version_gid) + # @release = Gitea::Versions::GetService.call(current_user.gitea_token, @user&.login, @repository&.identifier, @version&.version_gid) end def create @@ -49,6 +47,7 @@ class VersionReleasesController < ApplicationController zipball_url: git_version_release["zipball_url"], url: git_version_release["url"], version_gid: git_version_release["id"], + sha: git_version_release["sha"] } version_release.update_attributes!(update_params) version_release.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create") diff --git a/app/models/version_release.rb b/app/models/version_release.rb index 16b823a78..3c97420ea 100644 --- a/app/models/version_release.rb +++ b/app/models/version_release.rb @@ -17,6 +17,7 @@ # created_at :datetime not null # updated_at :datetime not null # repository_id :integer +# sha :string(255) # # Indexes # @@ -29,4 +30,9 @@ class VersionRelease < ApplicationRecord has_many :project_trends, as: :trend, dependent: :destroy scope :releases_size, ->{where(draft: false, prerelease: false).size} has_many :attachments, as: :container, dependent: :destroy + + def update_sha + git_release = Gitea::Versions::GetService.call(user.gitea_token, repository&.owner&.login, repository&.identifier, version_gid) + self.update(sha: git_release["sha"]) + end end diff --git a/app/views/version_releases/_version_release.json.jbuilder b/app/views/version_releases/_version_release.json.jbuilder index 86165d5af..ddf59ee75 100644 --- a/app/views/version_releases/_version_release.json.jbuilder +++ b/app/views/version_releases/_version_release.json.jbuilder @@ -1,14 +1,14 @@ json.version_id version.try(:id) -json.id re["id"] -json.tag_name re["tag_name"] -json.target_commitish re["target_commitish"] -json.name re["name"] -json.sha re["sha"] -json.body re["body"] -json.url re["url"] -json.tarball_url render_tar_url(@owner, @repository, re["tag_name"]) -json.zipball_url render_zip_url(@owner, @repository, re["tag_name"]) -json.draft re["draft"] ? "草稿" : (re["prerelease"] ? "预发行" : "稳定") +json.id version&.version_gid +json.tag_name version&.tag_name +json.target_commitish version&.target_commitish +json.name version&.name +json.sha version&.sha +json.body version&.body +json.url version&.url +json.tarball_url render_tar_url(@owner, @repository, version&.tag_name) +json.zipball_url render_zip_url(@owner, @repository, version&.tag_name) +json.draft version&.draft ? "草稿" : (version&.prerelease ? "预发行" : "稳定") json.created_at format_time(version.created_at.to_s.to_time) json.published_at format_time(version.created_at.to_s.to_time) json.user_name user.present? ? user.try(:show_real_name) : "" diff --git a/app/views/version_releases/index.json.jbuilder b/app/views/version_releases/index.json.jbuilder index 8efb88bc1..300b1b60d 100644 --- a/app/views/version_releases/index.json.jbuilder +++ b/app/views/version_releases/index.json.jbuilder @@ -3,18 +3,14 @@ json.user_permission @user_permission json.user_admin_permission @user_admin_permission # json.releases @version_releases json.releases do - json.array! @version_releases.to_a.each do |re| - if re.present? - user = User.select(:id, :gitea_uid, :login, :lastname,:firstname, :nickname).find_by_gitea_uid(re["author"]["id"]) - version = @forge_releases.find_by(version_gid: re["id"]) - if @user_permission && re["draft"] - json.partial! "version_release", locals: {version: version, user: user, re: re} - else - unless re["draft"] - json.partial! "version_release", locals: {version: version, user: user, re: re} - end + json.array! @version_releases.each do |version| + version.update_sha if version.sha.nil? + if @user_permission && version&.draft + json.partial! "version_release", locals: {version: version, user: version&.user} + else + unless version&.draft + json.partial! "version_release", locals: {version: version, user: version&.user} end end - end end diff --git a/app/views/version_releases/show.json.jbuilder b/app/views/version_releases/show.json.jbuilder index 803ae477a..716f5d7b2 100644 --- a/app/views/version_releases/show.json.jbuilder +++ b/app/views/version_releases/show.json.jbuilder @@ -1,2 +1,2 @@ -user = User.select(:id, :gitea_uid, :login, :lastname,:firstname, :nickname).find_by_gitea_uid(@release["author"]["id"]) -json.partial! "version_release", locals: {version: @version, user: user, re: @release} \ No newline at end of file + +json.partial! "version_release", locals: {version: @version, user: @version&.user} \ No newline at end of file diff --git a/db/migrate/20210930025555_add_sha_to_version_releases.rb b/db/migrate/20210930025555_add_sha_to_version_releases.rb new file mode 100644 index 000000000..475d361f8 --- /dev/null +++ b/db/migrate/20210930025555_add_sha_to_version_releases.rb @@ -0,0 +1,5 @@ +class AddShaToVersionReleases < ActiveRecord::Migration[5.2] + def change + add_column :version_releases, :sha, :string + end +end From 59fe010fdbe49947eccd4e332fc6fcecfecf0c96 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 30 Sep 2021 11:15:11 +0800 Subject: [PATCH 24/34] add: page totalcount --- app/views/version_releases/index.json.jbuilder | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/version_releases/index.json.jbuilder b/app/views/version_releases/index.json.jbuilder index 300b1b60d..85d1be256 100644 --- a/app/views/version_releases/index.json.jbuilder +++ b/app/views/version_releases/index.json.jbuilder @@ -14,3 +14,4 @@ json.releases do end end end +json.total_count @version_releases.total_count \ No newline at end of file From f7ba082944951fd0cf7501bd58d8c4ab27db1b08 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 30 Sep 2021 14:59:37 +0800 Subject: [PATCH 25/34] fix: readme return decode data --- app/controllers/repositories_controller.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index db1db604a..d66a25a93 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -1,4 +1,5 @@ class RepositoriesController < ApplicationController + include RepositoriesHelper include ApplicationHelper include OperateProjectAbilityAble include Repository::LanguagesPercentagable @@ -198,7 +199,8 @@ class RepositoriesController < ApplicationController result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token) end @readme = result[:status] === :success ? result[:body] : nil - + @readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref]) + Rails.logger.info "======+#{@readme}" render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha") rescue render json: nil From 689f2658580e0a94e912b447ece7e7879b337326 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 30 Sep 2021 14:59:46 +0800 Subject: [PATCH 26/34] fix --- app/controllers/repositories_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index d66a25a93..9887a2918 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -200,7 +200,6 @@ class RepositoriesController < ApplicationController end @readme = result[:status] === :success ? result[:body] : nil @readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref]) - Rails.logger.info "======+#{@readme}" render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha") rescue render json: nil From 9685c9717761d12c8d59241c24bf548bdcc60424 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 30 Sep 2021 17:40:18 +0800 Subject: [PATCH 27/34] fix: add user login and release authorize --- app/controllers/version_releases_controller.rb | 5 +++++ app/views/version_releases/_version_release.json.jbuilder | 1 + 2 files changed, 6 insertions(+) diff --git a/app/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index c66a4bf0d..2d7546a1c 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -2,6 +2,7 @@ class VersionReleasesController < ApplicationController before_action :load_repository before_action :set_user before_action :require_login, except: [:index, :show] + before_action :check_release_authorize, except: [:index, :show] before_action :find_version , only: [:show, :edit, :update, :destroy] def index @@ -161,4 +162,8 @@ class VersionReleasesController < ApplicationController end end + def check_release_authorize + return render_forbidden("您没有权限进行此操作.") unless current_user.admin? || @project.manager?(current_user) + end + end diff --git a/app/views/version_releases/_version_release.json.jbuilder b/app/views/version_releases/_version_release.json.jbuilder index ddf59ee75..1ccdbe617 100644 --- a/app/views/version_releases/_version_release.json.jbuilder +++ b/app/views/version_releases/_version_release.json.jbuilder @@ -12,6 +12,7 @@ json.draft version&.draft ? "草稿" : (version&.prerelease ? "预发行" : "稳 json.created_at format_time(version.created_at.to_s.to_time) json.published_at format_time(version.created_at.to_s.to_time) json.user_name user.present? ? user.try(:show_real_name) : "" +json.user_login user&.login json.image_url user.present? ? url_to_avatar(user) : "" json.attachments do json.array! version.try(:attachments) do |attachment| From 588850440e8c6cb03c55029dd3e01b971b45b307 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 30 Sep 2021 19:49:17 +0800 Subject: [PATCH 28/34] fix: decode error --- app/controllers/repositories_controller.rb | 1 + app/helpers/repositories_helper.rb | 2 +- app/views/repositories/_simple_entry.json.jbuilder | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 9887a2918..124dbc878 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -74,6 +74,7 @@ class RepositoriesController < ApplicationController def sub_entries file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) + @path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" if @project.educoder? if params[:type] === 'file' diff --git a/app/helpers/repositories_helper.rb b/app/helpers/repositories_helper.rb index d34e3a8d9..1096d1d21 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -6,7 +6,7 @@ module RepositoriesHelper def render_decode64_content(str) return nil if str.blank? - Base64.decode64(str).force_encoding("UTF-8") + Base64.decode64(str).force_encoding("UTF-8").encode("UTF-8", invalid: :replace) end def download_type(str) diff --git a/app/views/repositories/_simple_entry.json.jbuilder b/app/views/repositories/_simple_entry.json.jbuilder index cc9bdc3ae..6f33ac35e 100644 --- a/app/views/repositories/_simple_entry.json.jbuilder +++ b/app/views/repositories/_simple_entry.json.jbuilder @@ -9,7 +9,7 @@ if @project.forge? json.type entry['type'] json.size entry['size'] - json.content decode64_content(entry, @owner, @repository, @ref) + json.content decode64_content(entry, @owner, @repository, @ref, @path) json.target entry['target'] download_url = From 76183344bc6c96a38220313db9378e1ff0785f7c Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 8 Oct 2021 14:04:13 +0800 Subject: [PATCH 29/34] fix: main content_type --- app/controllers/main_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb index 7b7468f93..afe767897 100644 --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -23,9 +23,9 @@ class MainController < ApplicationController # TODO: 这块之后需要整合,者架构重新变化,统一跳转到index后再路由分发 if params[:path] && params[:path]&.include?("h5educoderbuild") && params[:path].split("/").first == "h5educoderbuild" - render file: 'public/h5educoderbuild/index.html', :layout => false + render file: 'public/h5educoderbuild/index.html', :layout => false, :content_type=> 'text/html' else - render file: 'public/react/build/index.html', :layout => false + render file: 'public/react/build/index.html', :layout => false, :content_type=> 'text/html' end end From 9d5503f09fefcb79665d344ddbb1a8bb2f743592 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 8 Oct 2021 14:43:46 +0800 Subject: [PATCH 30/34] fix: lastcommit --- app/controllers/repositories_controller.rb | 10 ++++- .../repository/commits/file_list_service.rb | 43 +++++++++++++++++++ 2 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 app/services/gitea/repository/commits/file_list_service.rb diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 124dbc878..5080dd942 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -254,8 +254,14 @@ class RepositoriesController < ApplicationController # TODO 获取最新commit信息 def project_commits - Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier, - sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call + if params[:filepath].present? + file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) + Gitea::Repository::Commits::FileListService.new(@project.owner.login, @project.identifier, file_path_uri, + sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call + else + Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier, + sha: get_ref, page: 1, limit: 1, token: current_user&.gitea_token).call + end end def get_statistics diff --git a/app/services/gitea/repository/commits/file_list_service.rb b/app/services/gitea/repository/commits/file_list_service.rb new file mode 100644 index 000000000..b1606a0f3 --- /dev/null +++ b/app/services/gitea/repository/commits/file_list_service.rb @@ -0,0 +1,43 @@ +# Get a list of all commits from a repository +class Gitea::Repository::Commits::FileListService < Gitea::ClientService + attr_reader :owner, :repo_name, :filepath, :args + + # sha: SHA or branch to start listing commits from (usually 'master') + # ex: + # Gitea::Repository::Commits::ListService.new(@project.owner.login, @project.identifier, + # sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call + def initialize(owner, repo_name, filepath, **args) + @owner = owner + @repo_name = repo_name + @filepath = filepath + @args = args + end + + def call + response = get(url, params) + render_result(response) + end + + private + def params + {sha: args[:sha] || 'master', page: args[:page] || PAGINATE_DEFAULT_PAGE, limit: args[:limit] || PAGINATE_DEFAULT_LIMIT, token: args[:token] || "" } + end + + def url + "/repos/#{owner}/#{repo_name}/file_commits/#{filepath}".freeze + end + + def render_result(response) + 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 + nil + # {status: -1, message: "#{body['message']}"} + end + end +end From f957b6f95e24eacbb3d3ff169348b3d8b6f2bec5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 8 Oct 2021 14:58:29 +0800 Subject: [PATCH 31/34] fix: commits filter by filepath --- app/controllers/repositories_controller.rb | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index 5080dd942..e1184fd17 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -105,8 +105,14 @@ class RepositoriesController < ApplicationController end def commits - @hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier, - sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call + if params[:filepath].present? + file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip)) + @hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri, + sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call + else + @hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier, + sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call + end end def commits_slice From 46ab55d50f555c2bd318bd93023c90a07421e592 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 9 Oct 2021 09:50:35 +0800 Subject: [PATCH 32/34] fix: issue change operate permission and repository detail remove garbage --- app/controllers/issues_controller.rb | 4 +- app/controllers/repositories_controller.rb | 10 ---- app/services/repositories/detail_service.rb | 52 +++++++------------- app/views/repositories/detail.json.jbuilder | 16 +----- app/views/repositories/entries.json.jbuilder | 1 - 5 files changed, 22 insertions(+), 61 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index 7b90e3108..bfa15aa50 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -15,7 +15,7 @@ class IssuesController < ApplicationController include TagChosenHelper def index - @user_admin_or_member = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user)) + @user_admin_or_member = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user) || @project.is_public?) issues = @project.issues.issue_issue.issue_index_includes issues = issues.where(is_private: false) unless @user_admin_or_member @@ -453,7 +453,7 @@ class IssuesController < ApplicationController end def operate_issue_permission - return render_forbidden("您没有权限进行此操作.") unless current_user.admin? || @project.member?(current_user) + return render_forbidden("您没有权限进行此操作.") unless current_user.present? && current_user.logged? && (current_user.admin? || @project.member?(current_user) || @project.is_public?) end def export_issues(issues) diff --git a/app/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index e1184fd17..35f11f476 100644 --- a/app/controllers/repositories_controller.rb +++ b/app/controllers/repositories_controller.rb @@ -55,16 +55,6 @@ class RepositoriesController < ApplicationController @entries = Gitea::Repository::Entries::ListService.new(@owner, @project.identifier, ref: @ref).call @entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : [] @path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/" - - # TODO - # 临时处理readme文件问题 - result = Gitea::Repository::Readme::GetService.call(@owner.login, @project.identifier, @ref, @owner&.gitea_token) - @readme = - if result[:status] == :success - result[:body] - else - {} - end end end diff --git a/app/services/repositories/detail_service.rb b/app/services/repositories/detail_service.rb index 984f10d51..4b29d50a7 100644 --- a/app/services/repositories/detail_service.rb +++ b/app/services/repositories/detail_service.rb @@ -8,29 +8,25 @@ class Repositories::DetailService < ApplicationService end def call - if @repo.project.educoder? - return { - repo: {}, - release: [], - branch: [], - branch_type: [], - tag: [], - contributor: [], - language: {}, - readme: {} - } - else - return { - repo: repo_suitable, - release: release_suitable, - branch: branch_suitable, - branch_slice: branch_slice_suitable, - tag: tag_suitable, - contributor: contributor_suitable, - language: language_suitable, - readme: readme_suitable - } - end + return { + repo: repo_suitable, + release: release_suitable, + branch: branch_suitable, + tag: tag_suitable, + contributor: contributor_suitable, + language: language_suitable + } + rescue + return { + repo: {}, + release: [], + branch: [], + branch_type: [], + tag: [], + contributor: [], + language: {}, + readme: {} + } end private @@ -48,11 +44,6 @@ class Repositories::DetailService < ApplicationService branches.is_a?(Hash) && branches.key?(:status) ? [] : branches end - def branch_slice_suitable - branches = Gitea::Repository::Branches::ListSliceService.call(@owner, @repo.identifier) - branches.is_a?(Hash) && branches.key?(:status) ? [] : branches - end - def tag_suitable tags = Gitea::Repository::Tags::ListService.call(@owner&.gitea_token, @owner.login, @repo.identifier) tags.is_a?(Hash) && tags[:status] == -1 ? [] : tags @@ -67,9 +58,4 @@ class Repositories::DetailService < ApplicationService result = Gitea::Repository::Languages::ListService.call(@owner.login, @repo.identifier, @user&.gitea_token) result[:status] === :success ? hash_transform_precentagable(result[:body]) : nil end - - def readme_suitable - result = Gitea::Repository::Readme::GetService.call(@owner.login, @repo.identifier, @repo.default_branch, @owner.gitea_token) - result[:status] === :success ? result[:body] : nil - end end diff --git a/app/views/repositories/detail.json.jbuilder b/app/views/repositories/detail.json.jbuilder index 18b5dd887..c08077088 100644 --- a/app/views/repositories/detail.json.jbuilder +++ b/app/views/repositories/detail.json.jbuilder @@ -1,11 +1,6 @@ json.content @project.content json.website @project.website json.lesson_url @project.lesson_url -if @result[:readme].blank? - json.readme nil -else - json.readme @result[:readme].merge(content: readme_render_decode64_content(@result[:readme]["content"], nil)) -end json.identifier render_identifier(@project) json.invite_code @project.invite_code json.name @project.name @@ -72,15 +67,6 @@ json.branches do end json.total_count @result[:branch].size end -json.branches_slice do - json.list @result[:branch_slice].each do |branch_slice| - json.branch_type branch_slice["branch_name"] - json.list branch_slice["branches"].each do |branch| - json.name branch["name"] - end - end - json.total_count @result[:branch_slice].size -end json.tags do json.list @result[:tag].each do |tag| json.name tag["name"] @@ -104,6 +90,6 @@ json.contributors do end json.total_count total_count end -json.languages @result[:language] +json.languages @result[:language].blank? ? nil : @result[:language] json.partial! 'author', locals: { user: @project.owner } diff --git a/app/views/repositories/entries.json.jbuilder b/app/views/repositories/entries.json.jbuilder index 8c028e6a2..8d1e67beb 100644 --- a/app/views/repositories/entries.json.jbuilder +++ b/app/views/repositories/entries.json.jbuilder @@ -61,5 +61,4 @@ if @project.forge? end end - json.readme @readme.merge(content: readme_render_decode64_content(@readme["content"], nil)) end From 6e653f768a6492d95b4dca23fc29b86ce91bb3dd Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 9 Oct 2021 10:45:13 +0800 Subject: [PATCH 33/34] fix: pullrequest comments_count --- app/views/pull_requests/show.json.jbuilder | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/pull_requests/show.json.jbuilder b/app/views/pull_requests/show.json.jbuilder index 6f6343903..046809386 100644 --- a/app/views/pull_requests/show.json.jbuilder +++ b/app/views/pull_requests/show.json.jbuilder @@ -5,7 +5,7 @@ json.project_identifier @project.identifier json.pr_time time_from_now(@pull_request.updated_at) json.commits_count @pull_request.commits_count json.files_count @pull_request.files_count -json.comments_count @pull_request.comments_count +json.comments_count @issue.get_journals_size json.pull_request do json.extract! @pull_request, :id,:base, :head, :status,:fork_project_id, :is_original From a22327d0df7403aec002e507fcc6ac351d566307 Mon Sep 17 00:00:00 2001 From: yystopf Date: Sat, 9 Oct 2021 14:19:02 +0800 Subject: [PATCH 34/34] fix: add comments_total_count --- app/services/gitea/pull_request/files_service.rb | 2 +- app/views/pull_requests/show.json.jbuilder | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/services/gitea/pull_request/files_service.rb b/app/services/gitea/pull_request/files_service.rb index 9785588e2..a8cb26627 100644 --- a/app/services/gitea/pull_request/files_service.rb +++ b/app/services/gitea/pull_request/files_service.rb @@ -24,7 +24,7 @@ class Gitea::PullRequest::FilesService < Gitea::ClientService def params Hash.new.merge(token: token) end - + def url "/repos/#{owner}/#{repo}/pulls/#{pull_number}/files".freeze end diff --git a/app/views/pull_requests/show.json.jbuilder b/app/views/pull_requests/show.json.jbuilder index 046809386..5c30bd172 100644 --- a/app/views/pull_requests/show.json.jbuilder +++ b/app/views/pull_requests/show.json.jbuilder @@ -5,7 +5,8 @@ json.project_identifier @project.identifier json.pr_time time_from_now(@pull_request.updated_at) json.commits_count @pull_request.commits_count json.files_count @pull_request.files_count -json.comments_count @issue.get_journals_size +json.comments_count @issue.journals.parent_journals.size +json.comments_total_count @issue.get_journals_size json.pull_request do json.extract! @pull_request, :id,:base, :head, :status,:fork_project_id, :is_original