|
- class Api::V1::SonarqubesController < Api::V1::BaseController
- before_action :load_repository
- def sonar_initialize
- gitea_params = { has_actions: params[:has_actions] == 'true' ? true :false }
- gitea_setting = Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params)
- if gitea_setting['has_actions'] == true
- Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_HOST_URL', Rails.application.config_for(:configuration)['sonarqube']['url'] ).call
- Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_TOKEN', Rails.application.config_for(:configuration)['sonarqube']['secret'] ).call
- else
- Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_HOST_URL', Rails.application.config_for(:configuration)['sonarqube']['url'] ).destroy
- Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_TOKEN', Rails.application.config_for(:configuration)['sonarqube']['secret'] ).destroy
- end
- render_ok
- end
-
- def insert_file
- sonar_scanner_content = {
- filepath: '.gitea/workflows/SonarScanner.yaml',
- branch: params[:branch],
- new_branch: nil,
- content: 'b246CiAgIyBUcmlnZ2VyIGFuYWx5c2lzIHdoZW4gcHVzaGluZyB0byB5b3VyIG1haW4gYnJhbmNoZXMsIGFuZCB3aGVuIGNyZWF0aW5nIGEgcHVsbCByZXF1ZXN0LgogIHB1c2g6CiAgICBicmFuY2hlczoKICAgICAgLSBtYWluCiAgICAgIC0gbWFzdGVyCiAgICAgIC0gZGV2ZWxvcAogICAgICAtICdyZWxlYXNlcy8qKicKICBwdWxsX3JlcXVlc3Q6CiAgICAgIHR5cGVzOiBbb3BlbmVkLCBzeW5jaHJvbml6ZSwgcmVvcGVuZWRdCgpuYW1lOiBNYWluIFdvcmtmbG93CmpvYnM6CiAgc29uYXJxdWJlOgogICAgcnVucy1vbjogdWJ1bnR1LWxhdGVzdAogICAgc3RlcHM6CiAgICAtIHVzZXM6IGh0dHBzOi8vZ2l0bGluay5vcmcuY24vS2luZ0NoYW4vY2hlY2tvdXRAdjQKICAgICAgd2l0aDoKICAgICAgICAjIERpc2FibGluZyBzaGFsbG93IGNsb25lcyBpcyByZWNvbW1lbmRlZCBmb3IgaW1wcm92aW5nIHRoZSByZWxldmFuY3kgb2YgcmVwb3J0aW5nCiAgICAgICAgZmV0Y2gtZGVwdGg6IDAKICAgIC0gbmFtZTogU29uYXJRdWJlIFNjYW4KICAgICAgdXNlczogaHR0cHM6Ly9naXRsaW5rLm9yZy5jbi9LaW5nQ2hhbi9zb25hcnF1YmUtc2Nhbi1hY3Rpb25AbWFzdGVyCiAgICAgIGVudjoKICAgICAgICBTT05BUl9UT0tFTjogJHt7IHNlY3JldHMuU09OQVJfVE9LRU4gfX0KICAgICAgICBTT05BUl9IT1NUX1VSTDogICR7eyBzZWNyZXRzLlNPTkFSX0hPU1RfVVJMIH19',
- message: 'Add .gitea/workflows/SonarScanner.yaml',
- committer: {
- email: @owner.mail,
- name: @owner.login
- },
- identifier: @project.identifier
- }
- @path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{params[:branch]}/"
- sonar_scanner_exit = Repositories::EntriesInteractor.call(@owner, @project.identifier, '.gitea/workflows/SonarScanner.yaml', ref: params[:branch])
- if sonar_scanner_exit.success?
- sonar_scanner_content[:content] = Base64.decode64(sonar_scanner_content[:content])
- Gitea::UpdateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_scanner_content.merge(sha:sonar_scanner_exit.result['sha']))
- else
- Gitea::CreateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_scanner_content)
- end
-
- sonar_project_content = {
- filepath: 'sonar-project.properties',
- branch: params[:branch],
- new_branch: nil,
- "content": "sonar.projectKey=#{params[:owner]}-#{params[:repo]}\nsonar.sources=.\nsonar.java.binaries=.",
- "message": 'Add sonar-project.properties',
- committer: {
- email: @owner.mail,
- name: @owner.login
- },
- identifier: @project.identifier
- }
- sonar_project_exit = Repositories::EntriesInteractor.call(@owner, @project.identifier, 'sonar-project.properties', ref: params[:branch])
- if sonar_project_exit.success?
- Gitea::UpdateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_project_content.merge(sha:sonar_project_exit.result['sha']))
- else
- sonar_project_content[:content] = Base64.strict_encode64(sonar_project_content[:content])
- Gitea::CreateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_project_content)
- end
- render_ok
- end
-
- def issues_search
- params_data = {
- components: "#{params[:owner]}-#{params[:repo]}",
- s: params[:s],
- impactSoftwareQualities: params[:impactSoftwareQualities],
- issueStatuses: params[:issueStatuses],
- ps: params[:ps],
- p: params[:p],
- facets: params[:facets],
- additionalFields: params[:additionalFields],
- timeZone: params[:timeZone],
- types: params[:types],
- impactSeverities: params[:impactSeverities],
- tags: params[:tags]
- }
- data = Sonarqube.client.get('/api/issues/search', query: params_data)
- render_ok data
- end
-
- def ce_component
- params_data = {
- components: "#{params[:owner]}-#{params[:repo]}",
- }
- data = Sonarqube.client.get('/api/ce/component', query: params_data)
- render_ok data
- end
-
- def sources_issue_snippet
- params_data = {
- issueKey: params[:issueKey]
- }
- data = Sonarqube.client.get('/api/sources/issue_snippets', query: params_data)
- render_ok data
- end
-
- def rules_show
- params_data = {
- key: params[:key]
- }
- data = Sonarqube.client.get('/api/rules/show', query: params_data)
- render_ok data
- end
-
- def measures_search_history
- params_data = {
- from: params[:form],
- component: "#{params[:owner]}-#{params[:repo]}",
- metrics: params[:metrics],
- ps: params[:ps]
- }
- data = Sonarqube.client.get('/api/measures/search_history', query: params_data)
- render_ok data
- end
-
- def measures_component
- params_data = {
- component: "#{params[:owner]}-#{params[:repo]}",
- additionalFields: params[:additionalFields],
- metricKeys: params[:metricKeys]
- }
- data = Sonarqube.client.get('/api/measures/component', query: params_data)
- render_ok data
- end
- end
|