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/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 diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 78056beed..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] @@ -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/controllers/repositories_controller.rb b/app/controllers/repositories_controller.rb index d9fba6ef4..f9d949db5 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 @@ -54,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 @@ -73,6 +64,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' @@ -103,10 +95,21 @@ 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 + @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) @@ -120,7 +123,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 @@ -183,10 +190,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 + @readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref]) + render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha") + rescue + render json: nil end def languages @@ -214,7 +227,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 @@ -237,8 +250,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/controllers/version_releases_controller.rb b/app/controllers/version_releases_controller.rb index 618eb0735..2d7546a1c 100644 --- a/app/controllers/version_releases_controller.rb +++ b/app/controllers/version_releases_controller.rb @@ -1,14 +1,14 @@ 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 :require_login, except: [:index, :show] + before_action :check_release_authorize, except: [:index, :show] + 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?) - @forge_releases = @repository.version_releases.select(:id,:version_gid, :created_at).includes(:attachments) + @user_admin_permission = current_user.present? && (@repository.project.all_managers.include?(current_user) || current_user.admin?) end def new @@ -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, "名称不能为空") @@ -37,13 +41,14 @@ 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"], 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") @@ -81,7 +86,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 @@ -102,7 +107,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, "删除成功") @@ -157,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/docs/slate/source/includes/_repositories.md b/app/docs/slate/source/includes/_repositories.md index 1552655e4..3604689c8 100644 --- a/app/docs/slate/source/includes/_repositories.md +++ b/app/docs/slate/source/includes/_repositories.md @@ -274,6 +274,124 @@ 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 | +|page |否| 1 | integer | 页码 | +|limit |否| 20| integer | 每页个数 | + + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|id |int |标签id | +|name |string|标签名称| +|zipball_url |string|标签zip包下载地址| +|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.committer|object|commit的提交者| +|commit.author|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", + "tagger": { + "id": 4, + "login": "testforge1", + "name": "testforge1", + "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", + "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" + } + } + }, + { + "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", + "tagger": { + "id": null, + "login": "viletyy", + "name": "viletyy", + "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", + "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" + } + } + } +] +``` + ## 编辑仓库信息 编辑仓库信息 @@ -868,6 +986,128 @@ 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" +} +``` + + +## 获取仓库贡献者 +获取仓库贡献者 + +> 示例: + +```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/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 7057ac581..1096d1d21 100644 --- a/app/helpers/repositories_helper.rb +++ b/app/helpers/repositories_helper.rb @@ -6,16 +6,16 @@ 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) - 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 @@ -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? && author_json["email"].present?) + return find_user_by_login_and_mail(author_json['name'], author_json["email"]) + end end def readme_render_decode64_content(str, path) @@ -79,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 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/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/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/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 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/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/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/services/repositories/detail_service.rb b/app/services/repositories/detail_service.rb index d8853cf45..4b29d50a7 100644 --- a/app/services/repositories/detail_service.rb +++ b/app/services/repositories/detail_service.rb @@ -8,27 +8,25 @@ class Repositories::DetailService < ApplicationService end def call - if @repo.project.educoder? - return { - repo: {}, - release: [], - branch: [], - tag: [], - contributor: [], - language: {}, - readme: {} - } - else - return { - repo: repo_suitable, - release: release_suitable, - branch: branch_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 @@ -43,7 +41,7 @@ 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 tag_suitable @@ -60,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/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 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 new file mode 100644 index 000000000..31c662a13 --- /dev/null +++ b/app/views/projects/branches_slice.json.jbuilder @@ -0,0 +1,24 @@ +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 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 diff --git a/app/views/pull_requests/show.json.jbuilder b/app/views/pull_requests/show.json.jbuilder index 6f6343903..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 @pull_request.comments_count +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 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 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/_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 = 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'] 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 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/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/app/views/repositories/detail.json.jbuilder b/app/views/repositories/detail.json.jbuilder index c00ae3462..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 @@ -95,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 diff --git a/app/views/repositories/tags.json.jbuilder b/app/views/repositories/tags.json.jbuilder index 9db3ff93e..d1ee3671e 100644 --- a/app/views/repositories/tags.json.jbuilder +++ b/app/views/repositories/tags.json.jbuilder @@ -4,8 +4,23 @@ 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.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 + json.author do + json.partial! 'commit_author', user: render_commit_author(tag['commit']['author']), name: tag['commit']['author']['name'] + end 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..1ccdbe617 --- /dev/null +++ b/app/views/version_releases/_version_release.json.jbuilder @@ -0,0 +1,21 @@ +json.version_id version.try(:id) +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) : "" +json.user_login user&.login +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 88ae36f26..85d1be256 100644 --- a/app/views/version_releases/index.json.jbuilder +++ b/app/views/version_releases/index.json.jbuilder @@ -1,51 +1,17 @@ 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| - 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.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) : "" - 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) : "" - end - end - - json.attachments do - json.array! version.try(:attachments) do |attachment| - json.partial! "attachments/attachment_simple", locals: {attachment: attachment} - 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 +json.total_count @version_releases.total_count \ No newline at end of file diff --git a/app/views/version_releases/show.json.jbuilder b/app/views/version_releases/show.json.jbuilder new file mode 100644 index 000000000..716f5d7b2 --- /dev/null +++ b/app/views/version_releases/show.json.jbuilder @@ -0,0 +1,2 @@ + +json.partial! "version_release", locals: {version: @version, user: @version&.user} \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 9c6dda1b0..005bd926a 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' @@ -431,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 @@ -526,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 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 diff --git a/public/docs/api.html b/public/docs/api.html index c77c08988..ef03d978f 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -469,6 +469,9 @@
编辑仓库信息
+仓库标签列表
-示例:
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
请求参数:
@@ -6213,6 +6222,20 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
string
项目标识identifier
+
+page
+否
+1
+integer
+页码
+
+
+limit
+否
+20
+integer
+每页个数
+
返回字段说明:
@@ -6223,6 +6246,197 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
+id
+int
+标签id
+
+
+name
+string
+标签名称
+
+
+zipball_url
+string
+标签zip包下载地址
+
+
+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.committer
+object
+commit的提交者
+
+
+commit.author
+object
+commit的作者
+
+
+
+
+返回的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",
+ "tagger": {
+ "id": 4,
+ "login": "testforge1",
+ "name": "testforge1",
+ "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",
+ "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"
+ }
+ }
+ },
+ {
+ "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",
+ "tagger": {
+ "id": null,
+ "login": "viletyy",
+ "name": "viletyy",
+ "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",
+ "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"
+ }
+ }
+ }
+]
+
编辑仓库信息
+编辑仓库信息
+
+
+示例:
+
+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
+请求参数:
+
+
+参数
+必选
+默认
+类型
+字段说明
+
+
+
+owner
+是
+
+string
+用户登录名
+
+
+repo
+是
+
+string
+项目标识identifier
+
+
+返回字段说明:
+
+
+参数
+类型
+字段说明
+
+
+
identifier
string
仓库标识
@@ -6291,9 +6505,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
-请求参数:
+请求参数:
参数
@@ -6353,7 +6567,7 @@ http://localhost:3000/api/jasder/jasder_test.json
项目是否私有, true:为私有,false: 公开,默认为公开
-返回字段说明:
+返回字段说明:
参数
@@ -6418,9 +6632,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
-请求参数:
+请求参数:
参数
@@ -6445,7 +6659,7 @@ http://localhost:3000/api/jasder/jasder_test.json
项目标识identifier
-返回字段说明:
+返回字段说明:
参数
@@ -6486,83 +6700,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
-请求参数:
-
-
-参数
-必选
-默认
-类型
-字段说明
-
-
-
-owner
-是
-
-string
-用户登录名
-
-
-repo
-是
-
-string
-项目标识identifier
-
-
-user_id
-是
-int
-
-用户id
-
-
-返回字段说明:
-
-
-参数
-类型
-字段说明
-
-
-
-status
-int
-返回状态, 0: 表示操作成功
-
-
-message
-string
-返回信息说明
-
-
-
-
-返回的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
请求参数:
@@ -6615,6 +6754,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
+请求参数:
+
+
+参数
+必选
+默认
+类型
+字段说明
+
+
+
+owner
+是
+
+string
+用户登录名
+
+
+repo
+是
+
+string
+项目标识identifier
+
+
+user_id
+是
+int
+
+用户id
+
+
+返回字段说明:
+
+
+参数
+类型
+字段说明
+
+
+
+status
+int
+返回状态, 0: 表示操作成功
+
+
+message
+string
+返回信息说明
+
+
+
返回的JSON示例:
@@ -6637,9 +6851,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
-请求参数:
+请求参数:
参数
@@ -6678,7 +6892,7 @@ http://localhost:3000/api/jasder/jasder_test/change_role.json
取值范围:"Manager", "Developer", "Reporter";分别为项目管理人员(拥有所有操作权限)、项目开发人员(只拥有读写权限)、项目报告人员(只拥有读权限)
-返回字段说明:
+返回字段说明:
参数
@@ -6720,9 +6934,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
-请求参数:
+请求参数:
参数
@@ -6761,7 +6975,7 @@ http://localhost:3000/api/jasder/jasder_test/collaborators.json
每页多少条数据,默认15条
-返回字段说明:
+返回字段说明:
参数
@@ -6849,9 +7063,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
-请求参数:
+请求参数:
参数
@@ -6890,7 +7104,7 @@ http://localhost:3000/api/yystopf/ceshi/files.json
分支名,默认为仓库默认分支
-返回字段说明:
+返回字段说明:
参数
@@ -6972,9 +7186,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
-请求参数:
+请求参数:
参数
@@ -7006,7 +7220,7 @@ http://localhost:3000//api/jasder/jasder_test/entries.json
分支名称、tag名称或是提交记录id,默认为master分支
-返回字段说明:
+返回字段说明:
参数
@@ -7120,9 +7334,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
-请求参数:
+请求参数:
参数
@@ -7161,7 +7375,7 @@ http://localhost:3000//api/jasder/jasder_test/sub_entries.json
分支名称、tag名称或是提交记录id,默认为master分支
-返回字段说明:
+返回字段说明:
参数
@@ -7247,6 +7461,237 @@ http://localhost:3000//api/jasder/jasder_test/sub_entries.json
+获取仓库README文件
+获取仓库README文件
+
+
+示例:
+
+curl -X GET \
+-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/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示例:
+
+{
+ "type": "file",
+ "encoding": "base64",
+ "size": 24,
+ "name": "README.md",
+ "path": "lib/README.md",
+ "content": "ZGZhc2RhZGpmIGRrZnNsCgpzZGZkZnMK",
+ "sha": "860962cd21c60b1a9e07d723080c87c32c18d44a"
+}
+
+
+获取仓库贡献者
+获取仓库贡献者
+
+
+示例:
+
+curl -X GET \
+-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/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示例:
+
+{
+ "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列表
@@ -7256,9 +7701,9 @@ http://localhost:3000//api/jasder/jasder_test/sub_entries.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
-请求参数:
+请求参数:
参数
@@ -7283,7 +7728,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks.json
项目标识identifier
-返回字段说明:
+返回字段说明:
参数
@@ -7385,9 +7830,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
-请求参数:
+请求参数:
参数
@@ -7419,7 +7864,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/edit.json
webhook ID
-返回字段说明:
+返回字段说明:
参数
@@ -7620,9 +8065,9 @@ 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 请求
+HTTP 请求
POST /api/:owner/:repo/webhooks.json
-请求参数:
+请求参数:
参数
@@ -7806,7 +8251,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks.json
"branch_filter": "*",
"events": ["push"]
}
-返回字段说明:
+返回字段说明:
参数
@@ -7878,9 +8323,9 @@ http://localhost:3000/api/yystopf/ceshi/webhooks.json
curl -X PATCH \
http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
await octokit.request('PATCH /api/yystopf/ceshi/webhooks/7.json')
-
HTTP 请求
+HTTP 请求
PATCH /api/:owner/:repo/webhooks/:id.json
-请求参数:
+请求参数:
参数
@@ -8071,7 +8516,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
"branch_filter": "*",
"events": ["push"]
}
-返回字段说明:
+返回字段说明:
返回的JSON示例:
@@ -8092,9 +8537,9 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
curl -X DELETE \
http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
await octokit.request('DELETE /api/yystopf/ceshi/webhooks/7.json')
-
HTTP 请求
+HTTP 请求
DELETE /api/:owner/:repo/webhooks/:id.json
-请求参数:
+请求参数:
参数
@@ -8126,7 +8571,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/7.json
webhook id
-返回字段说明:
+返回字段说明:
返回的JSON示例:
@@ -8147,9 +8592,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 +8626,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/tasks.json
webhook ID
-返回字段说明:
+返回字段说明:
参数
@@ -8418,9 +8863,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 +8897,7 @@ http://localhost:3000/api/yystopf/ceshi/webhooks/3/test.json
webhook ID
-返回字段说明:
+返回字段说明:
返回的JSON示例: