diff --git a/app/controllers/api/v1/sonarqubes_controller.rb b/app/controllers/api/v1/sonarqubes_controller.rb index d42593a33..e81e2a4b4 100644 --- a/app/controllers/api/v1/sonarqubes_controller.rb +++ b/app/controllers/api/v1/sonarqubes_controller.rb @@ -15,11 +15,40 @@ class Api::V1::SonarqubesController < Api::V1::BaseController end def insert_file + config = Rails.application.config_for(:configuration) + sonarqube_config = config.dig('sonarqube') + sonar_scanner_content = { filepath: '.gitea/workflows/SonarScanner.yaml', branch: params[:branch], new_branch: nil, - content: 'b246CiAgIyBUcmlnZ2VyIGFuYWx5c2lzIHdoZW4gcHVzaGluZyB0byB5b3VyIG1haW4gYnJhbmNoZXMsIGFuZCB3aGVuIGNyZWF0aW5nIGEgcHVsbCByZXF1ZXN0LgogIHB1c2g6CiAgICBicmFuY2hlczoKICAgICAgLSBtYWluCiAgICAgIC0gbWFzdGVyCiAgICAgIC0gZGV2ZWxvcAogICAgICAtICdyZWxlYXNlcy8qKicKICBwdWxsX3JlcXVlc3Q6CiAgICAgIHR5cGVzOiBbb3BlbmVkLCBzeW5jaHJvbml6ZSwgcmVvcGVuZWRdCgpuYW1lOiBNYWluIFdvcmtmbG93CmpvYnM6CiAgc29uYXJxdWJlOgogICAgcnVucy1vbjogdWJ1bnR1LWxhdGVzdAogICAgc3RlcHM6CiAgICAtIHVzZXM6IGh0dHBzOi8vZ2l0bGluay5vcmcuY24vS2luZ0NoYW4vY2hlY2tvdXRAdjQKICAgICAgd2l0aDoKICAgICAgICAjIERpc2FibGluZyBzaGFsbG93IGNsb25lcyBpcyByZWNvbW1lbmRlZCBmb3IgaW1wcm92aW5nIHRoZSByZWxldmFuY3kgb2YgcmVwb3J0aW5nCiAgICAgICAgZmV0Y2gtZGVwdGg6IDAKICAgIC0gbmFtZTogU29uYXJRdWJlIFNjYW4KICAgICAgdXNlczogaHR0cHM6Ly9naXRsaW5rLm9yZy5jbi9LaW5nQ2hhbi9zb25hcnF1YmUtc2Nhbi1hY3Rpb25AbWFzdGVyCiAgICAgIGVudjoKICAgICAgICBTT05BUl9UT0tFTjogJHt7IHNlY3JldHMuU09OQVJfVE9LRU4gfX0KICAgICAgICBTT05BUl9IT1NUX1VSTDogICR7eyBzZWNyZXRzLlNPTkFSX0hPU1RfVVJMIH19', + content: " + on: + # Trigger analysis when pushing to your main branches, and when creating a pull request. + push: + branches: + - main + - master + - develop + - 'releases/**' + pull_request: + types: [opened, synchronize, reopened] + + name: Main Workflow + jobs: + sonarqube: + runs-on: ubuntu-latest + steps: + - uses: #{sonarqube_config['checkout']} + with: + # Disabling shallow clones is recommended for improving the relevancy of reporting + fetch-depth: 0 + - name: SonarQube Scan + uses: #{sonarqube_config['scanner']} + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + ", message: 'Add .gitea/workflows/SonarScanner.yaml', committer: { email: @owner.mail, @@ -30,9 +59,9 @@ class Api::V1::SonarqubesController < Api::V1::BaseController @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 + sonar_scanner_content[:content] = Base64.strict_encode64(sonar_scanner_content[:content]) Gitea::CreateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_scanner_content) end diff --git a/config/configuration.yml.example b/config/configuration.yml.example index c18cf544c..9d5294a76 100644 --- a/config/configuration.yml.example +++ b/config/configuration.yml.example @@ -56,6 +56,8 @@ default: &default sonarqube: url: '' secret: '' + checkout: '' + scanner: '' production: <<: *default