All files / app/assets/javascripts/diffs/utils suggestions.js

100% Statements 13/13
66.66% Branches 4/6
100% Functions 5/5
100% Lines 13/13

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  22x 111x     111x 101x     111x     22x       22x 22x 101x   22x   22x 100x   100x      
function removeEmptyProperties(dict) {
  const noBlanks = Object.entries(dict).reduce((final, [key, value]) => {
    const upd = { ...final };
 
    // The number 0 shouldn't be falsey when we're printing variables
    if (value || value === 0) {
      upd[key] = value;
    }
 
    return upd;
  }, {});
 
  return noBlanks;
}
 
export function computeSuggestionCommitMessage({ message, values = {} } = {}) {
  const noEmpties = removeEmptyProperties(values);
  const matchPhrases = Object.keys(noEmpties)
    .map((key) => `%{${key}}`)
    .join('|');
  const replacementExpression = new RegExp(`(${matchPhrases})`, 'gm');
 
  return message.replace(replacementExpression, (match) => {
    const key = match.replace(/(^%{|}$)/gm, '');
 
    return noEmpties[key];
  });
}