From 983edca9a3f055c30ae0cb13f6d09d7ef64c07a0 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Thu, 30 May 2024 11:50:08 +0800 Subject: [PATCH] add sonarqube for projects --- Gemfile | 2 +- Gemfile.lock | 34 +++++++++++++------ app/controllers/api/v1/projects_controller.rb | 7 +++- config/initializers/sonarqube.rb | 6 ++++ config/routes/api.rb | 3 +- 5 files changed, 38 insertions(+), 14 deletions(-) create mode 100644 config/initializers/sonarqube.rb diff --git a/Gemfile b/Gemfile index 811fabc41..41e5d2123 100644 --- a/Gemfile +++ b/Gemfile @@ -26,7 +26,7 @@ gem 'roo-xls' gem 'simple_xlsx_reader', '~>1.0.4' gem 'rubyzip' - +gem 'sonarqube', :git => 'https://gitlink.org.cn/KingChan/sonarqube.git' gem 'spreadsheet' gem 'ruby-ole' # 导出为xlsx diff --git a/Gemfile.lock b/Gemfile.lock index b7f060b2a..0e18d1f29 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,3 +1,11 @@ +GIT + remote: https://gitlink.org.cn/KingChan/sonarqube.git + revision: 80f07d427322ef02c0714c77a382e87aed0bef81 + specs: + sonarqube (1.3.0) + httparty (~> 0.14, >= 0.14.0) + terminal-table (~> 1.5, >= 1.5.1) + GEM remote: https://mirrors.cloud.tencent.com/rubygems/ specs: @@ -135,7 +143,7 @@ GEM fugit (1.4.1) et-orbi (~> 1.1, >= 1.1.8) raabro (~> 1.4) - gitea-client (1.4.2) + gitea-client (1.5.7) rest-client (~> 2.1.0) globalid (0.4.2) activesupport (>= 4.2.0) @@ -150,6 +158,9 @@ GEM http-accept (1.7.0) http-cookie (1.0.5) domain_name (~> 0.5) + httparty (0.21.0) + mini_mime (>= 1.0.0) + multi_xml (>= 0.5.2) i18n (1.8.2) concurrent-ruby (~> 1.0) io-like (0.3.1) @@ -187,9 +198,9 @@ GEM mimemagic (~> 0.3.2) maruku (0.7.3) method_source (0.9.2) - mime-types (3.4.1) + mime-types (3.5.2) mime-types-data (~> 3.2015) - mime-types-data (3.2023.0218.1) + mime-types-data (3.2024.0507) mimemagic (0.3.10) nokogiri (~> 1) rake @@ -245,13 +256,12 @@ GEM powerpack (0.1.2) prettier (0.18.2) public_suffix (4.0.3) - puma (3.12.2) + puma (5.6.8) + nio4r (~> 2.0) raabro (1.4.0) rack (2.0.9) rack-cors (1.1.1) rack (>= 2.0.0) - rack-mini-profiler (2.0.1) - rack (>= 1.2.0) rack-protection (2.0.8.1) rack rack-test (1.1.0) @@ -438,6 +448,8 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + terminal-table (1.8.0) + unicode-display_width (~> 1.1, >= 1.1.1) thor (1.0.1) thread_safe (0.3.6) tilt (2.0.10) @@ -450,7 +462,7 @@ GEM execjs (>= 0.3.0, < 3) unf (0.1.4) unf_ext - unf_ext (0.0.8.2) + unf_ext (0.0.9.1) unicode-display_width (1.6.1) web-console (3.7.0) actionview (>= 5.0) @@ -492,7 +504,7 @@ DEPENDENCIES enumerize faraday (~> 0.15.4) font-awesome-sass (= 4.7.0) - gitea-client (~> 1.4.2) + gitea-client (~> 1.5.7) grape-entity (~> 0.7.1) groupdate (~> 4.1.0) harmonious_dictionary (~> 0.0.1) @@ -514,9 +526,8 @@ DEPENDENCIES parallel (~> 1.19, >= 1.19.1) pdfkit prettier - puma (~> 3.11) + puma (~> 5.6.5) rack-cors - rack-mini-profiler rails (~> 5.2.0) rails-i18n (~> 5.1) ransack @@ -538,9 +549,10 @@ DEPENDENCIES sidekiq-cron (= 1.2.0) sidekiq-failures simple_form - simple_xlsx_reader + simple_xlsx_reader (~> 1.0.4) sinatra solargraph (~> 0.38.0) + sonarqube! spreadsheet spring spring-watcher-listen (~> 2.0.0) diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 810c40171..33f664b31 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -1,5 +1,5 @@ class Api::V1::ProjectsController < Api::V1::BaseController - before_action :require_public_and_member_above, only: [:show, :compare, :blame] + before_action :require_public_and_member_above, only: [:show, :compare, :blame, :sonar_search] def index render_ok @@ -9,6 +9,11 @@ class Api::V1::ProjectsController < Api::V1::BaseController @result_object = Api::V1::Projects::GetService.call(@project, current_user.gitea_token) end + def sonar_search + data = Sonarqube.client.get("/api/issues/search", { components:"#{@project.owner.login}-#{@project.identifier}" }) + render_ok data + end + def compare @result_object = Api::V1::Projects::CompareService.call(@project, params[:from], params[:to], current_user&.gitea_token) end diff --git a/config/initializers/sonarqube.rb b/config/initializers/sonarqube.rb new file mode 100644 index 000000000..99c88c82a --- /dev/null +++ b/config/initializers/sonarqube.rb @@ -0,0 +1,6 @@ +Sonarqube.configure do |config| + config.endpoint = 'http://172.20.32.202:9999' # API endpoint URL, default: ENV['SONARQUBE_API_ENDPOINT'] + config.private_token = 'squ_fb81f52a7b2c2db00c71c29f71c9595f48c2ff3f' # user's private token, default: ENV['SONARQUBE_API_PRIVATE_TOKEN'] + # Optional + # config.user_agent = 'Custom User Agent' # user agent, default: 'Sonarqube Ruby Gem [version]' +end \ No newline at end of file diff --git a/config/routes/api.rb b/config/routes/api.rb index c74b38836..9eede3e4f 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -48,7 +48,7 @@ defaults format: :json do end end - scope ':owner' do + scope ':owner' do resource :users, path: '/', only: [:update, :edit, :destroy] do collection do get :send_email_vefify_code @@ -76,6 +76,7 @@ defaults format: :json do collection do get :compare get :blame + get :sonar_search end end