Browse Source

sonar 转发接口

pull/347/head
kingChan 2 years ago
parent
commit
c98c7d5ac5
10 changed files with 81 additions and 5 deletions
  1. +1
    -0
      Gemfile
  2. +7
    -0
      Gemfile.lock
  3. +2
    -0
      app/assets/javascripts/api/v1/sonarqubes.js
  4. +3
    -0
      app/assets/stylesheets/api/v1/sonarqubes.scss
  5. +0
    -4
      app/controllers/api/v1/projects_controller.rb
  6. +40
    -0
      app/controllers/api/v1/sonarqubes_controller.rb
  7. +2
    -0
      app/helpers/api/v1/sonarqubes_helper.rb
  8. +6
    -1
      config/routes/api.rb
  9. +5
    -0
      spec/controllers/api/v1/sonarqubes_controller_spec.rb
  10. +15
    -0
      spec/helpers/api/v1/sonarqubes_helper_spec.rb

+ 1
- 0
Gemfile View File

@@ -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


+ 7
- 0
Gemfile.lock View File

@@ -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)


+ 2
- 0
app/assets/javascripts/api/v1/sonarqubes.js View File

@@ -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.

+ 3
- 0
app/assets/stylesheets/api/v1/sonarqubes.scss View File

@@ -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/

+ 0
- 4
app/controllers/api/v1/projects_controller.rb View File

@@ -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)


+ 40
- 0
app/controllers/api/v1/sonarqubes_controller.rb View File

@@ -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

+ 2
- 0
app/helpers/api/v1/sonarqubes_helper.rb View File

@@ -0,0 +1,2 @@
module Api::V1::SonarqubesHelper
end

+ 6
- 1
config/routes/api.rb View File

@@ -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



+ 5
- 0
spec/controllers/api/v1/sonarqubes_controller_spec.rb View File

@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe Api::V1::SonarqubesController, type: :controller do

end

+ 15
- 0
spec/helpers/api/v1/sonarqubes_helper_spec.rb View File

@@ -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

Loading…
Cancel
Save