<commit_before>require 'inch_ci/worker/project/build/handle_worker_output'
require 'inch_ci/gossip'
require 'open3'
require 'json'

module InchCI
  module Worker
    module Project
      # The Build worker is responsible for "building" projects,
      # i.e. cloning and analysing repos, by utilizing a gem called
      # "inch_ci-worker".
      module BuildJSON
        # @return [Build]
        def self.enqueue(filename, trigger = nil)
          # this is invoked from the inch_ci-worker gem
          json = InchCI::Worker::BuildJSON.json(filename)
          if trigger.nil?
            trigger = 'ci'
            trigger = 'travis' if json.travis?
            trigger = 'circleci' if json.circleci?
          end

          if json.url
            branch = Store::EnsureProjectAndBranch.call(json.url, json.branch_name)
            build = Store::CreateBuild.call(branch, trigger)
            Gossip.new_build(build, build.project, build.branch)
            ShellInvocation.perform_async(filename, json.url, json.branch_name, trigger, build.id)
            build
          end
        end

        # The ShellInvocation class spawns another shell in which the given
        # repo is analysed. The executed script then returns a YAML formatted
        # string which contains the "build data".<commit_msg>Add trigger 'shell' to builds<commit_after>require 'inch_ci/worker/project/build/handle_worker_output'
require 'inch_ci/gossip'
require 'open3'
require 'json'

module InchCI
  module Worker
    module Project
      # The Build worker is responsible for "building" projects,
      # i.e. cloning and analysing repos, by utilizing a gem called
      # "inch_ci-worker".
      module BuildJSON
        # @return [Build]
        def self.enqueue(filename, trigger = nil)
          # this is invoked from the inch_ci-worker gem
          json = InchCI::Worker::BuildJSON.json(filename)
          if trigger.nil?
            trigger = 'ci'
            trigger = 'shell' if json.shell?
            trigger = 'travis' if json.travis?
            trigger = 'circleci' if json.circleci?
          end

          if json.url
            branch = Store::EnsureProjectAndBranch.call(json.url, json.branch_name)
            build = Store::CreateBuild.call(branch, trigger)
            Gossip.new_build(build, build.project, build.branch)
            ShellInvocation.perform_async(filename, json.url, json.branch_name, trigger, build.id)
            build
          end
        end

        # The ShellInvocation class spawns another shell in which the given
        # repo is analysed. The executed script then returns a YAML formatted
        # string which contains the "build data".
{'fraction_non_alphanumeric': 0.08019395747855278, 'fraction_numerical': 0.0007459903021260724, 'mean_word_length': 2.348314606741573, 'pattern_counts': {'":': 0, '<': 3, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5094957', 'n_tokens_mistral': 735, 'n_tokens_neox': 728, 'n_words': 225}