| @@ -135,4 +135,4 @@ gem 'doorkeeper' | |||
| gem 'doorkeeper-jwt' | |||
| gem 'gitea-client', '~> 0.10.2' | |||
| gem 'gitea-client', '~> 0.10.5' | |||
| @@ -2,6 +2,7 @@ class Api::V1::BaseController < ApplicationController | |||
| include Api::ProjectHelper | |||
| include Api::UserHelper | |||
| include Api::PullHelper | |||
| # before_action :doorkeeper_authorize! | |||
| # skip_before_action :user_setup | |||
| @@ -30,18 +31,18 @@ class Api::V1::BaseController < ApplicationController | |||
| # 具有对仓库的管理权限 | |||
| def require_manager_above | |||
| @project = load_project | |||
| return render_forbidden unless current_user.admin? && @project.manager?(current_user) | |||
| return render_forbidden if !current_user.admin? && !@project.manager?(current_user) | |||
| end | |||
| # 具有对仓库的操作权限 | |||
| def require_operate_above | |||
| @project = load_project | |||
| return render_forbidden unless current_user.admin? && @project.operator?(current_user) | |||
| return render_forbidden if !current_user.admin? && !@project.operator?(current_user) | |||
| end | |||
| # 具有对仓库的访问权限 | |||
| def require_public_and_member_above | |||
| @project = load_project | |||
| return render_forbidden unless @project.is_public || (current_user.admin? && @project.member?(current_user)) | |||
| return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user) | |||
| end | |||
| end | |||
| @@ -2,7 +2,11 @@ class Api::V1::Projects::ContentsController < Api::V1::BaseController | |||
| before_action :require_operate_above, only: [:batch] | |||
| def batch | |||
| @result_object = Api::V1::Projects::Contents::BatchCreateService.call(@project, batch_content_params, current_user&.gitea_token) | |||
| @batch_content_params = batch_content_params | |||
| # 处理下author和committer信息,如果没传则默认为当前用户信息 | |||
| @batch_content_params.merge!(author_email: current_user.mail, author_name: current_user.login) if batch_content_params[:author_email].blank? && batch_content_params[:author_name].blank? | |||
| @batch_content_params.merge!(committer_email: current_user.mail, committer_name: current_user.login) if batch_content_params[:committer_email].blank? && batch_content_params[:committer_name].blank? | |||
| @result_object = Api::V1::Projects::Contents::BatchCreateService.call(@project, @batch_content_params, current_user&.gitea_token) | |||
| puts @result_object | |||
| end | |||
| @@ -0,0 +1,5 @@ | |||
| class Api::V1::Projects::Pulls::BaseController < Api::V1::BaseController | |||
| before_action :require_public_and_member_above | |||
| before_action :load_pull_request | |||
| end | |||
| @@ -0,0 +1,40 @@ | |||
| class Api::V1::Projects::Pulls::JournalsController < Api::V1::Projects::Pulls::BaseController | |||
| def index | |||
| @journals = Api::V1::Projects::Pulls::Journals::ListService.call(@project, @pull_request, params, current_user) | |||
| @journals = kaminari_paginate(@journals) | |||
| end | |||
| def create | |||
| @journal = Api::V1::Projects::Pulls::Journals::CreateService.call(@project, @pull_request, create_params, current_user) | |||
| end | |||
| before_action :find_journal, only: [:update, :destroy] | |||
| def update | |||
| @journal = Api::V1::Projects::Pulls::Journals::UpdateService.call(@project, @pull_request, @journal, update_params, current_user) | |||
| end | |||
| def destroy | |||
| if @journal.destroy | |||
| render_ok | |||
| else | |||
| render_error("删除评论失败!") | |||
| end | |||
| end | |||
| private | |||
| def create_params | |||
| params.permit(:parent_id, :line_code, :note, :commit_id, :path, :type, :review_id, :diff => {}) | |||
| end | |||
| def update_params | |||
| params.permit(:note, :commit_id, :state) | |||
| end | |||
| def find_journal | |||
| @journal = @pull_request.journals.find_by_id(params[:id]) | |||
| return render_not_found unless @journal.present? | |||
| end | |||
| end | |||
| @@ -0,0 +1,20 @@ | |||
| class Api::V1::Projects::Pulls::PullsController < Api::V1::BaseController | |||
| before_action :require_public_and_member_above | |||
| def index | |||
| @pulls = Api::V1::Projects::Pulls::ListService.call(@project, query_params) | |||
| @pulls = kaminari_paginate(@pulls) | |||
| end | |||
| before_action :load_pull_request, only: [:show] | |||
| def show | |||
| @result_object = Api::V1::Projects::Pulls::GetService.call(@project, @pull_request, current_user&.gitea_token) | |||
| @last_review = @pull_request.reviews.order(created_at: :desc).take | |||
| end | |||
| private | |||
| def query_params | |||
| params.permit(:status, :keyword, :priority_id, :issue_tag_id, :version_id, :reviewer_id, :sort_by, :sort_direction) | |||
| end | |||
| end | |||
| @@ -0,0 +1,22 @@ | |||
| class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::BaseController | |||
| def index | |||
| @reviews = @pull_request.reviews | |||
| @reviews = kaminari_paginate(@reviews) | |||
| end | |||
| before_action :require_reviewer, only: [:create] | |||
| def create | |||
| @review = Api::V1::Projects::Pulls::Reviews::CreateService.call(@project, @pull_request, review_params, current_user) | |||
| end | |||
| private | |||
| def require_reviewer | |||
| return render_forbidden('您没有审查权限,请联系项目管理员') if !current_user.admin? && !@pull_request.reviewers.exists?(current_user.id) | |||
| end | |||
| def review_params | |||
| params.require(:review).permit(:content, :commit_id, :status) | |||
| end | |||
| end | |||
| @@ -0,0 +1,10 @@ | |||
| class Api::V1::Projects::Pulls::VersionsController < Api::V1::Projects::Pulls::BaseController | |||
| def index | |||
| @result_object = Api::V1::Projects::Pulls::Versions::ListService.call(@project, @pull_request, {page: page, limit: limit}, current_user&.gitea_token) | |||
| end | |||
| def diff | |||
| @result_object = Api::V1::Projects::Pulls::Versions::GetDiffService.call(@project, @pull_request, params[:id], {filepath: params[:filepath]}, current_user&.gitea_token) | |||
| end | |||
| end | |||
| @@ -20,9 +20,9 @@ class ApplicationController < ActionController::Base | |||
| # TODO | |||
| # check sql query time | |||
| before_action do | |||
| if request.subdomain === 'testforgeplus' || request.subdomain === "profiler" | |||
| Rack::MiniProfiler.authorize_request | |||
| end | |||
| # if request.subdomain === 'testforgeplus' || request.subdomain === "profiler" | |||
| # Rack::MiniProfiler.authorize_request | |||
| # end | |||
| end | |||
| DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z) | |||
| @@ -0,0 +1,19 @@ | |||
| module Api::PullHelper | |||
| extend ActiveSupport::Concern | |||
| def load_pull_request | |||
| pull_request_id = params[:pull_id] || params[:id] | |||
| @pull_request = @project.pull_requests.where(gitea_number: pull_request_id).where.not(id: pull_request_id).take || PullRequest.find_by_id(pull_request_id) | |||
| @issue = @pull_request&.issue | |||
| if @pull_request | |||
| logger.info "###########pull_request founded" | |||
| @pull_request | |||
| else | |||
| logger.info "###########pull_request not found" | |||
| @pull_request = nil | |||
| render_not_found and return | |||
| end | |||
| @pull_request | |||
| end | |||
| end | |||
| @@ -0,0 +1,38 @@ | |||
| class MarkFilesController < ApplicationController | |||
| before_action :require_login | |||
| before_action :load_project | |||
| before_action :load_pull_request | |||
| def index | |||
| @files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token) | |||
| @mark_files = MarkFile.where(pull_request_id: @pull_request.id) | |||
| end | |||
| def create | |||
| unless @pull_request.mark_files.present? | |||
| MarkFile.bulk_insert(*%i[pull_request_id, file_path_sha file_path created_at updated_at]) do |worker| | |||
| @files_result['Files'].each do |file| | |||
| worker.add(pull_request_id: @pull_request.id, file_path_sha: SecureRandom.uuid.gsub("-", ""), file_path: file['Name']) | |||
| end | |||
| end | |||
| end | |||
| end | |||
| def mark_file_as_unread | |||
| end | |||
| def mark_file_as_read | |||
| end | |||
| private | |||
| def review_params | |||
| params.require(:review).permit(:content, :commit_id, :status) | |||
| end | |||
| def load_pull_request | |||
| @pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || PullRequest.find_by_id(params[:id]) | |||
| end | |||
| end | |||
| @@ -0,0 +1,112 @@ | |||
| class ObRepositorySyncsController < ApplicationController | |||
| before_action :require_login | |||
| before_action :load_project | |||
| before_action :load_ob_repository_sync, except: [:create] | |||
| before_action :authenticate_user! | |||
| def index | |||
| render_ok(data: @ob_repository_sync) | |||
| end | |||
| def create | |||
| tip_exception "参数错误" if params[:github_address].blank? && params[:gitee_address].blank? | |||
| project_name ="#{@project.owner.name}:#{@project.identifier}" | |||
| service = ObRepositorySync::ApiService.new(project_name) | |||
| project_params = params.merge({ "gitlink_address": @project.repository.url }) | |||
| res = service.create_projects(project_params) | |||
| tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200" | |||
| sync_id = res["data"]["id"] | |||
| ob_repository_sync = ObRepositorySync.find_or_initialize_by(project_id: @project.id) | |||
| ob_repository_sync.project_id = @project.id | |||
| ob_repository_sync.user_id = current_user.id | |||
| ob_repository_sync.name = project_name | |||
| ob_repository_sync.github_address = "#{params[:github_address]}" | |||
| ob_repository_sync.gitee_address = "#{params[:gitee_address]}" | |||
| ob_repository_sync.gitlink_address = @project.repository.url | |||
| ob_repository_sync.github_token = "#{params[:github_token]}" | |||
| ob_repository_sync.gitee_token = "#{params[:gitee_token]}" | |||
| ob_repository_sync.sync_id = sync_id | |||
| ob_repository_sync.save! | |||
| render_ok | |||
| end | |||
| def delete | |||
| service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) | |||
| res = service.delete_project @ob_repository_sync.sync_id | |||
| tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200" | |||
| if res["code"].to_s == "200" | |||
| @ob_repository_sync.destroy! | |||
| end | |||
| end | |||
| def jobs | |||
| tip_exception "该项目未创建同步任务" if @ob_repository_sync.blank? | |||
| service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) | |||
| res = service.get_projects_jobs | |||
| render_ok(count: res["data"]["total"], data: res["data"]["list"]) | |||
| end | |||
| def create_jobs | |||
| service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) | |||
| res = service.create_projects_jobs(params) | |||
| tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200" | |||
| job_id = res["data"]["id"] | |||
| job = ObRepositorySyncJob.new | |||
| job.ob_repository_sync_id = @ob_repository_sync.id | |||
| job.github_branch = "#{params[:github_branch]}" | |||
| job.gitee_branch = "#{params[:gitee_branch]}" | |||
| job.gitlink_branch = "#{params[:gitlink_branch]}" | |||
| job.job_type = "#{params[:type]}" | |||
| job.base = "#{params[:base]}" | |||
| job.job_id = job_id | |||
| job.save | |||
| render_ok | |||
| end | |||
| def delete_job | |||
| tip_exception "缺少参数job_id" if params[:job_id].blank? | |||
| service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) | |||
| res = service.delete_job params[:job_id] | |||
| tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200" | |||
| @ob_repository_sync.destroy! | |||
| render_ok | |||
| end | |||
| def start_job | |||
| tip_exception "缺少参数job_id" if params[:job_id].blank? | |||
| service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) | |||
| res = service.start_job params[:job_id] | |||
| tip_exception "启动错误: #{res["msg"]}" if res["code"].to_s != "200" | |||
| render_ok | |||
| end | |||
| def stop_job | |||
| tip_exception "缺少参数job_id" if params[:job_id].blank? | |||
| service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) | |||
| res = service.stop_job params[:job_id] | |||
| tip_exception "停止错误: #{res["msg"]}" if res["code"].to_s != "200" | |||
| render_ok | |||
| end | |||
| def job_logs | |||
| tip_exception "该项目未创建同步任务" if @ob_repository_sync.blank? | |||
| tip_exception "缺少参数job_id" if params[:job_id].blank? | |||
| service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) | |||
| @data = service.job_logs params[:job_id] | |||
| tip_exception "请求错误: #{res["msg"]}" if res["code"].to_s != "200" | |||
| render_ok(count: res["data"]["total"], data: res["data"]["list"]) | |||
| end | |||
| private | |||
| def load_ob_repository_sync | |||
| @ob_repository_sync = ObRepositorySync.find_by(project_id: @project.id) | |||
| end | |||
| def authenticate_user! | |||
| return if @project.member?(current_user) || current_user.admin? | |||
| render_forbidden('你没有权限操作') | |||
| end | |||
| end | |||
| @@ -67,6 +67,8 @@ class PullRequestsController < ApplicationController | |||
| @pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params) | |||
| if @gitea_pull_request[:status] == :success | |||
| @pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"]) | |||
| reviewers = User.where(id: params[:reviewer_ids]) | |||
| @pull_request.reviewers = reviewers | |||
| SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id) if Site.has_notice_menu? | |||
| SendTemplateMessageJob.perform_later('ProjectPullRequest', current_user.id, @pull_request&.id) if Site.has_notice_menu? | |||
| Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}" | |||
| @@ -112,6 +114,9 @@ class PullRequestsController < ApplicationController | |||
| end | |||
| end | |||
| reviewers = User.where(id: params[:reviewer_ids]) | |||
| @pull_request.reviewers = reviewers | |||
| if @issue.update_attributes(@issue_params) | |||
| if @pull_request.update_attributes(@local_params.compact) | |||
| gitea_pull = Gitea::PullRequest::UpdateService.call(@owner.login, @repository.identifier, | |||
| @@ -181,7 +186,7 @@ class PullRequestsController < ApplicationController | |||
| @issue_assign_to = @issue.get_assign_user | |||
| @gitea_pull = Gitea::PullRequest::GetService.call(@owner.login, | |||
| @repository.identifier, @pull_request.gitea_number, current_user&.gitea_token) | |||
| @last_review = @pull_request.issue.reviews.take | |||
| @last_review = @pull_request.reviews.take | |||
| end | |||
| def pr_merge | |||
| @@ -5,7 +5,7 @@ class ReviewsController < ApplicationController | |||
| def create | |||
| return render_forbidden('您不是审查人员,无法进行审查!') if current_user&.id != @pull_request.issue.assigned_to_id | |||
| @journal, @review = Api::V1::Projects::PullRequests::Reviews::CreateService.call(@project, @pull_request, review_params, current_user) | |||
| @review = Api::V1::Projects::Pulls::Reviews::CreateService.call(@project, @pull_request, review_params, current_user) | |||
| end | |||
| private | |||
| @@ -3,6 +3,7 @@ class Traces::ProjectsController < Traces::BaseController | |||
| before_action :require_login | |||
| before_action :load_project | |||
| before_action :set_trace_token_to_cookie | |||
| before_action :authorizate_user_can_edit_project!, except: [:task_results] | |||
| def tasks | |||
| @@ -35,7 +36,7 @@ class Traces::ProjectsController < Traces::BaseController | |||
| return render :json => {left_tasks_count: 5, data: []} if current_user.trace_user.nil? | |||
| code, data, error = Trace::CheckResultService.call(current_user.trace_token, @project, nil, page, limit) | |||
| if code == 200 | |||
| render :json => {left_tasks_count: 5 - @project.user_trace_tasks.size, data: data} | |||
| render :json => {left_tasks_count: 5 - @project.user_trace_tasks.size, data: data, view_base: "#{Trace.trace_config[:view_domain]}/analysis_ccf/analysis-results/" } | |||
| else | |||
| render_error("获取检测记录失败 Error:#{error}") | |||
| end | |||
| @@ -86,4 +87,12 @@ class Traces::ProjectsController < Traces::BaseController | |||
| puts exception.message | |||
| normal_status(-1, exception.message) | |||
| end | |||
| def set_trace_token_to_cookie | |||
| cookies[:vue_admin_template_token] = { | |||
| :value => current_user&.trace_token, | |||
| :expires => 1.hours.from_now, | |||
| :domain => Trace.trace_config[:cookie_domain] | |||
| } | |||
| end | |||
| end | |||
| @@ -1,7 +1,10 @@ | |||
| class Users::IsPinnedProjectsController < Users::BaseController | |||
| before_action :private_user_resources!, only: [:pin] | |||
| def index | |||
| @is_pinned_projects = observed_user.pinned_projects.order(position: :desc, created_at: :asc).includes(project: [:project_category, :project_language, :repository]).order(position: :desc) | |||
| def index | |||
| @is_pinned_projects = observed_user.pinned_projects.left_joins(:project) | |||
| .where("projects.is_public = TRUE") | |||
| .order(position: :desc, created_at: :asc) | |||
| .includes(project: [:project_category, :project_language, :repository]).order(position: :desc) | |||
| @is_pinned_projects = kaminari_paginate(@is_pinned_projects) | |||
| end | |||
| @@ -1126,21 +1126,21 @@ await octokit.request('POST /api/v1/yystopf/ceshi/contents/batch.json') | |||
| ### 请求参数: | |||
| 参数 | 必选 | 默认 | 类型 | 字段说明 | |||
| --------- | ------- | ------- | -------- | ---------- | |||
| |owner |是| |string |用户登录名 | | |||
| |repo |是| |string |项目标识identifier | | |||
| |files.action_type |是| |string|操作类型 create: 创建 update: 更新 delete: 删除| | |||
| |files.content |是| |string|文件内容| | |||
| |files.encoding |是| |string|文件编码方式 text 文本 base64 加密| | |||
| |files.file_path |是| |string|文件路径| | |||
| |author_email |是| |string|作者邮箱| | |||
| |author_name |是| |string|作者名称| | |||
| |author_timeunix |是| |int|编码时间,精确到秒| | |||
| |committer_email |是| |string|提交者邮箱| | |||
| |committer_name |是| |string|提交者名称| | |||
| |committer_timeunix|是| |int|提交时间戳,精确到秒| | |||
| |branch |是| |string|提交分支| | |||
| |new_branch |否| |string|如果需要创建新分支,这个需要填| | |||
| |message |是| |string|提交信息| | |||
| |owner |是| |string |用户登录名 | | |||
| |repo |是| |string |项目标识identifier | | |||
| |files.action_type |是| |string|操作类型 create: 创建 update: 更新 delete: 删除| | |||
| |files.content |是| |string|文件内容| | |||
| |files.encoding |是| |string|文件编码方式 text 文本 base64 加密| | |||
| |files.file_path |是| |string|文件路径| | |||
| |author_email |否| 当前用户邮箱 |string|作者邮箱,不填时需要与作者名称同时为空| | |||
| |author_name |否| 当前用户标识 |string|作者名称,不填时需要与作者邮箱同时为空| | |||
| |author_timeunix |否| 当前时间戳 |int|编码时间,精确到秒| | |||
| |committer_email |否| 当前用户邮箱 |string|提交者邮箱,不填时需要与提交者名称同时为空| | |||
| |committer_name |否| 当前用户标识 |string|提交者名称,不填时需要与提交者邮箱同时为空| | |||
| |committer_timeunix|否| 当前时间戳 |int|提交时间戳,精确到秒| | |||
| |branch |是| |string|提交分支| | |||
| |new_branch |否| |string|如果需要创建新分支,这个需要填| | |||
| |message |是| |string|提交信息| | |||
| > 请求的JSON示例: | |||
| @@ -1990,25 +1990,27 @@ await octokit.request('GET /api/v1/yystopf/csfjkkj/compare.json') | |||
| |diff.files.is_created|bool|是否为新建文件| | |||
| |diff.files.is_deleted|bool|是否为删除文件| | |||
| |diff.files.is_bin|bool|是否为二进制文件| | |||
| |diff.files.is_lfs_file|bool|| | |||
| |diff.files.is_lfs_file|bool|是否为LFS文件| | |||
| |diff.files.is_renamed|bool|是否重命名| | |||
| |diff.files.is_ambiguous|bool|| | |||
| |diff.files.is_submodule|bool|是否为子模块| | |||
| |diff.files.sections.file_name|string|文件名称| | |||
| |diff.files.sections.name|string|| | |||
| |diff.files.sections.lines.left_index|int|| | |||
| |diff.files.sections.lines.right_index|int|| | |||
| |diff.files.sections.lines.left_index|int|文件变动之前所在行数| | |||
| |diff.files.sections.lines.right_index|int|文件变动之后所在行数| | |||
| |diff.files.sections.lines.match|int|| | |||
| |diff.files.sections.lines.type|int|| | |||
| |diff.files.sections.lines.content|string|| | |||
| |diff.files.sections.lines.section_path|string|| | |||
| |diff.files.sections.lines.type|int|文件变更类型| | |||
| |diff.files.sections.lines.content|string|文件变更内容| | |||
| |diff.files.sections.lines.section_path|string|文件路径| | |||
| |diff.files.sections.lines.section_last_left_index|int|| | |||
| |diff.files.sections.lines.section_last_right_index|int|| | |||
| |diff.files.sections.lines.section_left_index|int|| | |||
| |diff.files.sections.lines.section_right_index|int|| | |||
| |diff.files.sections.lines.section_left_hunk_size|int|| | |||
| |diff.files.sections.lines.section_right_hunk_size|int|| | |||
| |diff.files.sections.lines.section_left_index|int|文件变更之前所在行数| | |||
| |diff.files.sections.lines.section_right_index|int|文件变更之后所在行数(即:页面编辑器开始显示的行数)| | |||
| |diff.files.sections.lines.section_left_hunk_size|int|文件变更之前的行数| | |||
| |diff.files.sections.lines.section_right_hunk_size|int|文件变更之后的行数(及当前页面编辑器显示的总行数)| | |||
| |diff.files.is_incomplete|bool|是否不完整| | |||
| |diff.files.is_incomplete_line_too_long|bool|文件是否不完整是因为太长了| | |||
| |diff.files.is_protected|bool|文件是否被保护| | |||
| > 返回的JSON示例: | |||
| @@ -63,6 +63,7 @@ module ProjectsHelper | |||
| project_category_id: project.project_category_id, | |||
| project_language_id: project.project_language_id, | |||
| license_id: project.license_id, | |||
| jianmu_devops: jianmu_devops_code(project, user), | |||
| ignore_id: project.ignore_id | |||
| }).compact | |||
| @@ -98,4 +99,40 @@ module ProjectsHelper | |||
| def render_educoder_avatar_url(project_educoder) | |||
| [Rails.application.config_for(:configuration)['educoder']['cdn_url'], project_educoder&.image_url].join('/') | |||
| end | |||
| # 静默登录方式: | |||
| # | |||
| # 数据格式为JSON: | |||
| # { | |||
| # "userId": "xxx", // 用户唯一标识 | |||
| # "ref": "xxx", // 仓库唯一标识 | |||
| # "owner": "xxx", // 用户登录名或组织账号 | |||
| # "timestamp": xxx // 当前时间戳,单位:毫秒 | |||
| # } | |||
| # 加密方式:把数据序列化成JSON字符串,用Client Secret和固定IV(5183666c72eec9e4)对称加密(模式:AES-256-CBC) | |||
| # | |||
| # API: | |||
| # GET:https://ci-v3.test.jianmuhub.com/oauth2/authorize?code=${encode(密文)} | |||
| def jianmu_devops_code(project, user) | |||
| if user.admin? || project.member?(user.id) | |||
| data = { userId: user.id, ref: project.identifier, owner: project.owner.login, timestamp: Time.now.to_i * 1000 } | |||
| # uid = EduSetting.get("jianmu_oauth2_uid") || 'oedKx4v-WyAfu2oy_AsFpFQCH_-g91ms0PQKN7YcEuw' | |||
| # app = Doorkeeper::Application.find_by(uid: uid) | |||
| key = 'bf3c199c2470cb477d907b1e0917c17b' | |||
| aes_encrypt(key, data.to_json) | |||
| end | |||
| end | |||
| def aes_encrypt(key, des_text) | |||
| # des_text='{"access_key_id":"STS.NTuC9RVmWfJqj3JkcMzPnDf7X","access_key_secret":"E8NxRZWGNxxMfwgt5nFLnBFgg6AzgXCZkSNCyqygLuHM","end_point":"oss-accelerate.aliyuncs.com","security_token":"CAIS8gF1q6Ft5B2yfSjIr5fACIPmu7J20YiaaBX7j2MYdt9Cq6Ocujz2IHhMenVhA+8Wv/02n2hR7PcYlq9IS55VWEqc/VXLaywQo22beIPkl5Gfz95t0e+IewW6Dxr8w7WhAYHQR8/cffGAck3NkjQJr5LxaTSlWS7OU/TL8+kFCO4aRQ6ldzFLKc5LLw950q8gOGDWKOymP2yB4AOSLjIx6lAt2T8vs/7hmZPFukSFtjCglL9J/baWC4O/csxhMK14V9qIx+FsfsLDqnUIs0YWpf0p3P0doGyf54vMWUM05A6dduPS7txkLAJwerjVl1/ADxc0/hqAASXhPeiktbmDjwvnSn4iKcSGQ+xoQB468eHXNdvf13dUlbbE1+JhRi0pZIB2UCtN9oTsLHcwIHt+EJaoMd3+hGwPVmvHSXzECDFHylZ8l/pzTwlE/aCtZyVmI5cZEvmWu2xBa3GRbULo7lLvyeX1cHTVmVWf4Nk6D09PzTU8qlAj","bucket":"edu-bigfiles1","region":"oss-cn-hangzhou","callback_url":"https://data.educoder.net/api/buckets/callback.json","bucket_host":"data.educoder.net"}' | |||
| # des = OpenSSL::Cipher::Cipher.new('aes-256-ctr') | |||
| des = OpenSSL::Cipher.new('AES-256-CBC') | |||
| des.encrypt | |||
| # des.padding = | |||
| des.key = key | |||
| des.iv = "5183666c72eec9e4" | |||
| result = des.update(des_text) | |||
| result << des.final | |||
| Base64.strict_encode64 result | |||
| end | |||
| end | |||
| @@ -1,6 +1,6 @@ | |||
| module CustomRegexp | |||
| PHONE = /1\d{10}/ | |||
| EMAIL = /\A[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+\z/ | |||
| EMAIL = /\A[a-zA-Z0-9]+([._\-\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+\z/ | |||
| LOGIN = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]{4,15}\z/ #只含有数字、字母、下划线不能以下划线开头和结尾 | |||
| LASTNAME = /\A[a-zA-Z0-9\u4e00-\u9fa5]+\z/ | |||
| NICKNAME = /\A[\u4e00-\u9fa5_a-zA-Z0-9]+\z/ | |||
| @@ -69,7 +69,6 @@ class Issue < ApplicationRecord | |||
| has_many :issue_tags, through: :issue_tags_relates | |||
| has_many :issue_times, dependent: :destroy | |||
| has_many :issue_depends, dependent: :destroy | |||
| has_many :reviews, dependent: :destroy | |||
| scope :issue_includes, ->{includes(:user)} | |||
| scope :issue_many_includes, ->{includes(journals: :user)} | |||
| scope :issue_issue, ->{where(issue_classify: [nil,"issue"])} | |||
| @@ -13,6 +13,15 @@ | |||
| # comments_count :integer default("0") | |||
| # reply_id :integer | |||
| # review_id :integer | |||
| # commit_id :string(255) | |||
| # diff :text(4294967295) | |||
| # line_code :string(255) | |||
| # path :string(255) | |||
| # state :integer default("0") | |||
| # resolve_at :datetime | |||
| # resolveer_id :integer | |||
| # need_respond :boolean default("0") | |||
| # updated_on :datetime | |||
| # | |||
| # Indexes | |||
| # | |||
| @@ -24,8 +33,13 @@ | |||
| # | |||
| class Journal < ApplicationRecord | |||
| serialize :diff, JSON | |||
| alias_attribute :note, :notes | |||
| belongs_to :user | |||
| belongs_to :issue, foreign_key: :journalized_id, :touch => true | |||
| belongs_to :issue, foreign_key: :journalized_id, :touch => true, optional: true | |||
| belongs_to :journalized, polymorphic: true | |||
| belongs_to :review, optional: true | |||
| belongs_to :resolveer, class_name: 'User', foreign_key: :resolveer_id, optional: true | |||
| has_many :journal_details, :dependent => :delete_all | |||
| has_many :attachments, as: :container, dependent: :destroy | |||
| @@ -33,6 +47,7 @@ class Journal < ApplicationRecord | |||
| scope :parent_journals, ->{where(parent_id: nil)} | |||
| scope :children_journals, lambda{|journal_id| where(parent_id: journal_id)} | |||
| enum state: {opened: 0, resolved: 1, disabled: 2} | |||
| def is_journal_detail? | |||
| self.notes.blank? && self.journal_details.present? | |||
| @@ -0,0 +1,5 @@ | |||
| class MarkFile < ApplicationRecord | |||
| belongs_to :pull_request | |||
| end | |||
| @@ -0,0 +1,28 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: ob_repository_syncs | |||
| # | |||
| # id :integer not null, primary key | |||
| # project_id :integer | |||
| # user_id :integer | |||
| # name :string(255) | |||
| # github_address :string(255) | |||
| # gitee_address :string(255) | |||
| # github_token :string(255) | |||
| # gitee_token :string(255) | |||
| # sync_id :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_ob_repository_syncs_on_project_id (project_id) | |||
| # index_ob_repository_syncs_on_user_id (user_id) | |||
| # | |||
| class ObRepositorySync < ApplicationRecord | |||
| belongs_to :project | |||
| belongs_to :user | |||
| has_many :ob_repository_sync_jobs, dependent: :destroy | |||
| end | |||
| @@ -0,0 +1,24 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: ob_repository_sync_jobs | |||
| # | |||
| # id :integer not null, primary key | |||
| # ob_repository_sync_id :integer | |||
| # github_branch :string(255) | |||
| # gitee_branch :string(255) | |||
| # gitlink_branch :string(255) | |||
| # job_type :string(255) | |||
| # base :string(255) | |||
| # job_id :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_ob_repository_sync_jobs_on_ob_repository_sync_id (ob_repository_sync_id) | |||
| # | |||
| class ObRepositorySyncJob < ApplicationRecord | |||
| belongs_to :ob_repository_sync | |||
| end | |||
| @@ -32,12 +32,18 @@ class PullRequest < ApplicationRecord | |||
| belongs_to :issue | |||
| belongs_to :user | |||
| belongs_to :project, counter_cache: true, touch: true | |||
| # belongs_to :fork_project, foreign_key: :fork_project_id | |||
| belongs_to :fork_project, class_name: 'Project', foreign_key: :fork_project_id, optional: true | |||
| has_many :pull_request_assigns, foreign_key: :pull_request_id | |||
| has_many :pull_request_tags, foreign_key: :pull_request_id | |||
| has_many :project_trends, as: :trend, dependent: :destroy | |||
| has_many :attachments, as: :container, dependent: :destroy | |||
| has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_id, class_name: 'Gitea::Pull' | |||
| has_many :journals, :as => :journalized, :dependent => :destroy | |||
| has_many :journal_details, through: :journals | |||
| has_many :reviews, dependent: :destroy | |||
| has_many :pull_requests_reviewers, dependent: :destroy | |||
| has_many :reviewers, through: :pull_requests_reviewers | |||
| has_many :mark_files, dependent: :destroy | |||
| scope :merged_and_closed, ->{where.not(status: 0)} | |||
| scope :opening, -> {where(status: 0)} | |||
| @@ -0,0 +1,21 @@ | |||
| # == Schema Information | |||
| # | |||
| # Table name: pull_requests_reviewers | |||
| # | |||
| # id :integer not null, primary key | |||
| # pull_request_id :integer | |||
| # reviewer_id :integer | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_pull_requests_reviewers_on_pull_request_id (pull_request_id) | |||
| # index_pull_requests_reviewers_on_reviewer_id (reviewer_id) | |||
| # | |||
| class PullRequestsReviewer < ApplicationRecord | |||
| belongs_to :pull_request | |||
| belongs_to :reviewers, class_name: 'User', foreign_key: :reviewer_id | |||
| end | |||
| @@ -49,7 +49,7 @@ class Repository < ApplicationRecord | |||
| end | |||
| def url | |||
| self['url'].blank? ? "#{Rails.application.config_for(:configuration)['platform_url']}/#{self.owner&.login}/#{self.identifier}.git" : self['url'] | |||
| self['url'].blank? ? "#{Gitea.gitea_config[:domain]}/#{self.owner&.login}/#{self.identifier}.git" : self['url'] | |||
| end | |||
| # with repository is mirror | |||
| @@ -2,24 +2,24 @@ | |||
| # | |||
| # Table name: reviews | |||
| # | |||
| # id :integer not null, primary key | |||
| # issue_id :integer | |||
| # reviewer_id :integer | |||
| # content :text(65535) | |||
| # commit_id :string(255) | |||
| # status :integer default("0") | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # id :integer not null, primary key | |||
| # reviewer_id :integer | |||
| # content :text(65535) | |||
| # commit_id :string(255) | |||
| # status :integer default("0") | |||
| # created_at :datetime not null | |||
| # updated_at :datetime not null | |||
| # pull_request_id :integer | |||
| # | |||
| # Indexes | |||
| # | |||
| # index_reviews_on_issue_id (issue_id) | |||
| # index_reviews_on_reviewer_id (reviewer_id) | |||
| # index_reviews_on_pull_request_id (pull_request_id) | |||
| # index_reviews_on_reviewer_id (reviewer_id) | |||
| # | |||
| class Review < ApplicationRecord | |||
| belongs_to :issue | |||
| belongs_to :pull_request | |||
| belongs_to :reviewer, class_name: 'User', foreign_key: :reviewer_id | |||
| has_one :journal, dependent: :destroy | |||
| @@ -13,7 +13,6 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService | |||
| def initialize(project, params, token=nil) | |||
| puts params | |||
| @project = project | |||
| @owner = project&.owner.login | |||
| @repo = project&.identifier | |||
| @@ -21,11 +20,11 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService | |||
| @files = params[:files] | |||
| @author_email = params[:author_email] | |||
| @author_name = params[:author_name] | |||
| @author_timeunix = params[:author_timeunix] | |||
| @author_timeunix = params[:author_timeunix] || Time.now.to_i | |||
| @branch = params[:branch] | |||
| @committer_email = params[:committer_email] | |||
| @committer_name = params[:committer_name] | |||
| @committer_timeunix = params[:committer_timeunix] | |||
| @committer_timeunix = params[:committer_timeunix] || Time.now.to_i | |||
| @message = params[:message] | |||
| @new_branch = params[:new_branch] | |||
| end | |||
| @@ -63,6 +62,7 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService | |||
| committer: Time.at(committer_timeunix.to_i) | |||
| }, | |||
| message: message, | |||
| branch: branch, | |||
| new_branch: new_branch, | |||
| signoff: false | |||
| } | |||
| @@ -77,15 +77,16 @@ class Api::V1::Projects::Contents::BatchCreateService < ApplicationService | |||
| end | |||
| def excute_data_to_gitea | |||
| puts request_body.to_json | |||
| @gitea_data = $gitea_client.post_repos_contents_batch_by_owner_repo(owner, repo, {body: request_body.to_json, query: request_params}) rescue nil | |||
| raise Error, '创建文件失败!' unless @gitea_data.is_a?(Hash) | |||
| raise Error, '提交文件失败!' unless @gitea_data.is_a?(Hash) | |||
| end | |||
| def check_branch_exist | |||
| result = $gitea_client.get_repos_branch_name_set_by_owner_repo(owner, repo, {query: request_params} ) rescue nil | |||
| raise Error, '查询分支名称失败!' unless result.is_a?(Hash) | |||
| raise Error, '分支不存在!' unless result['branch_name'].include?(branch) | |||
| raise Error, '分支已存在!' if result['branch_name'].include?(new_branch) && new_branch.nil? | |||
| raise Error, '分支已存在!' if result['branch_name'].include?(new_branch) && !new_branch.nil? | |||
| end | |||
| end | |||
| @@ -0,0 +1,32 @@ | |||
| class Api::V1::Projects::Pulls::GetService < ApplicationService | |||
| attr_reader :project, :pull_request, :owner, :repo, :index, :token | |||
| attr_accessor :gitea_data | |||
| def initialize(project, pull_request, token = nil) | |||
| @project = project | |||
| @pull_request = pull_request | |||
| @owner = project&.owner.login | |||
| @repo = project&.identifier | |||
| @index = pull_request.gitea_number | |||
| @token = token | |||
| end | |||
| def call | |||
| load_gitea_data | |||
| gitea_data | |||
| end | |||
| private | |||
| def request_params | |||
| { | |||
| access_token: token | |||
| } | |||
| end | |||
| def load_gitea_data | |||
| @gitea_data = $gitea_client.get_repos_pulls_by_owner_repo_index(owner, repo, index, {query: request_params}) | |||
| # raise Error, '获取合并请求失败!' unless @gitea_data.is_a?(Hash) | |||
| end | |||
| end | |||
| @@ -0,0 +1,48 @@ | |||
| class Api::V1::Projects::Pulls::Journals::CreateService < ApplicationService | |||
| include ActiveModel::Model | |||
| attr_reader :project, :pull_request, :issue, :parent_id, :line_code, :note, :commit_id, :path, :type, :diff, :review_id, :user | |||
| attr_accessor :journal | |||
| validates :type, inclusion: {in: %w(comment problem), message: '请输入正确的Type'} | |||
| def initialize(project, pull_request, params, user) | |||
| @project = project | |||
| @pull_request = pull_request | |||
| @issue = pull_request&.issue | |||
| @parent_id = params[:parent_id] | |||
| @line_code = params[:line_code] | |||
| @note = params[:note] | |||
| @commit_id = params[:commit_id] | |||
| @path = params[:path] | |||
| @type = params[:type] | |||
| @diff = params[:diff] | |||
| @review_id = params[:review_id] | |||
| @user = user | |||
| end | |||
| def call | |||
| raise Error, errors.full_messages.join(", ") unless valid? | |||
| check_review_is_exists | |||
| if type == 'problem' | |||
| create_problem_journal | |||
| else | |||
| create_comment_journal | |||
| end | |||
| journal | |||
| end | |||
| private | |||
| def create_comment_journal | |||
| @journal = pull_request.journals.create!(user_id: user&.id, notes: note, parent_id: parent_id, review_id: review_id, commit_id: commit_id, diff: diff, line_code: line_code, path: path) | |||
| end | |||
| def check_review_is_exists | |||
| raise Error, '合并请求审查不存在!' unless @pull_request.reviews.exists?(review_id) | |||
| end | |||
| def create_problem_journal | |||
| @journal = pull_request.journals.create!(user_id: user&.id, notes: note, parent_id: parent_id, review_id: review_id, commit_id: commit_id, diff: diff, line_code: line_code, path: path, need_respond: true) | |||
| end | |||
| end | |||
| @@ -0,0 +1,51 @@ | |||
| class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService | |||
| include ActiveModel::Model | |||
| attr_reader :project, :pull_request, :keyword, :review_id, :need_respond, :state, :parent_id, :sort_by, :sort_direction, :user | |||
| attr_accessor :queried_journals | |||
| validates :sort_by, inclusion: {in: Journal.column_names, message: '请输入正确的SortBy'} | |||
| validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'} | |||
| validates :need_respond, inclusion: {in: [true, false], message: '请输入正确的NeedRespond'}, allow_nil: true | |||
| validates :state, inclusion: {in: %w(opened resolved disabled)}, allow_nil: true | |||
| def initialize(project, pull_request, params, user) | |||
| @project = project | |||
| @pull_request = pull_request | |||
| @keyword = params[:keyword] | |||
| @review_id = params[:review_id] | |||
| @need_respond = ActiveModel::Type::Boolean.new.cast(params[:need_respond]) | |||
| @state = params[:state] | |||
| @parent_id = params[:parent_id] | |||
| @sort_by = params[:sort_by] || 'created_on' | |||
| @sort_direction = params[:sort_direction] || 'asc' | |||
| @user = user | |||
| end | |||
| def call | |||
| raise Error, errors.full_messages.join(",") unless valid? | |||
| journal_query_data | |||
| queried_journals | |||
| end | |||
| private | |||
| def journal_query_data | |||
| journals = @pull_request.journals | |||
| if parent_id.present? | |||
| journals = journals.where(parent_id: parent_id) | |||
| else | |||
| journals = journals.parent_journals | |||
| end | |||
| journals = journals.where(review_id: review_id) if review_id.present? | |||
| journals = journals.where(need_respond: need_respond) if need_respond.present? | |||
| journals = journals.where(state: state) if state.present? | |||
| q = journals.ransack(notes_cont: keyword) | |||
| scope = q.result.includes(:user, :resolveer, review: [:reviewer, pull_request: :issue]) | |||
| scope = scope.order("journals.#{sort_by} #{sort_direction}") | |||
| @queried_journals = scope | |||
| end | |||
| end | |||
| @@ -0,0 +1,38 @@ | |||
| class Api::V1::Projects::Pulls::Journals::UpdateService < ApplicationService | |||
| include ActiveModel::Model | |||
| attr_reader :project, :pull_request, :journal, :note, :commit_id, :state, :user | |||
| attr_accessor :updated_journal | |||
| validates :state, inclusion: {in: %w(opened resolved disabled)} | |||
| def initialize(project, pull_request, journal, params, user) | |||
| @project = project | |||
| @pull_request = pull_request | |||
| @journal = journal | |||
| @note = params[:note] | |||
| @commit_id = params[:commit_id] | |||
| @state = params[:state] | |||
| @user = user | |||
| end | |||
| def call | |||
| raise Error, errors.full_messages.join(", ") unless valid? | |||
| update_journal | |||
| updated_journal | |||
| end | |||
| private | |||
| def update_journal | |||
| journal.attributes = {notes: note, commit_id: commit_id, state: state} | |||
| if state == 'resolved' | |||
| journal.resolve_at = Time.now | |||
| journal.resolveer_id = user.id | |||
| end | |||
| return Error, '保存评论失败!' unless journal.save | |||
| @updated_journal = journal.reload | |||
| end | |||
| end | |||
| @@ -0,0 +1,48 @@ | |||
| class Api::V1::Projects::Pulls::ListService < ApplicationService | |||
| include ActiveModel::Model | |||
| attr_reader :project, :keyword, :status, :priority_id, :issue_tag_id, :version_id, :reviewer_id, :assign_user_id, :sort_by, :sort_direction | |||
| attr_accessor :queried_pull_requests | |||
| validates :status, inclusion: {in: [0, 1, 2], message: "请输入正确的Status"}, allow_nil: true | |||
| validates :sort_by, inclusion: {in: PullRequest.column_names, message: '请输入正确的SortBy'} | |||
| validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'} | |||
| def initialize(project, params={}) | |||
| @project = project | |||
| @keyword = params[:keyword] | |||
| @status = params[:status].present? ? params[:status].to_i : nil | |||
| @priority_id = params[:priority_id] | |||
| @issue_tag_id = params[:issue_tag_id] | |||
| @version_id = params[:version_id] | |||
| @reviewer_id = params[:reviewer_id] | |||
| @assign_user_id = params[:assign_user_id] | |||
| @sort_by = params[:sort_by] || 'created_at' | |||
| @sort_direction = params[:sort_direction] || 'desc' | |||
| end | |||
| def call | |||
| raise Error, errors.full_messages.join(",") unless valid? | |||
| pull_request_query_data | |||
| queried_pull_requests | |||
| end | |||
| private | |||
| def pull_request_query_data | |||
| pull_requests = @project.pull_requests | |||
| pull_requests = pull_requests.where(status: status) if status.present? | |||
| pull_requests = pull_requests.where(issues: {priority_id: priority_id}) if priority_id.present? | |||
| pull_requests = pull_requests.where(issue_tags: {id: issue_tag_id}) if issue_tag_id.present? | |||
| pull_requests = pull_requests.where(issues: {fixed_version_id: version_id}) if version_id.present? | |||
| pull_requests = pull_requests.where(users: {id: reviewer_id}) if reviewer_id.present? | |||
| pull_requests = pull_requests.where(issues: {assigned_to_id: assign_user_id}) if assign_user_id.present? | |||
| q = pull_requests.ransack(title_or_body_cont: keyword) | |||
| scope = q.result.includes(:fork_project, :journals, :reviews, :reviewers, issue: [:journals, :priority, :version, :issue_tags]) | |||
| scope = scope.order("pull_requests.#{sort_by} #{sort_direction}") | |||
| @queried_pull_requests = scope | |||
| end | |||
| end | |||
| @@ -1,4 +1,4 @@ | |||
| class Api::V1::Projects::PullRequests::Reviews::CreateService < ApplicationService | |||
| class Api::V1::Projects::Pulls::Reviews::CreateService < ApplicationService | |||
| include ActiveModel::Model | |||
| attr_reader :project, :pull_request, :issue, :status, :commit_id, :content, :current_user | |||
| @@ -20,21 +20,18 @@ class Api::V1::Projects::PullRequests::Reviews::CreateService < ApplicationServi | |||
| raise Error, errors.full_messages.join(", ") unless valid? | |||
| ActiveRecord::Base.transaction do | |||
| create_review | |||
| create_journal | |||
| # create_journal | |||
| end | |||
| return @journal, @review | |||
| rescue | |||
| raise Error, '服务器错误,请联系系统管理员!' | |||
| @review | |||
| # rescue | |||
| # raise Error, '服务器错误,请联系系统管理员!' | |||
| end | |||
| private | |||
| def create_review | |||
| @review = issue.reviews.create!(status: status, content: content, commit_id: commit_id, reviewer_id: @current_user.id) | |||
| @review = pull_request.reviews.create!(status: status, content: content, commit_id: commit_id, reviewer_id: @current_user.id) | |||
| end | |||
| def create_journal | |||
| @journal = issue.journals.create!(notes: content, user_id: @current_user.id, review_id: @review.id) | |||
| end | |||
| end | |||
| @@ -0,0 +1,35 @@ | |||
| class Api::V1::Projects::Pulls::Versions::GetDiffService < ApplicationService | |||
| attr_reader :project, :pull_request, :version_id, :owner, :repo, :index, :filepath, :token | |||
| attr_accessor :gitea_data | |||
| def initialize(project, pull_request, version_id, params, token=nil) | |||
| @project = project | |||
| @pull_request = pull_request | |||
| @version_id = version_id | |||
| @owner = project&.owner.login | |||
| @repo = project&.identifier | |||
| @index = pull_request.gitea_number | |||
| @filepath = params[:filepath] | |||
| @token = token | |||
| end | |||
| def call | |||
| load_gitea_data | |||
| gitea_data | |||
| end | |||
| private | |||
| def request_params | |||
| params = { | |||
| access_token: token | |||
| } | |||
| params.merge!(filepath: filepath) if filepath.present? | |||
| end | |||
| def load_gitea_data | |||
| @gitea_data = $gitea_client.get_repos_pulls_versions_diff_by_owner_repo_index_version_id(owner, repo, index, version_id, {query: request_params}) | |||
| raise Error, '获取合并请求版本diff失败!' unless @gitea_data.is_a?(Hash) | |||
| end | |||
| end | |||
| @@ -0,0 +1,36 @@ | |||
| class Api::V1::Projects::Pulls::Versions::ListService < ApplicationService | |||
| attr_reader :project, :pull_request, :token, :owner, :repo, :index, :page, :limit | |||
| attr_accessor :gitea_data | |||
| def initialize(project, pull_request, params, token = nil) | |||
| @project = project | |||
| @pull_request = pull_request | |||
| @owner = project&.owner.login | |||
| @repo = project&.identifier | |||
| @page = params[:page] || 1 | |||
| @limit = params[:limit] || 15 | |||
| @index = pull_request.gitea_number | |||
| @token = token | |||
| end | |||
| def call | |||
| load_gitea_data | |||
| gitea_data | |||
| end | |||
| private | |||
| def request_params | |||
| { | |||
| access_token: token, | |||
| page: page, | |||
| limit: limit | |||
| } | |||
| end | |||
| def load_gitea_data | |||
| @gitea_data = $gitea_client.get_repos_pulls_versions_by_owner_repo_index(owner, repo, index, {query: request_params}) | |||
| raise Error, '获取合并请求版本失败!' unless @gitea_data.is_a?(Hash) | |||
| end | |||
| end | |||
| @@ -13,7 +13,7 @@ class Api::V1::Users::Projects::ListService < ApplicationService | |||
| def initialize(observe_user, params, current_user=nil) | |||
| @observe_user = observe_user | |||
| @category = params[:category] || 'all' | |||
| @is_public = params[:is_public] | |||
| @is_public = ActiveModel::Type::Boolean.new.cast(params[:is_public]) | |||
| @project_type = params[:project_type] | |||
| @sort_by = params[:sort_by] || 'updated_on' | |||
| @sort_direction = params[:sort_direction] || 'desc' | |||
| @@ -10,7 +10,7 @@ class Gitea::Repository::Languages::ListService < Gitea::ClientService | |||
| def initialize(owner, repo, token) | |||
| @owner = owner | |||
| @repo = repo | |||
| @args = token | |||
| @token = token | |||
| end | |||
| def call | |||
| @@ -15,6 +15,7 @@ class Issues::ListQueryService < ApplicationService | |||
| end_time = params[:due_date] | |||
| issues = all_issues.issue_index_includes | |||
| issues = issues.includes(pull_request: :reviewers) | |||
| if status_type.to_s == "2" #表示关闭中的 | |||
| issues = issues.where(status_id: 5) | |||
| elsif status_type.to_s == "1" | |||
| @@ -0,0 +1,168 @@ | |||
| class ObRepositorySync::ApiService < ApplicationService | |||
| attr_reader :project_name | |||
| def initialize(project_name) | |||
| @project_name = project_name | |||
| end | |||
| def call | |||
| true | |||
| end | |||
| def create_projects(params = {}) | |||
| projects_body = { | |||
| "name": "#{@project_name}", | |||
| "github_address": "#{params[:github_address]}", | |||
| "gitee_address": "#{params[:gitee_address]}", | |||
| "github_token": "#{params[:github_token]}", | |||
| "gitee_token": "#{params[:gitee_token]}", | |||
| "gitlink_address": "#{params[:gitlink_address]}", | |||
| "gitlink_token": "#{params[:gitlink_token]}" | |||
| } | |||
| url = URI("#{domain}/cerobot/projects") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Post.new(url) | |||
| request["Content-Type"] = "application/json" | |||
| request.body = JSON.dump(projects_body) | |||
| response = http.request(request) | |||
| # Rails.logger.info "cerobot/projects response.read_body======#{response.read_body}" | |||
| res = JSON.parse(response.body) | |||
| res | |||
| end | |||
| def delete_project sync_id | |||
| url = URI("#{domain}/cerobot/projects?id=#{sync_id}") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Delete.new(url) | |||
| request["Content-Type"] = "application/json" | |||
| response = http.request(request) | |||
| # Rails.logger.info "delete project response.read_body======#{response.read_body}" | |||
| res = JSON.parse(response.body) | |||
| res | |||
| end | |||
| def get_projects_jobs | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Get.new(url) | |||
| request["Content-Type"] = "application/json" | |||
| response = http.request(request) | |||
| Rails.logger.info "cerobot/projects response.read_body======#{response.read_body}" | |||
| res = JSON.parse(response.body) | |||
| res | |||
| end | |||
| def create_projects_jobs(params = {}) | |||
| job_body = { | |||
| "github_branch": "#{params[:github_branch]}", | |||
| "gitee_branch": "#{params[:gitee_branch]}", | |||
| "gitlink_branch": "#{params[:gitlink_branch]}", | |||
| "type": "#{params[:type]}", | |||
| "base": "#{params[:base]}" | |||
| } | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Post.new(url) | |||
| request["Content-Type"] = "application/json" | |||
| request.body = JSON.dump(job_body) | |||
| response = http.request(request) | |||
| Rails.logger.info "cerobot/projects response.read_body======#{response.read_body}" | |||
| res = JSON.parse(response.body) | |||
| res | |||
| end | |||
| def delete_job job_id | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs?id=#{job_id}") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Delete.new(url) | |||
| request["Content-Type"] = "application/json" | |||
| response = http.request(request) | |||
| Rails.logger.info "delete job response.read_body======#{response.read_body}" | |||
| res = JSON.parse(response.body) | |||
| res | |||
| end | |||
| def start_job job_id | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs/#{job_id}/start") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Put.new(url) | |||
| request["Content-Type"] = "application/json" | |||
| response = http.request(request) | |||
| Rails.logger.info "start job response.read_body======#{response.read_body}" | |||
| res = JSON.parse(response.body) | |||
| res | |||
| end | |||
| def stop_job job_id | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs/#{job_id}/stop") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Put.new(url) | |||
| request["Content-Type"] = "application/json" | |||
| response = http.request(request) | |||
| Rails.logger.info "stop job response.read_body======#{response.read_body}" | |||
| res = JSON.parse(response.body) | |||
| res | |||
| end | |||
| def set_commit job_id, commit_id | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs/#{job_id}/set_commit?commit=#{commit_id}") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Put.new(url) | |||
| response = http.request(request) | |||
| Rails.logger.info "set_commit job response.read_body======#{response.read_body}" | |||
| res = JSON.parse(response.body) | |||
| res | |||
| end | |||
| def job_logs job_id | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs/#{job_id}/logs") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Get.new(url) | |||
| request["Content-Type"] = "application/json" | |||
| response = http.request(request) | |||
| Rails.logger.info "set_commit job response.read_body======#{response.read_body}" | |||
| res = JSON.parse(response.body) | |||
| if res["code"].to_s == "200" | |||
| res["data"] | |||
| else | |||
| [] | |||
| end | |||
| end | |||
| def pull_requests | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/pullrequests") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Get.new(url) | |||
| request["Content-Type"] = "application/json" | |||
| response = http.request(request) | |||
| Rails.logger.info "pull_requests response.read_body======#{response.read_body}" | |||
| res = JSON.parse(response.body) | |||
| if res["code"].to_s == "200" | |||
| res["data"] | |||
| else | |||
| [] | |||
| end | |||
| end | |||
| def pull_requests_sync | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/pullrequests/sync") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Get.new(url) | |||
| request["Content-Type"] = "application/json" | |||
| response = http.request(request) | |||
| Rails.logger.info "pull_requests_sync response.read_body======#{response.read_body}" | |||
| res = JSON.parse(response.body) | |||
| if res["code"].to_s == "200" | |||
| res["data"] | |||
| else | |||
| [] | |||
| end | |||
| end | |||
| def domain | |||
| EduSetting.get("ob_repository_sync_api_domain") || "http://106.75.110.152:50087" | |||
| end | |||
| end | |||
| @@ -8,8 +8,11 @@ class Trace::ClientService < ApplicationService | |||
| def authed_post(token, url, params={}) | |||
| puts "[trace][POST] request params: #{params}" | |||
| puts "[trace][POST] request token: #{token}" | |||
| conn.headers['Authorization'] = token | |||
| conn.post(full_url(url), params[:data]) | |||
| conn.post do |req| | |||
| req.url full_url(url, 'post') | |||
| req.headers['Authorization'] = token | |||
| req.body = params[:data].as_json | |||
| end | |||
| end | |||
| def http_authed_post(token, url, params={}) | |||
| @@ -55,8 +58,11 @@ class Trace::ClientService < ApplicationService | |||
| def authed_delete(token, url, params={}) | |||
| puts "[trace][DELETE] request params: #{params}" | |||
| puts "[trace][DELETE] request token: #{token}" | |||
| conn.headers['Authorization'] = token | |||
| conn.delete(full_url(url), params[:data]) | |||
| conn.delete do |req| | |||
| req.url full_url(url, 'delete') | |||
| req.headers['Authorization'] = token | |||
| req.body = params[:data].as_json | |||
| end | |||
| end | |||
| def patch(url, params={}) | |||
| @@ -67,8 +73,11 @@ class Trace::ClientService < ApplicationService | |||
| def authed_patch(token, url, params={}) | |||
| puts "[trace][PATCH] request params: #{params}" | |||
| puts "[trace][PATCH] request token: #{token}" | |||
| conn.headers['Authorization'] = token | |||
| conn.patch(full_url(url), params[:data]) | |||
| conn.patch do |req| | |||
| req.url full_url(url, 'patch') | |||
| req.headers['Authorization'] = token | |||
| req.body = params[:data].as_json | |||
| end | |||
| end | |||
| def put(url, params={}) | |||
| @@ -79,8 +88,11 @@ class Trace::ClientService < ApplicationService | |||
| def authed_put(token, url, params={}) | |||
| puts "[trace][PUT] request params: #{params}" | |||
| puts "[trace][PUT] request token: #{token}" | |||
| conn.headers['Authorization'] = token | |||
| conn.put(full_url(url), params[:data]) | |||
| conn.put do |req| | |||
| req.url full_url(url, 'put') | |||
| req.headers['Authorization'] = token | |||
| req.body = params[:data].as_json | |||
| end | |||
| end | |||
| def conn | |||
| @@ -0,0 +1,35 @@ | |||
| json.name file['Name'] | |||
| json.oldname file['OldName'] | |||
| json.addition file['Addition'] | |||
| json.deletion file['Deletion'] | |||
| json.type file['Type'] | |||
| json.is_created file['IsCreated'] | |||
| json.is_deleted file['IsDeleted'] | |||
| json.is_bin file['IsBin'] | |||
| json.is_lfs_file file['IsLFSFile'] | |||
| json.is_renamed file['IsRenamed'] | |||
| json.is_ambiguous file['IsAmbiguous'] | |||
| json.is_submodule file['IsSubmodule'] | |||
| json.sections file['Sections'] do |section| | |||
| json.file_name section['FileName'] | |||
| json.name section['Name'] | |||
| json.lines section['Lines'] do |line| | |||
| json.left_index line['LeftIdx'] | |||
| json.right_index line['RightIdx'] | |||
| json.match line['Match'] | |||
| json.type line['Type'] | |||
| json.content line['Content'] | |||
| unless line['SectionInfo'].blank? | |||
| json.section_path line['SectionInfo']['Path'] | |||
| json.section_last_left_index line['SectionInfo']['LastLeftIdx'] | |||
| json.section_last_right_index line['SectionInfo']['LastRightIdx'] | |||
| json.section_left_index line['SectionInfo']['LeftIdx'] | |||
| json.section_right_index line['SectionInfo']['RightIdx'] | |||
| json.section_left_hunk_size line['SectionInfo']['LeftHunkSize'] | |||
| json.section_right_hunk_size line['SectionInfo']['RightHunkSize'] | |||
| end | |||
| end | |||
| end | |||
| json.is_incomplete file['IsIncomplete'] | |||
| json.is_incomplete_line_too_long file['IsIncompleteLineTooLong'] | |||
| json.is_protected file['IsProtected'] | |||
| @@ -3,12 +3,16 @@ json.commit do | |||
| json.authored_time render_unix_time(@result_object['commit']['author']['date']) | |||
| json.commited_time render_unix_time(@result_object['commit']['committer']['date']) | |||
| end | |||
| json.contents @result_object['contents'].each do |content| | |||
| json.name content['name'] | |||
| json.path content['path'] | |||
| json.sha content['sha'] | |||
| json.type content['type'] | |||
| json.size content['size'] | |||
| json.encoding content['encoding'] | |||
| json.content content['content'] | |||
| if @result_object['contents'].is_a?(Array) | |||
| json.contents @result_object['contents'].each do |content| | |||
| json.name content['name'] | |||
| json.path content['path'] | |||
| json.sha content['sha'] | |||
| json.type content['type'] | |||
| json.size content['size'] | |||
| json.encoding content['encoding'] | |||
| json.content content['content'] | |||
| end | |||
| else | |||
| json.contents [] | |||
| end | |||
| @@ -0,0 +1,26 @@ | |||
| json.(pull, :id, :title, :body, :head, :base, :is_original) | |||
| json.index pull.gitea_number | |||
| json.status pull.status == 1 ? "merged" : (pull.status == 2 ? "closed" : "open") | |||
| fork_project = pull&.fork_project | |||
| if fork_project.present? | |||
| json.fork_project do | |||
| json.(fork_project, :id, :identifier) | |||
| json.login fork_project&.owner&.login | |||
| end | |||
| end | |||
| issue = pull&.issue | |||
| json.issue do | |||
| json.id issue&.id | |||
| json.author do | |||
| json.partial! '/api/v1/users/simple_user', user: issue&.user | |||
| end | |||
| json.priority issue&.priority.try(:name) | |||
| json.version issue&.version.try(:name) | |||
| json.journals_count issue.journals.count | |||
| json.issue_tags issue.get_issue_tags | |||
| end | |||
| json.reviewers pull.reviewers.pluck(:login) | |||
| json.journals_count pull.journals.count | |||
| @@ -0,0 +1,21 @@ | |||
| json.(journal, :id, :note, :commit_id, :line_code, :path, :diff, :need_respond, :state, :parent_id) | |||
| json.user do | |||
| json.partial! 'api/v1/users/simple_user', user: journal.user | |||
| end | |||
| json.review do | |||
| if journal.review.present? | |||
| json.partial! 'api/v1/projects/pulls/reviews/simple_detail', review: journal.review | |||
| else | |||
| json.nil! | |||
| end | |||
| end | |||
| json.resolveer do | |||
| if journal.resolveer.present? | |||
| json.partial! 'api/v1/users/simple_user', user: journal.resolveer | |||
| else | |||
| json.nil! | |||
| end | |||
| end | |||
| json.resolve_at format_time(journal.resolve_at) | |||
| json.created_at format_time(journal.created_on) | |||
| json.updated_at format_time(journal.updated_on) | |||
| @@ -0,0 +1 @@ | |||
| json.partial! 'api/v1/projects/pulls/journals/simple_detail', journal: @journal | |||
| @@ -0,0 +1,4 @@ | |||
| json.total_count @journals.total_count | |||
| json.journals @journals.each do |journal| | |||
| json.partial! 'api/v1/projects/pulls/journals/simple_detail', journal: journal | |||
| end | |||
| @@ -0,0 +1 @@ | |||
| json.partial! 'api/v1/projects/pulls/journals/simple_detail', journal: @journal | |||
| @@ -0,0 +1,4 @@ | |||
| json.total_count @pulls.total_count | |||
| json.pulls @pulls.each do |pull| | |||
| json.partial! 'api/v1/projects/pulls/simple_detail', pull: pull | |||
| end | |||
| @@ -0,0 +1,30 @@ | |||
| json.partial! "api/v1/projects/pulls/simple_detail", pull: @pull_request | |||
| json.merge_base @result_object['merge_base'] | |||
| json.base_commit_sha @result_object['base']['sha'] | |||
| json.head_commit_sha @result_object['head']['sha'] | |||
| json.commit_num @result_object['commit_num'] | |||
| json.changed_files @result_object['changed_files'] | |||
| json.is_locked @result_object['is_locked'] | |||
| json.mergeable @result_object['mergeable'] # 是否能合并 | |||
| json.merged @result_object['merged'] | |||
| json.merged_at @result_object['merged_at'].nil? ? '' : render_unix_time( @result_object['merged_at']) | |||
| json.merge_commit_sha @result_object['merge_commit_sha'] | |||
| json.merge_by do | |||
| if @result_object['merged_by'] | |||
| json.partial! 'api/v1/users/commit_user', locals: { user: render_cache_commit_author(@result_object['merged_by']), name: @result_object['merged_by']['login'] } | |||
| else | |||
| json.nil! | |||
| end | |||
| end | |||
| json.last_review do | |||
| if @last_review.present? | |||
| json.(@last_review, :id, :commit_id, :content, :status) | |||
| json.created_at format_time(@last_review.created_at) | |||
| json.reviewer do | |||
| json.partial! "api/v1/users/simple_user", user: @last_review.reviewer | |||
| end | |||
| else | |||
| json.nil! | |||
| end | |||
| end | |||
| json.conflict_files @pull_request.conflict_files | |||
| @@ -0,0 +1,8 @@ | |||
| json.reviewer do | |||
| json.partial! "api/v1/users/simple_user", user: review.reviewer | |||
| end | |||
| json.pull_request do | |||
| json.partial! "api/v1/projects/pulls/simple_detail", pull: review.pull_request | |||
| end | |||
| json.(review, :id, :commit_id, :content, :status) | |||
| json.created_at format_time(review.created_at) | |||
| @@ -0,0 +1,8 @@ | |||
| json.reviewer do | |||
| json.partial! "api/v1/users/simple_user", user: @review.reviewer | |||
| end | |||
| json.pull_request do | |||
| json.partial! "api/v1/projects/pulls/simple_detail", pull: @review.pull_request | |||
| end | |||
| json.(@review, :id, :commit_id, :content, :status) | |||
| json.created_at format_time(@review.created_at) | |||
| @@ -0,0 +1,4 @@ | |||
| json.total_count @reviews.total_count | |||
| json.reviews @reviews.each do |review| | |||
| json.partial! 'api/v1/projects/pulls/reviews/simple_detail', review: review | |||
| end | |||
| @@ -0,0 +1,6 @@ | |||
| if @result_object.has_key?("NumFiles") | |||
| json.partial! "api/v1/projects/simple_gitea_diff_detail", diff: @result_object | |||
| else | |||
| json.partial! "api/v1/projects/simple_gitea_diff_file_detail", file: @result_object | |||
| end | |||
| @@ -0,0 +1,13 @@ | |||
| json.total_count @result_object[:total_data].to_i | |||
| json.versions @result_object[:data].each do |version| | |||
| json.id version['id'] | |||
| json.add_line_num version['add_line_num'] | |||
| json.del_line_num version['del_line_num'] | |||
| json.commits_count version['commits_count'] | |||
| json.files_count version['files_count'] | |||
| json.base_commit_sha version['base_commit_sha'] | |||
| json.head_commit_sha version['head_commit_sha'] | |||
| json.start_commit_sha version['start_commit_sha'] | |||
| json.created_time render_unix_time(version['created_at']) | |||
| json.updated_time render_unix_time(version['updated_at']) | |||
| end | |||
| @@ -0,0 +1,13 @@ | |||
| json.status 0 | |||
| json.message 'success' | |||
| json.count @files_result['NumFiles'] | |||
| json.files do | |||
| json.array! @files_result['Files'] do |file| | |||
| mark_file = @mark_files.select{|mark| mark.file_path.to_s == file['Name']}.first | |||
| json.file_path_sha Base64.strict_encode64(file['Name'].to_s) | |||
| json.name file['Name'] | |||
| json.mark_as_read mark_file.present? ? mark_file.mark_as_read : false | |||
| # json.updated_after_read mark_file.present? ? mark_file.updated_after_read : false | |||
| end | |||
| end | |||
| @@ -0,0 +1,7 @@ | |||
| <%if @error.present?%> | |||
| var alertDiv = $('<div class="alert alert-danger"><%= @error[:msg]%></div>') | |||
| $("#container").prepend(alertDiv) | |||
| setTimeout(function() { | |||
| $('.alert').remove(); | |||
| }, 3000); | |||
| <%end%> | |||
| @@ -0,0 +1,8 @@ | |||
| json.status 0 | |||
| json.message "success" | |||
| json.data do | |||
| if @ob_repository_sync | |||
| json.extract! @ob_repository_sync, :user_id, :name, :github_address, :gitee_address, :github_token, :gitee_token,:sync_id, :created_at, :updated_at | |||
| end | |||
| end | |||
| @@ -9,7 +9,7 @@ json.is_original pr.is_original | |||
| json.fork_project_id pr&.fork_project_id | |||
| json.fork_project_identifier pr&.fork_project&.identifier | |||
| json.fork_project_user pr&.fork_project&.owner.try(:login) | |||
| json.reviewers pr&.reviewers.pluck(:login) | |||
| json.id issue.id | |||
| json.name issue.subject | |||
| @@ -12,3 +12,4 @@ json.issue_tag_ids @issue&.issue_tags_value&.split(",") | |||
| json.commits_count @pull_request.commits_count | |||
| json.files_count @pull_request.files_count | |||
| json.comments_count @pull_request.comments_count | |||
| json.reviewers @pull_request.reviewers.pluck(:login) | |||
| @@ -24,7 +24,8 @@ json.issues do | |||
| json.fork_project_identifier pr&.fork_project&.identifier | |||
| json.fork_project_user pr&.fork_project&.owner.try(:login) | |||
| json.fork_project_user_name pr&.fork_project&.owner.try(:show_real_name) | |||
| json.reviewers pr.reviewers.pluck(:login) | |||
| json.id issue.id | |||
| json.name issue.subject | |||
| json.pr_time time_from_now(pr.status == 1 ? pr.updated_at : issue.updated_on) | |||
| @@ -30,6 +30,7 @@ json.pull_request do | |||
| json.create_user @pull_request&.user&.login | |||
| json.mergeable @gitea_pull["mergeable"] | |||
| json.state @gitea_pull["state"] | |||
| json.reviewers @pull_request.reviewers.pluck(:login) | |||
| end | |||
| json.issue do | |||
| @@ -556,7 +556,8 @@ Rails.application.routes.draw do | |||
| post :refuse_merge | |||
| get :files | |||
| get :commits | |||
| resources :reviews, only: [:create] | |||
| resources :reviews, only: [:create] | |||
| resources :mark_files, only: [:index, :create] | |||
| end | |||
| collection do | |||
| post :check_can_merge | |||
| @@ -583,6 +584,16 @@ Rails.application.routes.draw do | |||
| 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, :show, :create, :edit, :update, :destroy] | |||
| resources :ob_repository_syncs, :path => :synchronizes, only: [:index, :create] do | |||
| collection do | |||
| delete :delete | |||
| get :jobs | |||
| post :create_jobs | |||
| delete :delete_job | |||
| post :start_job | |||
| post :stop_job | |||
| end | |||
| end | |||
| scope module: :ci do | |||
| scope do | |||
| @@ -19,7 +19,16 @@ defaults format: :json do | |||
| # projects文件夹下的 | |||
| scope module: :projects do | |||
| resources :issues | |||
| resources :pull_requests | |||
| resources :pulls, module: 'pulls' do | |||
| resources :versions, only: [:index] do | |||
| member do | |||
| get :diff | |||
| end | |||
| end | |||
| resources :journals, except: [:show, :edit] | |||
| resources :reviews, only: [:index, :create] | |||
| end | |||
| resources :versions | |||
| resources :release_versions | |||
| resources :webhooks do | |||
| @@ -0,0 +1,15 @@ | |||
| class CreateObRepositorySyncs < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :ob_repository_syncs do |t| | |||
| t.references :project | |||
| t.references :user | |||
| t.string :name | |||
| t.string :github_address | |||
| t.string :gitee_address | |||
| t.string :github_token | |||
| t.string :gitee_token | |||
| t.integer :sync_id | |||
| t.timestamps | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,14 @@ | |||
| class CreateObRepositorySyncJobs < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :ob_repository_sync_jobs do |t| | |||
| t.references :ob_repository_sync | |||
| t.string :github_branch | |||
| t.string :gitee_branch | |||
| t.string :gitlink_branch | |||
| t.string :job_type | |||
| t.string :base | |||
| t.integer :job_id | |||
| t.timestamps | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,9 @@ | |||
| class CreatePullRequestsReviewers < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :pull_requests_reviewers do |t| | |||
| t.belongs_to :pull_request, index: true | |||
| t.belongs_to :reviewer, class_name: User, index:true | |||
| t.timestamps | |||
| end | |||
| end | |||
| end | |||
| @@ -0,0 +1,6 @@ | |||
| class ChangeReviewsReferenceToPullRequests < ActiveRecord::Migration[5.2] | |||
| def change | |||
| remove_reference :reviews, :issue | |||
| add_reference :reviews, :pull_request | |||
| end | |||
| end | |||
| @@ -0,0 +1,13 @@ | |||
| class AddLineCodeToJournals < ActiveRecord::Migration[5.2] | |||
| def change | |||
| add_column :journals, :commit_id, :string | |||
| add_column :journals, :diff, :text, :limit => 4294967295 | |||
| add_column :journals, :line_code, :string | |||
| add_column :journals, :path, :string | |||
| add_column :journals, :state, :integer, default: 0 | |||
| add_column :journals, :resolve_at, :datetime | |||
| add_column :journals, :resolveer_id, :integer, index: true | |||
| add_column :journals, :need_respond, :bool, default: false | |||
| add_column :journals, :updated_on, :datetime, index: true | |||
| end | |||
| end | |||
| @@ -0,0 +1,15 @@ | |||
| class CreateMarkFiles < ActiveRecord::Migration[5.2] | |||
| def change | |||
| create_table :mark_files do |t| | |||
| t.references :pull_request | |||
| t.integer :user_id | |||
| t.string :file_path_sha | |||
| t.string :file_path | |||
| t.boolean :mark_as_read, default: false | |||
| t.boolean :updated_after_read, default: false | |||
| t.timestamps | |||
| end | |||
| add_index :mark_files, :file_path_sha | |||
| end | |||
| end | |||
| @@ -0,0 +1,5 @@ | |||
| require 'rails_helper' | |||
| RSpec.describe PullRequestsReviewer, type: :model do | |||
| pending "add some examples to (or delete) #{__FILE__}" | |||
| end | |||