From c98c7d5ac57294ca79f56232fdcd0a3859bbd6e5 Mon Sep 17 00:00:00 2001 From: kingChan <281221230@qq.com> Date: Tue, 4 Jun 2024 17:25:08 +0800 Subject: [PATCH] =?UTF-8?q?sonar=20=E8=BD=AC=E5=8F=91=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Gemfile | 1 + Gemfile.lock | 7 ++++ app/assets/javascripts/api/v1/sonarqubes.js | 2 + app/assets/stylesheets/api/v1/sonarqubes.scss | 3 ++ app/controllers/api/v1/projects_controller.rb | 4 -- .../api/v1/sonarqubes_controller.rb | 40 +++++++++++++++++++ app/helpers/api/v1/sonarqubes_helper.rb | 2 + config/routes/api.rb | 7 +++- .../api/v1/sonarqubes_controller_spec.rb | 5 +++ spec/helpers/api/v1/sonarqubes_helper_spec.rb | 15 +++++++ 10 files changed, 81 insertions(+), 5 deletions(-) create mode 100644 app/assets/javascripts/api/v1/sonarqubes.js create mode 100644 app/assets/stylesheets/api/v1/sonarqubes.scss create mode 100644 app/controllers/api/v1/sonarqubes_controller.rb create mode 100644 app/helpers/api/v1/sonarqubes_helper.rb create mode 100644 spec/controllers/api/v1/sonarqubes_controller_spec.rb create mode 100644 spec/helpers/api/v1/sonarqubes_helper_spec.rb diff --git a/Gemfile b/Gemfile index 41e5d2123..07fb6b68b 100644 --- a/Gemfile +++ b/Gemfile @@ -70,6 +70,7 @@ group :development do gem 'web-console', '>= 3.3.0' gem 'listen', '>= 3.0.5', '< 3.2' gem 'spring' + gem 'pry-rails' gem 'spring-watcher-listen', '~> 2.0.0' gem "annotate", "~> 2.6.0" end diff --git a/Gemfile.lock b/Gemfile.lock index 0e18d1f29..fd4d95fa4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -107,6 +107,7 @@ GEM archive-zip (~> 0.10) nokogiri (~> 1.8) chunky_png (1.3.11) + coderay (1.1.3) concurrent-ruby (1.1.6) connection_pool (2.2.2) crass (1.0.6) @@ -255,6 +256,11 @@ GEM popper_js (1.16.0) powerpack (0.1.2) prettier (0.18.2) + pry (0.12.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + pry-rails (0.3.9) + pry (>= 0.10.4) public_suffix (4.0.3) puma (5.6.8) nio4r (~> 2.0) @@ -526,6 +532,7 @@ DEPENDENCIES parallel (~> 1.19, >= 1.19.1) pdfkit prettier + pry-rails puma (~> 5.6.5) rack-cors rails (~> 5.2.0) diff --git a/app/assets/javascripts/api/v1/sonarqubes.js b/app/assets/javascripts/api/v1/sonarqubes.js new file mode 100644 index 000000000..dee720fac --- /dev/null +++ b/app/assets/javascripts/api/v1/sonarqubes.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/sonarqubes.scss b/app/assets/stylesheets/api/v1/sonarqubes.scss new file mode 100644 index 000000000..8b651fe3a --- /dev/null +++ b/app/assets/stylesheets/api/v1/sonarqubes.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the api/v1/sonarqubes 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/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 33f664b31..d6a90e14a 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -9,10 +9,6 @@ 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) diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb new file mode 100644 index 000000000..6db7e2102 --- /dev/null +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -0,0 +1,40 @@ +class Api::V1::SonarqubesController < Api::V1::BaseController + def issues_search + params_data = { + components: 'kingchanx-fluid-cloudnative_fluid', + s: 'FILE_LINE', + impactSoftwareQualities: 'SECURITY', + issueStatuses: 'CONFIRMED%2COPEN', + ps: 100, + facets: 'cleanCodeAttributeCategories%2CimpactSoftwareQualities%2CcodeVariants&', + additionalFields: '_all', + timeZone: 'Asia%2FShanghai' + } + data = Sonarqube.client.get('/api/issues/search', params_data) + render_ok data + end + + def ce_component + params_data = { + components: 'kingchanx-fluid-cloudnative_fluid', + } + data = Sonarqube.client.get('/api/ce/component', params_data) + render_ok data + end + + def sources_issue_snippet + params_data = { + issueKey: '93f87856-d71e-44f6-93b6-f9a6d54ff488' + } + data = Sonarqube.client.get('/api/sources/issue_snippets', params_data) + render_ok data + end + + def rules_show + params_data = { + key: 'kubernetes%3AS6865' + } + data = Sonarqube.client.get('/api/rules/show', params_data) + render_ok data + end +end diff --git a/app/helpers/api/v1/sonarqubes_helper.rb b/app/helpers/api/v1/sonarqubes_helper.rb new file mode 100644 index 000000000..94205dc10 --- /dev/null +++ b/app/helpers/api/v1/sonarqubes_helper.rb @@ -0,0 +1,2 @@ +module Api::V1::SonarqubesHelper +end diff --git a/config/routes/api.rb b/config/routes/api.rb index 9eede3e4f..7adc55323 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -76,7 +76,12 @@ defaults format: :json do collection do get :compare get :blame - get :sonar_search + + end + end + resource :sonarqubes, only: [:index] do + collection do + get :search end end diff --git a/spec/controllers/api/v1/sonarqubes_controller_spec.rb b/spec/controllers/api/v1/sonarqubes_controller_spec.rb new file mode 100644 index 000000000..ce71590c4 --- /dev/null +++ b/spec/controllers/api/v1/sonarqubes_controller_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe Api::V1::SonarqubesController, type: :controller do + +end diff --git a/spec/helpers/api/v1/sonarqubes_helper_spec.rb b/spec/helpers/api/v1/sonarqubes_helper_spec.rb new file mode 100644 index 000000000..9021add1e --- /dev/null +++ b/spec/helpers/api/v1/sonarqubes_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::SonarqubesHelper. For example: +# +# describe Api::V1::SonarqubesHelper 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::SonarqubesHelper, type: :helper do + pending "add some examples to (or delete) #{__FILE__}" +end