| @@ -7,12 +7,12 @@ class Admins::MessageTemplatesController < Admins::BaseController | |||
| end | |||
| def new | |||
| @message_template = MessageTemplate::CustomTip.new | |||
| @message_template = MessageTemplate.new | |||
| end | |||
| def create | |||
| @message_template = MessageTemplate::CustomTip.new(ignore_params) | |||
| def create | |||
| @message_template = MessageTemplate::CustomTip.new(message_template_params) | |||
| @message_template.type = "MessageTemplate::CustomTip" | |||
| if @message_template.save! | |||
| redirect_to admins_message_templates_path | |||
| flash[:success] = "创建消息模板成功" | |||
| @@ -47,7 +47,9 @@ class Admins::MessageTemplatesController < Admins::BaseController | |||
| private | |||
| def message_template_params | |||
| params.require(@message_template.type.split("::").join("_").underscore.to_sym).permit! | |||
| # type = @message_template.present? ? @message_template.type : "MessageTemplate::CustomTip" | |||
| # params.require(type.split("::").join("_").underscore.to_sym).permit! | |||
| params.require(:message_template).permit! | |||
| end | |||
| def get_template | |||
| @@ -1,8 +1,9 @@ | |||
| class Admins::Topic::BannersController < Admins::Topic::BaseController | |||
| before_action :find_banner, only: [:edit, :update, :destroy] | |||
| def index | |||
| def index | |||
| @banners = paginate(::Topic::Banner) | |||
| @banners = paginate(::Topic::Banner.where("title like ?", "%#{params[:search]}%")) if params[:search].present? | |||
| end | |||
| def new | |||
| @@ -40,6 +40,13 @@ class Api::V1::BaseController < ApplicationController | |||
| return render_forbidden if !current_user.admin? && !@project.operator?(current_user) | |||
| end | |||
| # 具有仓库的操作权限或者fork仓库的操作权限 | |||
| def require_operate_above_or_fork_project | |||
| @project = load_project | |||
| puts !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user)) | |||
| return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user)) | |||
| end | |||
| # 具有对仓库的访问权限 | |||
| def require_public_and_member_above | |||
| @project = load_project | |||
| @@ -1,13 +1,13 @@ | |||
| class Api::V1::Projects::ContentsController < Api::V1::BaseController | |||
| before_action :require_operate_above, only: [:batch] | |||
| before_action :require_operate_above_or_fork_project, only: [:batch] | |||
| def batch | |||
| @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 | |||
| @result_object = Api::V1::Projects::Contents::BatchCreateService.call(@project, @batch_content_params, @project.owner.gitea_token) | |||
| end | |||
| private | |||
| @@ -2,7 +2,7 @@ class Api::V1::Projects::Pulls::JournalsController < Api::V1::Projects::Pulls::B | |||
| def index | |||
| @journals = Api::V1::Projects::Pulls::Journals::ListService.call(@project, @pull_request, params, current_user) | |||
| @journals = kaminari_paginate(@journals) | |||
| @journals = @journals.limit(200) | |||
| end | |||
| def create | |||
| @@ -2,7 +2,8 @@ class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::Ba | |||
| def index | |||
| @reviews = @pull_request.reviews | |||
| @reviews = kaminari_paginate(@reviews) | |||
| @reviews = @reviews.where(status: params[:status]) if params[:status].present? | |||
| # @reviews = kaminari_paginate(@reviews) | |||
| end | |||
| before_action :require_reviewer, only: [:create] | |||
| @@ -13,7 +14,7 @@ class Api::V1::Projects::Pulls::ReviewsController < Api::V1::Projects::Pulls::Ba | |||
| private | |||
| def require_reviewer | |||
| return render_forbidden('您没有审查权限,请联系项目管理员') if !current_user.admin? && !@pull_request.reviewers.exists?(current_user.id) | |||
| return render_forbidden('您没有审查权限,请联系项目管理员') if !current_user.admin? && !@pull_request.reviewers.exists?(current_user.id) && !@project.manager?(current_user) | |||
| end | |||
| def review_params | |||
| @@ -5,11 +5,12 @@ class Api::V1::Projects::WebhooksController < Api::V1::BaseController | |||
| def index | |||
| # @result_object = Api::V1::Projects::Webhooks::ListService.call(@project, current_user&.gitea_token) | |||
| @webhooks = @project.webhooks | |||
| @webhooks = @webhooks.where(type: params[:type]) if params[:type].present? | |||
| @webhooks = kaminari_paginate(@webhooks) | |||
| end | |||
| def create | |||
| @result_object = Api::V1::Projects::Webhooks::CreateService.call(@project, webhook_params, current_user&.gitea_token) | |||
| @result_object = Api::V1::Projects::Webhooks::CreateService.call(@project, create_webhook_params, current_user&.gitea_token) | |||
| end | |||
| def show | |||
| @@ -44,6 +45,10 @@ class Api::V1::Projects::WebhooksController < Api::V1::BaseController | |||
| end | |||
| private | |||
| def create_webhook_params | |||
| params.require(:webhook).permit(:active, :branch_filter, :http_method, :url, :content_type, :secret, :type, events: []) | |||
| end | |||
| def webhook_params | |||
| params.require(:webhook).permit(:active, :branch_filter, :http_method, :url, :content_type, :secret, events: []) | |||
| end | |||
| @@ -619,7 +619,7 @@ class ApplicationController < ActionController::Base | |||
| def kaminari_paginate(relation) | |||
| limit = params[:limit] || params[:per_page] | |||
| limit = (limit.to_i.zero? || limit.to_i > 20) ? 20 : limit.to_i | |||
| limit = (limit.to_i.zero? || limit.to_i > 25) ? 25 : limit.to_i | |||
| page = params[:page].to_i.zero? ? 1 : params[:page].to_i | |||
| relation.page(page).per(limit) | |||
| @@ -15,6 +15,7 @@ class CommitLogsController < ApplicationController | |||
| owner = User.find_by(login: owner_name) | |||
| project = Project.where(identifier: repository_name).where(user_id: owner&.id)&.first | |||
| project = Project.where(identifier: repository_name).where(gpid: repository_id)&.first if project.blank? | |||
| project.update_column(:updated_on, Time.now) if project.present? | |||
| params[:commits].each do |commit| | |||
| commit_id = commit[:id] | |||
| message = commit[:message] | |||
| @@ -3,7 +3,7 @@ module RenderHelper | |||
| render json: { status: 0, message: 'success' }.merge(data) | |||
| end | |||
| def render_error(message = '') | |||
| def render_error(message = '', status = -1) | |||
| render json: { status: status, message: message } | |||
| end | |||
| @@ -4,26 +4,44 @@ class MarkFilesController < ApplicationController | |||
| 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) | |||
| @files_result = Gitea::PullRequest::FilesService.call(@owner.login, @project.identifier, @pull_request.gitea_number, current_user&.gitea_token, { "only-file-name": true }) | |||
| @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 | |||
| # 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 | |||
| tip_exception "参数错误" if params[:file_path_sha].blank? | |||
| file_path = Base64.strict_decode64(params[:file_path_sha].to_s) | |||
| mark_file = @pull_request.mark_files.find_or_initialize_by(file_path_sha: params[:file_path_sha]) | |||
| mark_file.file_path = file_path | |||
| mark_file.user_id = current_user.id | |||
| mark_file.mark_as_read = false | |||
| mark_file.save | |||
| render_ok | |||
| rescue Exception => e | |||
| tip_exception "参数解析错误" | |||
| end | |||
| def mark_file_as_read | |||
| tip_exception "参数错误" if params[:file_path_sha].blank? | |||
| file_path = Base64.strict_decode64(params[:file_path_sha].to_s) | |||
| mark_file = @pull_request.mark_files.find_or_initialize_by(file_path_sha: params[:file_path_sha]) | |||
| mark_file.file_path = file_path | |||
| mark_file.user_id = current_user.id | |||
| mark_file.mark_as_read = true | |||
| mark_file.save | |||
| render_ok | |||
| rescue Exception => e | |||
| tip_exception "参数解析错误" | |||
| end | |||
| private | |||
| @@ -26,6 +26,9 @@ class MembersController < ApplicationController | |||
| @total_count = scope.size | |||
| @members = paginate(scope) | |||
| if @project.owner.is_a?(Organization) && (params[:page].to_i == 1 || params[:page].blank?) && !@project.members.exists?(user_id: current_user.id) | |||
| @current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take | |||
| end | |||
| end | |||
| def remove | |||
| @@ -61,10 +64,13 @@ class MembersController < ApplicationController | |||
| end | |||
| def check_member_exists! | |||
| return render_error("user_id为#{params[:user_id]}的用户已经是项目成员") if member_exists? | |||
| @current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take | |||
| return render_error("user_id为#{params[:user_id]}的用户已经是项目成员") if member_exists? || (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) | |||
| end | |||
| def check_member_not_exists! | |||
| @current_user_header_team = Team.joins(:team_users, :team_projects).where(team_projects: {project_id: @project.id}, team_users: {user_id: current_user.id}).order(authorize: :desc).take | |||
| return render_error("用户为组织成员,请到组织下操作!") if (params[:user_id].to_i == current_user.id && @current_user_header_team.present?) && !member_exists? | |||
| return render_error("user_id为#{params[:user_id]}的用户还不是项目成员") unless member_exists? | |||
| end | |||
| @@ -13,7 +13,8 @@ class ObRepositorySyncsController < ApplicationController | |||
| 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 }) | |||
| domain = GiteaService.gitea_config[:domain] | |||
| project_params = params.merge({ "gitlink_address": "#{domain}/#{@project.owner&.login}/#{@project.identifier}.git" }) | |||
| res = service.create_projects(project_params) | |||
| tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200" | |||
| sync_id = res["data"]["id"] | |||
| @@ -23,7 +24,6 @@ class ObRepositorySyncsController < ApplicationController | |||
| 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 | |||
| @@ -34,20 +34,37 @@ class ObRepositorySyncsController < ApplicationController | |||
| 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" | |||
| tip_exception "删除失败: #{res["msg"]}" if res["code"].to_s != "200" | |||
| if res["code"].to_s == "200" | |||
| @ob_repository_sync.destroy! | |||
| end | |||
| render_ok | |||
| end | |||
| def jobs | |||
| tip_exception "该项目未创建同步任务" if @ob_repository_sync.blank? | |||
| page = params[:page] || 1 | |||
| limit = params[:limit] || 10 | |||
| service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) | |||
| res = service.get_projects_jobs | |||
| render_ok(count: res["data"]["total"], data: res["data"]["list"]) | |||
| source = "" | |||
| if params[:type] && params[:type].to_s.downcase == "github" | |||
| source = "github_branch" | |||
| elsif params[:type] && params[:type].to_s.downcase == "gitee" | |||
| source = "gitee_branch" | |||
| end | |||
| res = service.get_projects_jobs(source, page, limit) | |||
| data = res["data"]["list"] | |||
| render_ok(count: res["data"]["total"], data: data) | |||
| end | |||
| def create_jobs | |||
| tip_exception "必须配置一个分支" if params[:github_branch].blank? && params[:gitee_branch].blank? && params[:gitlink_branch].blank? | |||
| ob_jobs = ObRepositorySyncJob.where(ob_repository_sync_id: @ob_repository_sync.id) | |||
| ob_jobs = ob_jobs.where(job_type: params[:job_type]) if params[:job_type].present? | |||
| ob_jobs = ob_jobs.where(github_branch: params[:github_branch]) if params[:github_branch].present? | |||
| ob_jobs = ob_jobs.where(gitee_branch: params[:gitee_branch]) if params[:gitee_branch].present? | |||
| ob_jobs = ob_jobs.where(gitlink_branch: params[:gitlink_branch]) if params[:gitlink_branch].present? | |||
| tip_exception "该分支组合已配置,不能重复!" if ob_jobs.count > 0 | |||
| service = ObRepositorySync::ApiService.new(@ob_repository_sync.name) | |||
| res = service.create_projects_jobs(params) | |||
| tip_exception "保存失败: #{res["msg"]}" if res["code"].to_s != "200" | |||
| @@ -57,7 +74,7 @@ class ObRepositorySyncsController < ApplicationController | |||
| job.github_branch = "#{params[:github_branch]}" | |||
| job.gitee_branch = "#{params[:gitee_branch]}" | |||
| job.gitlink_branch = "#{params[:gitlink_branch]}" | |||
| job.job_type = "#{params[:type]}" | |||
| job.job_type = "#{params[:job_type]}" | |||
| job.base = "#{params[:base]}" | |||
| job.job_id = job_id | |||
| job.save | |||
| @@ -69,8 +86,9 @@ class ObRepositorySyncsController < ApplicationController | |||
| 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! | |||
| tip_exception "删除失败: #{res["msg"]}" if res["code"].to_s != "200" | |||
| job = ObRepositorySyncJob.find_by(ob_repository_sync_id: @ob_repository_sync.id, job_id: params[:job_id]) | |||
| job.destroy! if job.present? | |||
| render_ok | |||
| end | |||
| @@ -94,7 +112,7 @@ class ObRepositorySyncsController < ApplicationController | |||
| 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] | |||
| res = 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 | |||
| @@ -137,6 +137,7 @@ class RepositoriesController < ApplicationController | |||
| else | |||
| @commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token) | |||
| @commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true}) | |||
| render_error(@commit[:message], @commit[:status]) if @commit.has_key?(:status) || @commit_diff.has_key?(:status) | |||
| end | |||
| end | |||
| @@ -388,4 +389,4 @@ class RepositoriesController < ApplicationController | |||
| end | |||
| end | |||
| end | |||
| end | |||
| @@ -1,7 +1,7 @@ | |||
| class Traces::BaseController < ApplicationController | |||
| helper_method :observed_logged_user?, :observed_user | |||
| before_action :check_trace_system | |||
| def observed_user | |||
| @_observed_user ||= (User.find_by_login(params[:user_id]) || User.find_by_id(params[:user_id])) | |||
| @@ -15,4 +15,12 @@ class Traces::BaseController < ApplicationController | |||
| def check_auth | |||
| return render_forbidden unless current_user.admin? || observed_logged_user? | |||
| end | |||
| def check_trace_system | |||
| code, data, error = Trace::SystemInfoService.call(current_user.trace_token) | |||
| return render_ok({code: 501, data: {operate_time: data['operate_time']}, message: '系统维护中'}) if data['status'] === 0 | |||
| rescue | |||
| # 这里根据需求跳转到404 | |||
| return render_not_found | |||
| end | |||
| end | |||
| @@ -3,6 +3,7 @@ class Traces::ProjectsController < Traces::BaseController | |||
| before_action :require_login | |||
| before_action :load_project | |||
| before_action :require_project_not_be_forked_project | |||
| before_action :set_trace_token_to_cookie | |||
| before_action :authorizate_user_can_edit_project!, except: [:task_results] | |||
| @@ -95,4 +96,8 @@ class Traces::ProjectsController < Traces::BaseController | |||
| :domain => Trace.trace_config[:cookie_domain] | |||
| } | |||
| end | |||
| def require_project_not_be_forked_project | |||
| return render_error('fork仓库暂不支持代码溯源服务,敬请谅解。') if @project.forked_from_project_id.present? | |||
| end | |||
| end | |||
| @@ -903,6 +903,7 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff | |||
| |is_renamed|bool|是否重命名| | |||
| |is_ambiguous|bool|| | |||
| |is_submodule|bool|是否为子模块| | |||
| |diff|string|git diff内容| | |||
| |sections.file_name|string|文件名称| | |||
| |sections.name|string|| | |||
| |sections.lines.left_index|int|文件变动之前所在行数| | |||
| @@ -1028,6 +1029,7 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/reviews.json') | |||
| |owner |是| |string |用户登录名 | | |||
| |repo |是| |string |项目标识identifier | | |||
| |index |是| | int |合并请求序号| | |||
| |status |否| |string |审查类型, common: 评论类型, approved: 已通过, rejected: 已拒绝| | |||
| ### 返回字段说明: | |||
| 参数 | 类型 | 字段说明 | |||
| @@ -1246,6 +1248,8 @@ await octokit.request('GET /api/v1/yystopf/ceshi_commit/pulls/3/journals.json') | |||
| |need_respond |否| |bool |是否需要回应| | |||
| |state |否| |string |状态, opened: 开启的, resolved: 已解决的, disabled: 无效的| | |||
| |parent_id |否| |integer|父评论ID| | |||
| |path |否| |string |评论文件路径| | |||
| |is_full |否| |bool |是否展示全部评论(包括回复)| | |||
| |sort_by |否|created_on|string |排序字段 created_on: 创建时间, updated_on: 更新时间| | |||
| |sort_direction |否|asc |string |排序类型 desc: 倒序, asc: 正序| | |||
| @@ -1370,9 +1374,9 @@ await octokit.request('POST /api/v1/yystopf/ceshi/pulls/1/journals.json') | |||
| |owner |是| | string |用户登录名 | | |||
| |repo |是| | string |项目标识identifier | | |||
| |index |是| | integer|合并请求序号| | |||
| |type |是| | string |评论类型 comment: 普通, problem: 需要回应的评论| | |||
| |type |否|comment| string |评论类型 comment: 普通, problem: 需要回应的评论| | |||
| |note |否| | string |评论内容| | |||
| |review_id |是| | string |审查ID| | |||
| |review_id |否| | string |审查ID| | |||
| |line_code |否| | string |行号| | |||
| |commit_id |否| | bool |commitID| | |||
| |path |否| | integer|文件路径| | |||
| @@ -2283,7 +2283,7 @@ await octokit.request('POST /api/v1/yystopf/ceshi/webhooks.json') | |||
| |webhook.active |是| | bool | 是否激活| | |||
| |webhook.branch_filter|否| |string|分支过滤| | |||
| |webhook.events |否| |array|触发事件| | |||
| |webhook.type |否| gitea |string| hook类型,gitea slack discord dingtalk telegram msteams feishu matrix jianmu| | |||
| 触发事件字段说明 | |||
| 参数| 含义| | |||
| @@ -95,21 +95,31 @@ module ApplicationHelper | |||
| timePassed = currentTime - lastUpdateTime | |||
| timeIntoFormat = 0 | |||
| updateAtValue = "" | |||
| if timePassed < 0 | |||
| if timePassed <= 0 | |||
| updateAtValue = "刚刚" | |||
| elsif timePassed < 2 * 1000 | |||
| updateAtValue = "1秒前" | |||
| elsif timePassed < ONE_MINUTE | |||
| updateAtValue = "1分钟前" | |||
| elsif timePassed < ONE_HOUR | |||
| timeIntoFormat = timePassed / ONE_MINUTE | |||
| updateAtValue = timeIntoFormat.to_s + "分钟前" | |||
| elsif (timePassed < ONE_DAY) | |||
| timeIntoFormat = (timePassed.to_f / ONE_HOUR).ceil | |||
| timeIntoFormat = (timePassed.to_f / ONE_HOUR).round | |||
| timeIntoFormat == 1 if timeIntoFormat.to_i == 0 | |||
| updateAtValue = timeIntoFormat.to_s + "小时前" | |||
| elsif (timePassed < ONE_MONTH) | |||
| timeIntoFormat = (timePassed.to_f / ONE_DAY).ceil | |||
| timeIntoFormat = (timePassed.to_f / ONE_DAY).round | |||
| timeIntoFormat == 1 if timeIntoFormat.to_i == 0 | |||
| updateAtValue = timeIntoFormat.to_s + "天前" | |||
| elsif (timePassed < ONE_MONTH) | |||
| timeIntoFormat = (timePassed.to_f / ONE_DAY).round | |||
| timeIntoFormat == 1 if timeIntoFormat.to_i == 0 | |||
| updateAtValue = timeIntoFormat.to_s + "天前" | |||
| elsif (timePassed < ONE_YEAR) | |||
| timeIntoFormat = (timePassed.to_f / ONE_MONTH).ceil | |||
| timeIntoFormat = (timePassed.to_f / ONE_MONTH).round | |||
| timeIntoFormat == 1 if timeIntoFormat.to_i == 0 | |||
| updateAtValue = timeIntoFormat.to_s + "个月前" | |||
| else | |||
| timeIntoFormat = timePassed / ONE_YEAR | |||
| @@ -64,6 +64,7 @@ module ProjectsHelper | |||
| project_language_id: project.project_language_id, | |||
| license_id: project.license_id, | |||
| jianmu_devops: jianmu_devops_code(project, user), | |||
| jianmu_devops_url: jianmu_devops_url, | |||
| ignore_id: project.ignore_id | |||
| }).compact | |||
| @@ -123,6 +124,10 @@ module ProjectsHelper | |||
| end | |||
| end | |||
| def jianmu_devops_url | |||
| EduSetting.get("jianmu_devops_url") || "https://ci-v3.test.jianmuhub.com" | |||
| 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') | |||
| @@ -42,6 +42,7 @@ class Journal < ApplicationRecord | |||
| 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 | |||
| has_many :children_journals, class_name: 'Journal', foreign_key: :parent_id | |||
| scope :journal_includes, ->{includes(:user, :journal_details, :attachments)} | |||
| scope :parent_journals, ->{where(parent_id: nil)} | |||
| @@ -13,6 +13,7 @@ | |||
| # | |||
| class MessageTemplate < ApplicationRecord | |||
| self.inheritance_column = nil | |||
| PLATFORM = 'GitLink' | |||
| def self.build_init_data | |||
| @@ -113,6 +114,6 @@ class MessageTemplate < ApplicationRecord | |||
| end | |||
| def simple_type | |||
| self.type.split("::")[-1] | |||
| self.type.to_s.split("::")[-1] | |||
| end | |||
| end | |||
| @@ -49,7 +49,7 @@ class Repository < ApplicationRecord | |||
| end | |||
| def url | |||
| self['url'].blank? ? "#{Gitea.gitea_config[:domain]}/#{self.owner&.login}/#{self.identifier}.git" : self['url'] | |||
| self['url'].blank? ? "#{GiteaService.gitea_config[:domain]}/#{self.owner&.login}/#{self.identifier}.git" : self['url'] | |||
| end | |||
| # with repository is mirror | |||
| @@ -32,7 +32,7 @@ class TraceUser < ApplicationRecord | |||
| self.username = user.login | |||
| self.password = SecureRandom.hex | |||
| self.unit = user.custom_department.blank? ? 'GitLink' : user.custom_department | |||
| self.telnumber = user.phone.blank? ? '13800000000' : user.phone | |||
| self.telnumber = user.phone || "" | |||
| self.email = user.mail | |||
| self.name = user.nickname.blank? ? user.login : user.nickname | |||
| @@ -41,7 +41,7 @@ class TraceUser < ApplicationRecord | |||
| def build_token | |||
| return if username.blank? || password.blank? || unit.blank? || telnumber.blank? || email.blank? || name.blank? | |||
| return if username.blank? || password.blank? || unit.blank? || email.blank? || name.blank? | |||
| response = Trace::AddUserService.call(username, password, unit, telnumber, email, name) | |||
| self.token = response[1]['token'] | |||
| @@ -49,7 +49,7 @@ class TraceUser < ApplicationRecord | |||
| end | |||
| def refresh_token | |||
| return if username.blank? || password.blank? || unit.blank? || telnumber.blank? || email.blank? || name.blank? | |||
| return if username.blank? || password.blank? || unit.blank? || email.blank? || name.blank? | |||
| response = Trace::LoginService.call(username, password) | |||
| self.token = response[1]['token'] | |||
| @@ -32,7 +32,8 @@ class VersionRelease < ApplicationRecord | |||
| has_many :attachments, as: :container, dependent: :destroy | |||
| def update_sha | |||
| return if version_gid.blank? | |||
| git_release = Gitea::Versions::GetService.call(user.gitea_token, repository&.owner&.login, repository&.identifier, version_gid) | |||
| self.update(sha: git_release["sha"]) | |||
| self.update(sha: git_release["sha"]) if git_release.present? && git_release.is_a?(Hash) | |||
| end | |||
| end | |||
| @@ -15,7 +15,7 @@ class Api::V1::Projects::Pulls::Journals::CreateService < ApplicationService | |||
| @note = params[:note] | |||
| @commit_id = params[:commit_id] | |||
| @path = params[:path] | |||
| @type = params[:type] | |||
| @type = params[:type] || "comment" | |||
| @diff = params[:diff] | |||
| @review_id = params[:review_id] | |||
| @user = user | |||
| @@ -23,7 +23,7 @@ class Api::V1::Projects::Pulls::Journals::CreateService < ApplicationService | |||
| def call | |||
| raise Error, errors.full_messages.join(", ") unless valid? | |||
| check_review_is_exists | |||
| check_review_is_exists if review_id.present? | |||
| if type == 'problem' | |||
| create_problem_journal | |||
| else | |||
| @@ -1,12 +1,13 @@ | |||
| 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_reader :project, :pull_request, :keyword, :review_id, :need_respond, :state, :parent_id, :path, :is_full, :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 :is_full, inclusion: {in: [true, false], message: '请输入正确的IsFull'} | |||
| validates :state, inclusion: {in: %w(opened resolved disabled)}, allow_nil: true | |||
| def initialize(project, pull_request, params, user) | |||
| @@ -19,6 +20,8 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService | |||
| @parent_id = params[:parent_id] | |||
| @sort_by = params[:sort_by] || 'created_on' | |||
| @sort_direction = params[:sort_direction] || 'asc' | |||
| @is_full = ActiveModel::Type::Boolean.new.cast(params[:is_full]) || false | |||
| @path = params[:path] | |||
| @user = user | |||
| end | |||
| @@ -32,18 +35,21 @@ class Api::V1::Projects::Pulls::Journals::ListService < ApplicationService | |||
| 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 | |||
| if !is_full | |||
| if parent_id.present? | |||
| journals = journals.where(parent_id: parent_id) | |||
| else | |||
| journals = journals.parent_journals | |||
| end | |||
| 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? | |||
| journals = journals.where(path: path) if path.present? | |||
| q = journals.ransack(notes_cont: keyword) | |||
| scope = q.result.includes(:user, :resolveer, review: [:reviewer, pull_request: :issue]) | |||
| scope = q.result.includes(:user, :resolveer, :children_journals, review: [:reviewer, pull_request: :issue]) | |||
| scope = scope.order("journals.#{sort_by} #{sort_direction}") | |||
| @queried_journals = scope | |||
| @@ -26,6 +26,7 @@ class Api::V1::Projects::Pulls::Versions::GetDiffService < ApplicationService | |||
| access_token: token | |||
| } | |||
| params.merge!(filepath: filepath) if filepath.present? | |||
| params | |||
| end | |||
| def load_gitea_data | |||
| @@ -1,14 +1,14 @@ | |||
| class Api::V1::Projects::Webhooks::CreateService < ApplicationService | |||
| include ActiveModel::Model | |||
| attr_reader :project, :token, :owner, :repo, :active, :branch_filter, :content_type, :url, :http_method, :secret, :events | |||
| attr_reader :project, :token, :owner, :repo, :active, :branch_filter, :content_type, :url, :http_method, :secret, :events, :type | |||
| attr_accessor :gitea_data | |||
| validates :url, format: { with: URI::regexp(%w[http https]), message: "请输入正确的地址" } | |||
| validates :active, inclusion: {in: [true, false]} | |||
| validates :http_method, inclusion: { in: %w(POST GET), message: "请输入正确的请求方式"} | |||
| validates :content_type, inclusion: { in: %w(json form), message: "请输入正确的Content Type"} | |||
| validates :type, inclusion: {in: %w(gitea slack discord dingtalk telegram msteams feishu matrix jianmu), message: "请输入正确的Webhook Type"} | |||
| def initialize(project, params, token=nil) | |||
| @project = project | |||
| @owner = project&.owner.login | |||
| @@ -20,6 +20,7 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService | |||
| @http_method = params[:http_method] | |||
| @secret = params[:secret] | |||
| @events = params[:events] | |||
| @type = params[:type] || "gitea" | |||
| @token = token | |||
| end | |||
| @@ -52,7 +53,7 @@ class Api::V1::Projects::Webhooks::CreateService < ApplicationService | |||
| secret: secret | |||
| }, | |||
| events: events || [], | |||
| type: 'gitea', | |||
| type: type, | |||
| } | |||
| end | |||
| @@ -1,6 +1,6 @@ | |||
| # List pull requests files | |||
| class Gitea::PullRequest::FilesService < Gitea::ClientService | |||
| attr_reader :owner, :repo, :pull_number, :token | |||
| attr_reader :owner, :repo, :pull_number, :token, :params | |||
| # GET /repos/{owner}/{repo}/pulls/{pull_number}/files | |||
| # owner: 用户 | |||
| @@ -8,22 +8,23 @@ class Gitea::PullRequest::FilesService < Gitea::ClientService | |||
| # pull_number: pull request主键id | |||
| # eg: | |||
| # Gitea::PullRequest::FilesService.call('jasder', 'repo_identifier', 1) | |||
| def initialize(owner, repo, pull_number, token=nil) | |||
| def initialize(owner, repo, pull_number, token=nil, params={}) | |||
| @owner = owner | |||
| @repo = repo | |||
| @token = token | |||
| @pull_number = pull_number | |||
| @params = params | |||
| end | |||
| def call | |||
| response = get(url, params) | |||
| response = get(url, params.merge(token: token)) | |||
| render_result(response) | |||
| end | |||
| private | |||
| def params | |||
| Hash.new.merge(token: token) | |||
| end | |||
| # def params | |||
| # Hash.new.merge(token: token) | |||
| # end | |||
| def url | |||
| "/repos/#{owner}/#{repo}/pulls/#{pull_number}/files".freeze | |||
| @@ -42,8 +42,8 @@ class ObRepositorySync::ApiService < ApplicationService | |||
| res | |||
| end | |||
| def get_projects_jobs | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs") | |||
| def get_projects_jobs(source, pageNum = 1, pageSize = 100) | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs?pageSize=#{pageSize}&pageNum=#{pageNum}&source=#{source}") | |||
| http = Net::HTTP.new(url.host, url.port) | |||
| request = Net::HTTP::Get.new(url) | |||
| request["Content-Type"] = "application/json" | |||
| @@ -58,7 +58,7 @@ class ObRepositorySync::ApiService < ApplicationService | |||
| "github_branch": "#{params[:github_branch]}", | |||
| "gitee_branch": "#{params[:gitee_branch]}", | |||
| "gitlink_branch": "#{params[:gitlink_branch]}", | |||
| "type": "#{params[:type]}", | |||
| "type": "#{params[:job_type]}", | |||
| "base": "#{params[:base]}" | |||
| } | |||
| url = URI("#{domain}/cerobot/projects/#{@project_name}/jobs") | |||
| @@ -124,11 +124,7 @@ class ObRepositorySync::ApiService < ApplicationService | |||
| 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 | |||
| res | |||
| end | |||
| def pull_requests | |||
| @@ -0,0 +1,18 @@ | |||
| class Trace::SystemInfoService < Trace::ClientService | |||
| attr_accessor :token | |||
| def initialize(token) | |||
| @token = token | |||
| end | |||
| def call | |||
| result = authed_get(token, url) | |||
| response = render_response(result) | |||
| end | |||
| private | |||
| def url | |||
| '/user/systemInfo'.freeze | |||
| end | |||
| end | |||
| @@ -14,6 +14,7 @@ json.files diff['Files'].each do |file| | |||
| json.is_renamed file['IsRenamed'] | |||
| json.is_ambiguous file['IsAmbiguous'] | |||
| json.is_submodule file['IsSubmodule'] | |||
| json.diff file['Diff'] | |||
| json.sections file['Sections'] do |section| | |||
| json.file_name section['FileName'] | |||
| json.name section['Name'] | |||
| @@ -10,6 +10,7 @@ json.name file['Name'] | |||
| json.is_renamed file['IsRenamed'] | |||
| json.is_ambiguous file['IsAmbiguous'] | |||
| json.is_submodule file['IsSubmodule'] | |||
| json.diff file['Diff'] | |||
| json.sections file['Sections'] do |section| | |||
| json.file_name section['FileName'] | |||
| json.name section['Name'] | |||
| @@ -16,6 +16,7 @@ json.blame_parts @result_object['blame_parts'] do |part| | |||
| json.committed_time render_unix_time(part['commit']['committed_time']) | |||
| json.created_time render_unix_time(part['commit']['created_time']) | |||
| end | |||
| json.previous_number part['previous_number'] | |||
| json.current_number part['current_number'] | |||
| json.effect_line part['effect_line'] | |||
| json.lines part['lines'] | |||
| @@ -1,4 +1,4 @@ | |||
| json.total_count @journals.total_count | |||
| json.total_count @journals.count | |||
| json.journals @journals.each do |journal| | |||
| json.partial! 'api/v1/projects/pulls/journals/simple_detail', journal: journal | |||
| end | |||
| @@ -1,4 +1,5 @@ | |||
| json.total_count @reviews.total_count | |||
| # json.total_count @reviews.total_count | |||
| json.total_count @reviews.count | |||
| json.reviews @reviews.each do |review| | |||
| json.partial! 'api/v1/projects/pulls/reviews/simple_detail', review: review | |||
| end | |||
| @@ -1,3 +1,3 @@ | |||
| json.(webhook, :id, :url, :http_method, :is_active) | |||
| json.(webhook, :id, :url, :http_method, :is_active, :type) | |||
| json.last_status webhook.last_status | |||
| json.create_time Time.at(webhook.created_unix).strftime("%Y-%m-%d %H:%M:%S") | |||
| @@ -1,4 +1,5 @@ | |||
| json.id webhook["id"] | |||
| json.type webhook["type"] | |||
| json.content_type webhook['config']['content_type'] | |||
| json.http_method webhook['config']['http_method'] | |||
| json.url webhook['config']['url'] | |||
| @@ -1,9 +1,31 @@ | |||
| json.total_count @total_count | |||
| json.members @members do |member| | |||
| if member.user.present? | |||
| json.partial! 'member', user: member.user | |||
| json.is_owner @project.owner?(member.user) | |||
| json.role member.roles.last.name | |||
| json.role_name t("roles.#{member.roles.last.name}") | |||
| json.members do | |||
| if @current_user_header_team.present? | |||
| json.child! do | |||
| json.partial! 'member', user: current_user | |||
| json.is_owner @project.owner?(current_user) | |||
| case @current_user_header_team.authorize | |||
| when 'read' | |||
| json.role 'Reporter' | |||
| json.role_name t("roles.Reporter") | |||
| when 'write' | |||
| json.role 'Developer' | |||
| json.role_name t("roles.Developer") | |||
| when 'admin' | |||
| json.role 'Manager' | |||
| json.role_name t("roles.Manager") | |||
| when 'owner' | |||
| json.role 'Manager' | |||
| json.role_name t("roles.Manager") | |||
| end | |||
| end | |||
| end | |||
| @members.each do |member| | |||
| json.child! do | |||
| json.partial! 'member', user: member.user | |||
| json.is_owner @project.owner?(member.user) | |||
| json.role member.roles.last.name | |||
| json.role_name t("roles.#{member.roles.last.name}") | |||
| end | |||
| end | |||
| end | |||
| @@ -6,6 +6,7 @@ json.status message["status"] | |||
| json.content message["content"] | |||
| json.notification_url message["notification_url"] | |||
| json.source message["source"] | |||
| json.created_at message["created_at"] | |||
| json.time_ago time_from_now(message["created_at"].to_time) | |||
| case message["type"] | |||
| @@ -557,7 +557,11 @@ Rails.application.routes.draw do | |||
| get :files | |||
| get :commits | |||
| resources :reviews, only: [:create] | |||
| resources :mark_files, only: [:index, :create] | |||
| scope '/diffs' do | |||
| resources :mark_files, only: [:index] | |||
| put :mark_file_as_unread, to: 'mark_files#mark_file_as_unread', as: 'mark_file_as_unread' | |||
| put :mark_file_as_read, to: 'mark_files#mark_file_as_read', as: 'mark_file_as_read' | |||
| end | |||
| end | |||
| collection do | |||
| post :check_can_merge | |||
| @@ -588,6 +592,7 @@ Rails.application.routes.draw do | |||
| collection do | |||
| delete :delete | |||
| get :jobs | |||
| get :job_logs | |||
| post :create_jobs | |||
| delete :delete_job | |||
| post :start_job | |||
| @@ -11384,6 +11384,13 @@ http://localhost:3000/api/v1/yystopf/ceshi/webhooks.json | |||
| <td>array</td> | |||
| <td>触发事件</td> | |||
| </tr> | |||
| <tr> | |||
| <td>webhook.type</td> | |||
| <td>否</td> | |||
| <td>gitea</td> | |||
| <td>string</td> | |||
| <td>hook类型,gitea slack discord dingtalk telegram msteams feishu matrix jianmu</td> | |||
| </tr> | |||
| </tbody></table> | |||
| <p>触发事件字段说明 </p> | |||
| @@ -14335,6 +14342,11 @@ http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json | |||
| <td>是否为子模块</td> | |||
| </tr> | |||
| <tr> | |||
| <td>diff</td> | |||
| <td>string</td> | |||
| <td>git diff内容</td> | |||
| </tr> | |||
| <tr> | |||
| <td>sections.file_name</td> | |||
| <td>string</td> | |||
| <td>文件名称</td> | |||
| @@ -14545,6 +14557,13 @@ http://localhost:3000/api/v1/yystopf/ceshi_commit/pulls/3/versions/33/diff.json | |||
| <td>int</td> | |||
| <td>合并请求序号</td> | |||
| </tr> | |||
| <tr> | |||
| <td>status</td> | |||
| <td>否</td> | |||
| <td></td> | |||
| <td>string</td> | |||
| <td>审查类型, common: 评论类型, approved: 已通过, rejected: 已拒绝</td> | |||
| </tr> | |||
| </tbody></table> | |||
| <h3 id='7447e4874e-7'>返回字段说明:</h3> | |||
| <table><thead> | |||
| @@ -15053,6 +15072,20 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/reviews.json | |||
| <td>父评论ID</td> | |||
| </tr> | |||
| <tr> | |||
| <td>path</td> | |||
| <td>否</td> | |||
| <td></td> | |||
| <td>string</td> | |||
| <td>评论文件路径</td> | |||
| </tr> | |||
| <tr> | |||
| <td>is_full</td> | |||
| <td>否</td> | |||
| <td></td> | |||
| <td>bool</td> | |||
| <td>是否展示全部评论(包括回复)</td> | |||
| </tr> | |||
| <tr> | |||
| <td>sort_by</td> | |||
| <td>否</td> | |||
| <td>created_on</td> | |||
| @@ -15277,8 +15310,8 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals.json | |||
| </tr> | |||
| <tr> | |||
| <td>type</td> | |||
| <td>是</td> | |||
| <td></td> | |||
| <td>否</td> | |||
| <td>comment</td> | |||
| <td>string</td> | |||
| <td>评论类型 comment: 普通, problem: 需要回应的评论</td> | |||
| </tr> | |||
| @@ -15291,7 +15324,7 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals.json | |||
| </tr> | |||
| <tr> | |||
| <td>review_id</td> | |||
| <td>是</td> | |||
| <td>否</td> | |||
| <td></td> | |||
| <td>string</td> | |||
| <td>审查ID</td> | |||