<commit_before>module Fastlane
  module Actions
    module SharedValues
    end

    class DownloadJenkinsArtifactsAction < Action
      def self.run(params)
        # fastlane will take care of reading in the parameter and fetching the environment variable:
        UI.important("Downloading artifacts from job \"http://#{params[:server_url]}/job/#{params[:job_name]}/#{params[:job_number]}\"")
        UI.important("Downloading artifacts that match \"#{params[:apk_regex]}\"")

        # Call endpoint
        response = build(
            params[:server_url],
            params[:job_name],
            params[:job_number]
        )

        # Match artifacts and download
        download_artifacts(
            params[:server_url],
            params[:job_name],
            params[:job_number],
            params[:downloads_dir],
            params[:apk_regex],
            get_artifacts_from_response(response)
        )
      end

      def self.get_artifacts_from_response(response)
        require 'json'

        return JSON.parse(response[:body])['artifacts']
      end

      def self.download_artifacts(server_url, job_name, job_number, downloads_dir, apk_regex, artifacts)
        for artifact in artifacts do
          if artifact['fileName'].match(apk_regex)
            download_artifact("http://#{server_url}/job/#{job_name}/#{job_number}", downloads_dir, artifact)
          end
        end
      end

      def self.download_artifact(url, downloads_dir, artifact)
        UI.important("Downloading #{artifact['fileName']}...")

        require 'open-uri'

        open("#{downloads_dir}/#{artifact['fileName']}", "wb") do |file|
          file << open("#{url}/artifact/#{artifact['relativePath']}").read
        end
      end

      def self.call_endpoint(url, method)
        require 'excon'

        case method
          when 'get'
            response = Excon.get(url)
          else
            UI.user_error!("Unsupported method #{method}")
        end
<commit_msg>Return a list of files downloaded from Action<commit_after>module Fastlane
  module Actions
    module SharedValues
    end

    class DownloadJenkinsArtifactsAction < Action
      def self.run(params)
        # fastlane will take care of reading in the parameter and fetching the environment variable:
        UI.important("Downloading artifacts from job \"http://#{params[:server_url]}/job/#{params[:job_name]}/#{params[:job_number]}\"")
        UI.important("Downloading artifacts that match \"#{params[:apk_regex]}\"")

        # Call endpoint
        response = build(
            params[:server_url],
            params[:job_name],
            params[:job_number]
        )

        # Match artifacts and download
        files = download_artifacts(
            params[:server_url],
            params[:job_name],
            params[:job_number],
            params[:downloads_dir],
            params[:apk_regex],
            get_artifacts_from_response(response)
        )

        files
      end

      def self.get_artifacts_from_response(response)
        require 'json'

        return JSON.parse(response[:body])['artifacts']
      end

      def self.download_artifacts(server_url, job_name, job_number, downloads_dir, apk_regex, artifacts)
        files = []

        for artifact in artifacts do
          if artifact['fileName'].match(apk_regex)
            files << download_artifact("http://#{server_url}/job/#{job_name}/#{job_number}", downloads_dir, artifact)
          end
        end

        files
      end

      def self.download_artifact(url, downloads_dir, artifact)
        UI.important("Downloading #{artifact['fileName']}...")

        require 'open-uri'

        filename = "#{downloads_dir}/#{artifact['fileName']}"
        open(filename, 'wb') do |file|
          file << open("#{url}/artifact/#{artifact['relativePath']}").read
        end

        filename
      end

      def self.call_endpoint(url, method)
        require 'excon'

        case method
          when 'get'
            response = Excon.get(url)
          else
            UI.user_error!("Unsupported method #{method}")
        end

{'fraction_non_alphanumeric': 0.11353183248608086, 'fraction_numerical': 0.0, 'mean_word_length': 2.3188755020080323, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 29, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6605268', 'n_tokens_mistral': 1156, 'n_tokens_neox': 1100, 'n_words': 243}