All files / packages/icons/.claude/skills/icons-release/scripts/lib classify.js

0% Statements 0/21
0% Branches 0/18
0% Functions 0/4
0% Lines 0/21

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88                                                                                                                                                                               
'use strict'
 
const { mapCsvType, parseConvert } = require('./types')
 
const ELIGIBLE_STATUS = 'handed to eng'
 
function isEligibleStatus(designStatus) {
  return String(designStatus || '')
    .toLowerCase()
    .includes(ELIGIBLE_STATUS)
}
 
function isCancelled(designStatus) {
  return String(designStatus || '')
    .toLowerCase()
    .includes('cancel')
}
 
function isAssetSubmitted(assetSubmitted) {
  return String(assetSubmitted || '').toLowerCase().trim() === 'yes'
}
 
/**
 * Classify a single CSV row (already extracted into a plain object with
 * name/designStatus/iconType/assetSubmitted fields) into exactly one bucket.
 *
 * Precedence (locked):
 *   1. Design Status not "Handed to Eng."  -> ineligible (ineligibleStatus | unknownStatus)
 *   2. Icon Type "Convert existing"         -> convert (target type resolved)
 *   3. Asset submitted != Yes               -> ineligible (assetNotSubmitted)
 *   4. Icon Type unmappable                 -> ineligible (unmappableType)
 *   5. otherwise                            -> eligible
 *
 * Returns { bucket, type, reason, detail, source }.
 *   bucket: 'eligible' | 'ineligible' | 'convert'
 *   For 'convert', `type` is the TARGET repo type and `source` the origin set.
 */
function classifyRow(row) {
  if (!isEligibleStatus(row.designStatus)) {
    if (isCancelled(row.designStatus)) {
      return {
        bucket: 'ineligible',
        reason: 'ineligibleStatus',
        detail: `Design Status = "${row.designStatus}"`
      }
    }
    return {
      bucket: 'ineligible',
      reason: 'unknownStatus',
      detail: `No "Handed to Eng." label (found "${row.designStatus}")`
    }
  }
 
  const convert = parseConvert(row.iconType)
  if (convert) {
    if (!convert.target) {
      return {
        bucket: 'ineligible',
        reason: 'convertTargetUnknown',
        detail: `Could not parse a target type from "${row.iconType}"`
      }
    }
    return { bucket: 'convert', type: convert.target, source: convert.source }
  }
 
  const type = mapCsvType(row.iconType)
 
  if (!isAssetSubmitted(row.assetSubmitted)) {
    return {
      bucket: 'ineligible',
      reason: 'assetNotSubmitted',
      detail: `Asset submitted = "${row.assetSubmitted}"`
    }
  }
 
  if (!type) {
    return {
      bucket: 'ineligible',
      reason: 'unmappableType',
      detail: `Icon Type "${row.iconType}" not recognized`
    }
  }
 
  return { bucket: 'eligible', type }
}
 
module.exports = { classifyRow, isEligibleStatus, isCancelled, isAssetSubmitted }