<commit_before>'use script';

const unifiedList = require('./resources/default-unifiedlist.json');

function check (xmlObject) {
  // gets the licenses found in the following format:
  // [{ name: 'roi', version: '0.15.0', license: 'Apache-2.0' }]
  const licensesFound = xmlObject.licenses.license.map((e) => {
    return { name: e.name, version: e.version, license: e.license, approved: 'false' };
  });

  // gets the approved and not approved licenses from the default unified list.
  const approvedList = [];
  const notApprovedList = [];
  Object.keys(unifiedList).forEach(key => {
    if (unifiedList[key].approved === 'yes') {
      approvedList.push(unifiedList[key]);
    } else {
      notApprovedList.push(unifiedList[key]);
    }
  });

  // checks the licenses found against properties of approved list
  // to verify if the license name is found.
  const approvedFound = new Set();
  approvedList.forEach((a) => {
    licensesFound.forEach((lf) => {
      if (lf.license === a['fedora_abbrev'] ||
        lf.license === a['fedora_name'] ||
        lf.license === a['spdx_abbrev'] ||
        lf.license === a['spdx_name']) {
        approvedFound.add(lf);
      }
    });
  });

  // checks the licenses found against properties of not approved list
  // to verify if the license name is found.
  const notApprovedFound = new Set();
  notApprovedList.forEach((a) => {
    licensesFound.forEach((lf) => {
      if (lf.license === a['fedora_abbrev'] ||
        lf.license === a['fedora_name'] ||
        lf.license === a['spdx_abbrev'] ||
        lf.license === a['spdx_name'] ||
        lf.license.indexOf('*') === lf.license.length - 1) {
        notApprovedFound.add(lf);
      }
    });
  });

  if (approvedFound.size > 0) {
    console.error(`========= APPROVED LICENSES ==========`);
    Array.from(new Set(approvedFound)).forEach((license) => {
      console.log('name:', license.name,
           ', version:', license.version,
           ', licenses:', license.license);
    });
    console.error(`========= APPROVED LICENSES ==========`);
  }

  if (notApprovedFound.size > 0) {
    console.error(`========= NOT APPROVED LICENSES ==========`);
    Array.from(new Set(notApprovedFound)).forEach((license) => {
      console.log('name:', license.name,
           ', version:', license.version,
           ', licenses:', license.license);
    });
    console.error(`========= NOT APPROVED LICENSES ==========`);
  }<commit_msg>src: make approved warnings message consistent<commit_after>'use script';

const unifiedList = require('./resources/default-unifiedlist.json');

function check (xmlObject) {
  // gets the licenses found in the following format:
  // [{ name: 'roi', version: '0.15.0', license: 'Apache-2.0' }]
  const licensesFound = xmlObject.licenses.license.map((e) => {
    return { name: e.name, version: e.version, license: e.license, approved: 'false' };
  });

  // gets the approved and not approved licenses from the default unified list.
  const approvedList = [];
  const notApprovedList = [];
  Object.keys(unifiedList).forEach(key => {
    if (unifiedList[key].approved === 'yes') {
      approvedList.push(unifiedList[key]);
    } else {
      notApprovedList.push(unifiedList[key]);
    }
  });

  // checks the licenses found against properties of approved list
  // to verify if the license name is found.
  const approvedFound = new Set();
  approvedList.forEach((a) => {
    licensesFound.forEach((lf) => {
      if (lf.license === a['fedora_abbrev'] ||
        lf.license === a['fedora_name'] ||
        lf.license === a['spdx_abbrev'] ||
        lf.license === a['spdx_name']) {
        approvedFound.add(lf);
      }
    });
  });

  // checks the licenses found against properties of not approved list
  // to verify if the license name is found.
  const notApprovedFound = new Set();
  notApprovedList.forEach((a) => {
    licensesFound.forEach((lf) => {
      if (lf.license === a['fedora_abbrev'] ||
        lf.license === a['fedora_name'] ||
        lf.license === a['spdx_abbrev'] ||
        lf.license === a['spdx_name'] ||
        lf.license.indexOf('*') === lf.license.length - 1) {
        notApprovedFound.add(lf);
      }
    });
  });

  if (approvedFound.size > 0) {
    console.error(`========= APPROVED LICENSES        ==========`);
    Array.from(new Set(approvedFound)).forEach((license) => {
      console.log('name:', license.name,
           ', version:', license.version,
           ', licenses:', license.license);
    });
    console.error(`========= APPROVED LICENSES        ==========`);
  }

  if (notApprovedFound.size > 0) {
    console.error(`========= NOT APPROVED LICENSES    ==========`);
    Array.from(new Set(notApprovedFound)).forEach((license) => {
      console.log('name:', license.name,
           ', version:', license.version,
           ', licenses:', license.license);
    });
    console.error(`========= NOT APPROVED LICENSES    ==========`);
  }
{'fraction_non_alphanumeric': 0.19150657229524773, 'fraction_numerical': 0.003640040444893832, 'mean_word_length': 3.027687296416938, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '6018225', 'n_tokens_mistral': 1551, 'n_tokens_neox': 1499, 'n_words': 331}