|
|
|
@@ -1,15 +1,62 @@ |
|
|
|
class Api::V1::SonarqubesController < Api::V1::BaseController |
|
|
|
before_action :load_repository |
|
|
|
def sonar_initialize |
|
|
|
gitea_params = { has_actions: true } |
|
|
|
Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) |
|
|
|
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 execute_sonar_sanner |
|
|
|
def insert_file |
|
|
|
sonar_scanner_content = { |
|
|
|
filepath: '.gitea/workflows/SonarScanner.yaml', |
|
|
|
branch: params[:branch], |
|
|
|
new_branch: nil, |
|
|
|
content: 'b246CiAgIyBUcmlnZ2VyIGFuYWx5c2lzIHdoZW4gcHVzaGluZyB0byB5b3VyIG1haW4gYnJhbmNoZXMsIGFuZCB3aGVuIGNyZWF0aW5nIGEgcHVsbCByZXF1ZXN0LgogIHB1c2g6CiAgICBicmFuY2hlczoKICAgICAgLSBtYWluCiAgICAgIC0gbWFzdGVyCiAgICAgIC0gZGV2ZWxvcAogICAgICAtICdyZWxlYXNlcy8qKicKICBwdWxsX3JlcXVlc3Q6CiAgICAgIHR5cGVzOiBbb3BlbmVkLCBzeW5jaHJvbml6ZSwgcmVvcGVuZWRdCgpuYW1lOiBNYWluIFdvcmtmbG93CmpvYnM6CiAgc29uYXJxdWJlOgogICAgcnVucy1vbjogdWJ1bnR1LWxhdGVzdAogICAgc3RlcHM6CiAgICAtIHVzZXM6IGFjdGlvbnMvY2hlY2tvdXRAdjQKICAgICAgd2l0aDoKICAgICAgICAjIERpc2FibGluZyBzaGFsbG93IGNsb25lcyBpcyByZWNvbW1lbmRlZCBmb3IgaW1wcm92aW5nIHRoZSByZWxldmFuY3kgb2YgcmVwb3J0aW5nCiAgICAgICAgZmV0Y2gtZGVwdGg6IDAKICAgIC0gbmFtZTogU29uYXJRdWJlIFNjYW4KICAgICAgdXNlczogc29uYXJzb3VyY2Uvc29uYXJxdWJlLXNjYW4tYWN0aW9uQG1hc3RlcgogICAgICBlbnY6CiAgICAgICAgU09OQVJfVE9LRU46ICR7eyBzZWNyZXRzLlNPTkFSX1RPS0VOIH19CiAgICAgICAgU09OQVJfSE9TVF9VUkw6ICAke3sgc2VjcmV0cy5TT05BUl9IT1NUX1VSTCB9fQ==', |
|
|
|
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=.", |
|
|
|
"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[:components], |
|
|
|
|