From ad085fcddc2cb363707553c279c253373cb05ae7 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Wed, 29 May 2024 16:06:56 +0800 Subject: [PATCH] add sonarqube --- Gemfile | 3 +- Gemfile.lock | 34 +++++++++++++------ .../javascripts/api/v1/sonarqube/issues.js | 2 ++ .../stylesheets/api/v1/sonarqube/issues.scss | 3 ++ .../api/v1/sonarqubes/issues_controller.rb | 6 ++++ app/helpers/api/v1/sonarqube/issues_helper.rb | 2 ++ config/initializers/sonarqube.rb | 6 ++++ config/routes/api.rb | 6 ++++ .../v1/sonarqube/issues_controller_spec.rb | 5 +++ .../api/v1/sonarqube/issues_helper_spec.rb | 15 ++++++++ 10 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 app/assets/javascripts/api/v1/sonarqube/issues.js create mode 100644 app/assets/stylesheets/api/v1/sonarqube/issues.scss create mode 100644 app/controllers/api/v1/sonarqubes/issues_controller.rb create mode 100644 app/helpers/api/v1/sonarqube/issues_helper.rb create mode 100644 config/initializers/sonarqube.rb create mode 100644 spec/controllers/api/v1/sonarqube/issues_controller_spec.rb create mode 100644 spec/helpers/api/v1/sonarqube/issues_helper_spec.rb diff --git a/Gemfile b/Gemfile index edaae8a75..206b0057d 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 @@ -114,7 +114,6 @@ gem 'aasm' gem 'enumerize' gem 'diffy' - gem 'deep_cloneable', '~> 3.0.0' # oauth2 diff --git a/Gemfile.lock b/Gemfile.lock index b7f060b2a..4dff7c2ba 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.4.6) 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.4.3) 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/assets/javascripts/api/v1/sonarqube/issues.js b/app/assets/javascripts/api/v1/sonarqube/issues.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/api/v1/sonarqube/issues.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/app/assets/stylesheets/api/v1/sonarqube/issues.scss b/app/assets/stylesheets/api/v1/sonarqube/issues.scss new file mode 100644 index 000000000..a74cba738 --- /dev/null +++ b/app/assets/stylesheets/api/v1/sonarqube/issues.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the api/v1/sonarqube/issues controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/api/v1/sonarqubes/issues_controller.rb b/app/controllers/api/v1/sonarqubes/issues_controller.rb new file mode 100644 index 000000000..0a0188875 --- /dev/null +++ b/app/controllers/api/v1/sonarqubes/issues_controller.rb @@ -0,0 +1,6 @@ +class Api::V1::Sonarqubes::IssuesController < ApplicationController + def index + data = Sonarqube.client.get("/api/issues/search",params) + render_ok data + end +end diff --git a/app/helpers/api/v1/sonarqube/issues_helper.rb b/app/helpers/api/v1/sonarqube/issues_helper.rb new file mode 100644 index 000000000..7dbee46e4 --- /dev/null +++ b/app/helpers/api/v1/sonarqube/issues_helper.rb @@ -0,0 +1,2 @@ +module Api::V1::Sonarqube::IssuesHelper +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 6df7dc8a3..66018a51c 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -48,6 +48,12 @@ defaults format: :json do end end + resources :sonarqubes ,only: [:index] do + collection do + resource :issues + end + end + scope ':owner' do resource :users, path: '/', only: [:update, :edit, :destroy] do collection do diff --git a/spec/controllers/api/v1/sonarqube/issues_controller_spec.rb b/spec/controllers/api/v1/sonarqube/issues_controller_spec.rb new file mode 100644 index 000000000..194d01c09 --- /dev/null +++ b/spec/controllers/api/v1/sonarqube/issues_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::V1::Sonarqube::IssuesController, type: :controller do + +end diff --git a/spec/helpers/api/v1/sonarqube/issues_helper_spec.rb b/spec/helpers/api/v1/sonarqube/issues_helper_spec.rb new file mode 100644 index 000000000..7288e088d --- /dev/null +++ b/spec/helpers/api/v1/sonarqube/issues_helper_spec.rb @@ -0,0 +1,15 @@ +require 'rails_helper' + +# Specs in this file have access to a helper object that includes +# the Api::V1::Sonarqube::IssuesHelper. For example: +# +# describe Api::V1::Sonarqube::IssuesHelper do +# describe "string concat" do +# it "concats two strings with spaces" do +# expect(helper.concat_strings("this","that")).to eq("this that") +# end +# end +# end +RSpec.describe Api::V1::Sonarqube::IssuesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end