<commit_before>require "json"
require "./status"

class Input
  JSON.mapping(
    name: String,
    resource: String,
  )
end

class Job
  JSON.mapping(
    name: String,
    groups: Array(String?),
    paused: Bool?,
    next_build: Status?,
    finished_build: Status?,
    inputs: Array(Input)?,
  )
  @broken = Hash(String, Bool).new(false)
  setter broken

  def groups
    return [nil] if @groups.size == 0
    @groups
  end

  def clear_groups
    @groups = [] of String?
  end

  def running
    !!next_build
  end

  def broken
    @inputs.try do |inputs|
      return inputs.any? { |i| @broken[i.name] || @broken[i.resource] }
    end
    return false
  end

  def status
    paused.try do |p|
      return "paused_job" if p
    end
    finished_build.try do |build|
      build.status
    end
  end

  def self.all(client, job_url : String)
    response = client.get("/api/v1#{job_url}/jobs")
    begin
      Array(Job).from_json(response.body)
    rescue ex
      puts "EXCEPTION: #{job_url}"
      [] of Job
    end
  end
end
<commit_msg>Handle missing group field from concourse jobs<commit_after>require "json"
require "./status"

class Input
  JSON.mapping(
    name: String,
    resource: String,
  )
end

class Job
  JSON.mapping(
    name: String,
    groups: Array(String?)?,
    paused: Bool?,
    next_build: Status?,
    finished_build: Status?,
    inputs: Array(Input)?,
  )
  @broken = Hash(String, Bool).new(false)
  setter broken

  def groups
    return [nil] if @groups.nil? || @groups.not_nil!.size == 0
    @groups.not_nil!
  end

  def clear_groups
    @groups = [] of String?
  end

  def running
    !!next_build
  end

  def broken
    @inputs.try do |inputs|
      return inputs.any? { |i| @broken[i.name] || @broken[i.resource] }
    end
    return false
  end

  def status
    paused.try do |p|
      return "paused_job" if p
    end
    finished_build.try do |build|
      build.status
    end
  end

  def self.all(client, job_url : String)
    response = client.get("/api/v1#{job_url}/jobs")
    begin
      Array(Job).from_json(response.body)
    rescue ex
      puts "EXCEPTION: #{job_url}"
      [] of Job
    end
  end
end

{'fraction_non_alphanumeric': 0.11705069124423963, 'fraction_numerical': 0.0018433179723502304, 'mean_word_length': 2.51294498381877, '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': '6860324', 'n_tokens_mistral': 773, 'n_tokens_neox': 751, 'n_words': 205}