<commit_before>import { getProjectUrl, getRunnableJobsURL } from '../helpers/url';
import { escapeId } from '../helpers/aggregateId';

import JobModel from './job';

export default class RunnableJobModel {
  constructor(data) {
    Object.assign(this, data);
  }

  static async getList(repoName, params) {
    let uri = getRunnableJobsURL(params.decision_task_id);
    let rawJobs = await fetch(uri).then(response => response.json());
    const jobList = [];

    // TODO: Remove this fallback once the gz artifacts expire
    if (rawJobs.code === 'ResourceNotFound') {
      uri = getProjectUrl('/runnable_jobs/');
      rawJobs = await JobModel.getList(repoName, params, { uri });
      rawJobs.forEach(job => {
        job.push_id = params.push_id;
        job.id = escapeId(params.push_id + job.ref_data_name);
      });
      return rawJobs;
    }

    Object.entries(rawJobs).forEach(([key, value]) => {
      jobList.push({
        build_platform: value.platform || '',
        build_system_type: 'taskcluster',
        job_group_name: value.groupName || '',
        job_group_symbol: value.groupSymbol || '',
        job_type_name: key,
        job_type_symbol: value.symbol,
        platform: value.platform || '',
        platform_option: Object.keys(value.collection).join(' '),
        ref_data_name: key,
        state: 'runnable',
        result: 'runnable',
        push_id: params.push_id,
        id: escapeId(params.push_id + key),
      });
    });
    return jobList;
  }
}<commit_msg>Bug 1513902 - Fix filtering with add new jobs (#4372)<commit_after>import { getProjectUrl, getRunnableJobsURL } from '../helpers/url';
import { escapeId } from '../helpers/aggregateId';

import JobModel from './job';

export default class RunnableJobModel {
  constructor(data) {
    Object.assign(this, data);
  }

  static async getList(repoName, params) {
    let uri = getRunnableJobsURL(params.decision_task_id);
    let rawJobs = await fetch(uri).then(response => response.json());

    // TODO: Remove this fallback once the gz artifacts expire
    if (rawJobs.code === 'ResourceNotFound') {
      uri = getProjectUrl('/runnable_jobs/');
      rawJobs = await JobModel.getList(repoName, params, { uri });
      rawJobs.forEach(job => {
        job.push_id = params.push_id;
        job.id = escapeId(params.push_id + job.ref_data_name);
      });
      return rawJobs;
    }

    return Object.entries(rawJobs).map(
      ([key, value]) =>
        new JobModel({
          build_platform: value.platform || '',
          build_system_type: 'taskcluster',
          job_group_name: value.groupName || '',
          job_group_symbol: value.groupSymbol || '',
          job_type_name: key,
          job_type_symbol: value.symbol,
          platform: value.platform || '',
          platform_option: Object.keys(value.collection).join(' '),
          ref_data_name: key,
          state: 'runnable',
          result: 'runnable',
          push_id: params.push_id,
          id: escapeId(params.push_id + key),
        }),
    );
  }
}
{'fraction_non_alphanumeric': 0.13333333333333333, 'fraction_numerical': 0.00361247947454844, 'mean_word_length': 2.751231527093596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '6241229', 'n_tokens_mistral': 966, 'n_tokens_neox': 928, 'n_words': 193}