| @@ -1,5 +1,6 @@ | |||
| #source 'https://gems.ruby-china.com' | |||
| source 'https://mirrors.cloud.tencent.com/rubygems/' | |||
| #source 'https://rubygems.org' | |||
| git_source(:github) { |repo| "https://github.com/#{repo}.git" } | |||
| gem 'rails', '~> 5.2.0' | |||
| @@ -0,0 +1,31 @@ | |||
| class Api::V1::Projects::OssHealthMeasuringController < Api::V1::BaseController | |||
| def index | |||
| url = URI("#{EduSetting.get("ohm_server_url")}/api/OSS_Health_Measuring/#{params[:owner]}/#{params[:repo]}") | |||
| http = Net::HTTP.new(url.host, url.port); | |||
| request = Net::HTTP::Get.new(url) | |||
| response = http.request(request) | |||
| render :json=> response.read_body | |||
| end | |||
| def keyid | |||
| url = URI("#{EduSetting.get("ohm_server_url")}/api/OSS_Health_Measuring/#{params[:owner]}/#{params[:repo]}/#{params[:key_id]}") | |||
| http = Net::HTTP.new(url.host, url.port); | |||
| request = Net::HTTP::Get.new(url) | |||
| response = http.request(request) | |||
| render :json=> response.read_body | |||
| end | |||
| def can_get | |||
| url = URI("#{EduSetting.get("ohm_server_url")}/api/OHM_can_get/#{params[:owner]}/#{params[:repo]}") | |||
| http = Net::HTTP.new(url.host, url.port); | |||
| request = Net::HTTP::Get.new(url) | |||
| response = http.request(request) | |||
| render :json=> response.read_body | |||
| end | |||
| end | |||
| @@ -8,6 +8,6 @@ class Api::V1::Users::ProjectsController < Api::V1::BaseController | |||
| private | |||
| def query_params | |||
| params.permit(:category, :is_public, :project_type, :sort_by, :sort_direction, :search) | |||
| params.permit(:category, :is_public, :project_type, :sort_by, :sort_direction, :search, :start_at, :end_at) | |||
| end | |||
| end | |||
| @@ -287,13 +287,19 @@ class ProjectsController < ApplicationController | |||
| end | |||
| def watch_users | |||
| start_at = params[:start_at] | |||
| end_at = params[:end_at] | |||
| watchers = @project.watchers.includes(:user).order("watchers.created_at desc").distinct | |||
| watchers = watchers.where("watchers.created_at > ? and watchers.created_at < ?", Time.at(start_at.to_i), Time.at(end_at.to_i)) if start_at.present? && end_at.present? | |||
| @watchers_count = watchers.size | |||
| @watchers = paginate(watchers) | |||
| end | |||
| def praise_users | |||
| start_at = params[:start_at] | |||
| end_at = params[:end_at] | |||
| praises = @project.praise_treads.includes(:user).order("praise_treads.created_at desc").distinct | |||
| praises = praises.where("praise_treads.created_at > ? and praise_treads.created_at < ?", Time.at(start_at.to_i), Time.at(end_at.to_i)) if start_at.present? && end_at.present? | |||
| @praises_count = praises.size | |||
| @praises = paginate(praises) | |||
| end | |||
| @@ -5,7 +5,10 @@ class WatchersController < ApplicationController | |||
| before_action :get_target | |||
| def index | |||
| start_at = params[:start_at] | |||
| end_at = params[:end_at] | |||
| scope = @target.watchers.includes(:user) | |||
| scope = scope.where("watchers.created_at > ? and watchers.created_at < ?", Time.at(start_at.to_i), Time.at(end_at.to_i)) if start_at.present? && end_at.present? | |||
| @watchers = paginate(scope) | |||
| end | |||
| @@ -154,6 +154,9 @@ module ProjectsHelper | |||
| when 'kernel' then "#{url}/v1/openeuler/entropy" | |||
| when 'opengauss-server' then "#{url}/v1/opengauss/entropy" | |||
| when 'mindspore' then "#{url}/v1/mindspore/entropy" | |||
| when 'openharmony' then "#{url}/api/openharmony/entropy" | |||
| when 'openeuler' then "#{url}/api/openeuler/entropy" | |||
| when 'xiuos' then "#{url}/api/xiuos/entropy" | |||
| else '' | |||
| end | |||
| end | |||
| @@ -1,7 +1,7 @@ | |||
| class Api::V1::Users::Projects::ListService < ApplicationService | |||
| include ActiveModel::Model | |||
| attr_reader :observe_user, :category, :is_public, :project_type, :sort_by, :sort_direction, :search, :current_user | |||
| attr_reader :observe_user, :category, :is_public, :project_type, :sort_by, :sort_direction, :search, :start_at, :end_at, :current_user | |||
| attr_accessor :queried_projects | |||
| validates :category, inclusion: {in: %w(all join created manage watched forked), message: "请输入正确的Category"} | |||
| @@ -18,6 +18,8 @@ class Api::V1::Users::Projects::ListService < ApplicationService | |||
| @sort_by = params[:sort_by] || 'updated_on' | |||
| @sort_direction = params[:sort_direction] || 'desc' | |||
| @search = params[:search] | |||
| @start_at = params[:start_at] | |||
| @end_at = params[:end_at] | |||
| @current_user = current_user | |||
| end | |||
| @@ -53,10 +55,16 @@ class Api::V1::Users::Projects::ListService < ApplicationService | |||
| projects = Project.from("( #{normal_projects} UNION #{org_projects} ) AS projects").distinct | |||
| when 'watched' | |||
| projects = projects.where.not(user_id: observe_user.id).joins(:watchers).where(watchers: {watchable_type: "Project", user_id: observe_user.id}) | |||
| projects = projects.joins(:watchers).where("watchers.created_at > ? and watchers.created_at < ?", Time.at(start_at.to_i), Time.at(end_at.to_i)) if start_at.present? && end_at.present? | |||
| when 'only_watched' | |||
| projects = projects.where.joins(:watchers).where(watchers: {watchable_type: "Project", user_id: observe_user.id}) | |||
| projects = projects.joins(:watchers).where("watchers.created_at > ? and watchers.created_at < ?", Time.at(start_at.to_i), Time.at(end_at.to_i)) if start_at.present? && end_at.present? | |||
| when 'forked' | |||
| fork_ids = observe_user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id) | |||
| if start_at.present? && end_at.present? | |||
| fork_ids = observe_user.fork_users.where("created_at > ? and created_at < ?", Time.at(start_at.to_i), Time.at(end_at.to_i)).select(:id, :fork_project_id).pluck(:fork_project_id) | |||
| else | |||
| fork_ids = observe_user.fork_users.select(:id, :fork_project_id).pluck(:fork_project_id) | |||
| end | |||
| projects = projects.where(id: fork_ids) | |||
| else | |||
| normal_projects = projects.members_projects(observe_user.id).to_sql | |||
| @@ -23,4 +23,5 @@ json.issue do | |||
| end | |||
| json.reviewers pull.reviewers.pluck(:login) | |||
| json.journals_count pull.journals.count | |||
| json.journals_count pull.journals.count | |||
| json.pr_created_unix pull.created_at.to_i | |||
| @@ -33,6 +33,7 @@ json.issues do | |||
| json.name issue.subject | |||
| json.pr_time time_from_now(pr.status == 1 ? pr.updated_at : issue.updated_on) | |||
| json.pr_full_time pr.status == 1 ? pr.updated_at : issue.updated_on | |||
| json.pr_created_unix pr.created_at.to_i | |||
| json.assign_user_name issue.get_assign_user.try(:show_real_name) | |||
| json.assign_user_login issue.get_assign_user.try(:login) | |||
| json.author_name issue.user.blank?? "已注销": issue.user.show_real_name | |||
| @@ -1431,6 +1431,11 @@ Q微 | |||
| 永鑫娱乐 | |||
| 新锦江公司 | |||
| 福布斯客服 | |||
| 福布斯 | |||
| 客服热线 | |||
| 红蓝注册 | |||
| 上分游戏 | |||
| 游戏网址 | |||
| 亚星正网 | |||
| 尊龙凯时 | |||
| 线上开户 | |||
| @@ -131,6 +131,12 @@ defaults format: :json do | |||
| # projects文件夹下的 | |||
| scope module: :projects do | |||
| resources :oss_health_measuring, only: [:index] do | |||
| collection do | |||
| get :can_get | |||
| get :keyid | |||
| end | |||
| end | |||
| resources :portrait, only: [:index] | |||
| resources :sync_repositories, only: [:create, :index] do | |||
| collection do | |||
| @@ -6,7 +6,7 @@ class AddUserInfoToUserActions < ActiveRecord::Migration[5.2] | |||
| add_column :user_actions, :memo, :text | |||
| UserAction.find_in_batches(batch_size: 1000) do |sw| | |||
| Parallel.each(sw, in_threads: 5) do |user_action| | |||
| Parallel.each(sw, in_threads: 1) do |user_action| | |||
| if user_action.user.present? | |||
| user_action.login = user_action.user&.login | |||
| user_action.email = user_action.user&.mail | |||
| @@ -0,0 +1,146 @@ | |||
| desc "导入导出issue、version、journal数据" | |||
| namespace :import_from_another_forge do | |||
| def find_or_create_by(login) | |||
| return nil unless login.present? | |||
| user = User.find_by(login: login) | |||
| return user if user.present? | |||
| user = User.new(admin: false, login: login, mail: "#{login}@forge.com", nickname: login, platform: 'forge' , type: "User") | |||
| user.password = "12345678" | |||
| user.activate | |||
| interactor = Gitea::RegisterInteractor.call({username: login, email: "#{login}@forge.com", password: "12345678"}) | |||
| gitea_user = interactor.result | |||
| result = Gitea::User::GenerateTokenService.call(login, "12345678") | |||
| user.gitea_token = result['sha1'] | |||
| user.gitea_uid = gitea_user[:body]['id'] | |||
| user.save! | |||
| UserExtension.create!(user_id: user.id) | |||
| return user | |||
| rescue | |||
| return nil | |||
| end | |||
| desc "导出数据" | |||
| # 执行示例 bundle exec rake "import_from_another_forge:export[110]" | |||
| # RAILS_ENV=production bundle exec rake "import_from_another_forge:export[110]" | |||
| task :export, [:project_id] => :environment do |t, args| | |||
| project_id = args.project_id | |||
| project = Project.find_by_id project_id | |||
| Axlsx::Package.new do |p| | |||
| p.workbook.add_worksheet(:name => 'version') do |sheet| | |||
| sheet.add_row ['id', 'name', 'description', 'effective_date', 'created_on', 'updated_on', 'status', 'creator','issues_count', 'closed_issues_count', 'percent'] | |||
| project.versions.each do |version| | |||
| sheet.add_row [version.id, version.name, version.description, version.effective_date, version.created_on.strftime("%Y-%m-%d %H:%M:%S"), version.updated_on.strftime("%Y-%m-%d %H:%M:%S"), version.status, version.user.try(:login), version.issues_count, version.closed_issues_count, version.percent] | |||
| end | |||
| end | |||
| p.workbook.add_worksheet(:name => 'issue') do |sheet| | |||
| sheet.add_row ['id', 'project_issues_index', 'subject', 'description', 'creator', 'created_on', 'changer', 'updated_on', 'status_id', 'assigners', 'priority_id', 'issue_tags', 'version_id'] | |||
| project.issues.issue_issue.each do |issue| | |||
| sheet.add_row [issue.id, issue.project_issues_index, issue.subject, issue.description, issue.user.try(:login), issue.created_on.strftime("%Y-%m-%d %H:%M:%S"), issue.changer.try(:login), issue.updated_on.strftime("%Y-%m-%d %H:%M:%S"), issue.status_id, issue.assigners.pluck(:login).join(","),issue.priority_id, issue.issue_tags.pluck(:name, :color).join(","), issue.fixed_version_id] | |||
| end | |||
| end | |||
| issue_ids = project.issues.issue_issue | |||
| p.workbook.add_worksheet(:name => 'journal') do |sheet| | |||
| sheet.add_row ['id', 'journalized_type', 'journalized_id', 'creator', 'notes', 'created_on', 'parent_id', 'comments_count', 'reply_id', 'updated_on', 'operate_by'] | |||
| Journal.where(journalized_type: 'Issue', journalized_id: issue_ids).where.not(notes: nil).each do |journal| | |||
| sheet.add_row [journal.id, journal.journalized_type, journal.journalized_id, journal.user.try(:login), journal.notes, journal.created_on.strftime("%Y-%m-%d %H:%M:%S"), journal.parent_id, journal.comments_count, journal.reply_id, journal.updated_on.strftime("%Y-%m-%d %H:%M:%S"), journal.operate_by] | |||
| end | |||
| end | |||
| p.serialize('public/version_issue_journal_data.xlsx') | |||
| end | |||
| end | |||
| # 执行示例 bundle exec rake "import_from_another_forge:import[filepath, 365, ceshi_org]" | |||
| # RAILS_ENV=production bundle exec rake "import_from_another_forge:import[public/version_issue_journal_data.xlsx, 110]" | |||
| task :import, [:attachment_uuid, :project_id] => :environment do |t, args| | |||
| attachment_uuid = args.attachment_uuid | |||
| project_id = args.project_id | |||
| a =Attachment.find_by(uuid: attachment_uuid) | |||
| project = Project.find_by_id project_id | |||
| version_hash = {} | |||
| issue_hash = {} | |||
| journal_hash = {} | |||
| ActiveRecord::Base.transaction do | |||
| doc = SimpleXlsxReader.open("#{Rails.root}/tmp/files/#{a.relative_path_filename}") | |||
| doc.sheets.each do |sheet| | |||
| case sheet.name | |||
| when 'version' | |||
| sheet.rows.each.with_index do |row, index| | |||
| next if index == 0 | |||
| version = Version.new(project_id: project_id) | |||
| version.name = row[1] | |||
| version.description = row[2] | |||
| version.effective_date = row[3] | |||
| version.created_on = row[4] | |||
| version.updated_on = row[5] | |||
| version.status = row[6] | |||
| version.user = find_or_create_by(row[7]) | |||
| version.issues_count = row[8].to_i | |||
| version.closed_issues_count = row[9].to_i | |||
| version.percent = row[10].to_f | |||
| version.save! | |||
| version_hash["#{row[0]}"] = version.id | |||
| end | |||
| when 'issue' | |||
| sheet.rows.each.with_index do |row, index| | |||
| next if index == 0 | |||
| issue = Issue.new(issue_classify: "issue", project_id: project_id, tracker_id: Tracker.first.id) | |||
| issue.project_issues_index = row[1] | |||
| issue.subject = row[2] | |||
| issue.description = row[3] | |||
| issue.user = find_or_create_by(row[4]) | |||
| issue.created_on = row[5] | |||
| issue.changer = find_or_create_by(row[6]) | |||
| issue.updated_on = row[7] | |||
| issue.status_id = row[8] | |||
| if row[9].present? | |||
| row[9].split(',').each do |a| | |||
| u = find_or_create_by(a) | |||
| next unless u.present? | |||
| issue.assigners << u | |||
| end | |||
| end | |||
| issue.priority_id = row[10] | |||
| issue.issue_tags | |||
| if row[11].present? | |||
| row[11].split(',').each_slice(2).to_a.each do |t| | |||
| tag = IssueTag.find_by(project_id: project_id, name: t[0]) | |||
| if tag.present? | |||
| issue.issue_tags << tag | |||
| else | |||
| tag = IssueTag.create(project_id: project_id, name: t[0], color: t[1]) | |||
| issue.issue_tags << tag | |||
| end | |||
| end | |||
| end | |||
| issue.fixed_version_id = version_hash["#{row[12]}"] | |||
| issue.save! | |||
| issue_hash["#{row[0]}"] = issue.id | |||
| end | |||
| when 'journal' | |||
| sheet.rows.each.with_index do |row, index| | |||
| next if index == 0 | |||
| next if row[6].present? || row[8].present? | |||
| journal = Journal.new | |||
| journal.journalized_type = row[1] | |||
| journal.journalized_id = issue_hash["#{row[2]}"] | |||
| journal.user = find_or_create_by(row[3]) | |||
| journal.notes = row[4] | |||
| journal.created_on = row[5] | |||
| journal.updated_on = row[9] | |||
| journal.parent_id = journal_hash["#{row[6]}"] | |||
| journal.reply_id = journal_hash["#{row[8]}"] | |||
| journal.save! | |||
| journal_hash["#{row[0]}"] = journal.id | |||
| end | |||
| end | |||
| end | |||
| end | |||
| end | |||
| end | |||