All files / app/assets/javascripts/reports/codequality_report/store getters.js

100% Statements 23/23
95% Branches 19/20
100% Functions 4/4
100% Lines 23/23

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        6x 23x   6x 279x 140x   139x 127x     12x     6x 24x   24x 15x 9x 3x           6x 3x 3x 3x     24x     6x 16x 3x                       13x    
import { spriteIcon } from '~/lib/utils/common_utils';
import { sprintf, s__ } from '~/locale';
import { LOADING, ERROR, SUCCESS, STATUS_NOT_FOUND } from '../../constants';
 
export const hasCodequalityIssues = (state) =>
  Boolean(state.newIssues?.length || state.resolvedIssues?.length);
 
export const codequalityStatus = (state) => {
  if (state.isLoading) {
    return LOADING;
  }
  if (state.hasError) {
    return ERROR;
  }
 
  return SUCCESS;
};
 
export const codequalityText = (state) => {
  const { newIssues, resolvedIssues } = state;
  let text;
  if (!newIssues.length && !resolvedIssues.length) {
    text = s__('ciReport|No changes to code quality');
  } else if (newIssues.length && resolvedIssues.length) {
    text = sprintf(
      s__(`ciReport|Code quality scanning detected %{issueCount} changes in merged results`),
      {
        issueCount: newIssues.length + resolvedIssues.length,
      },
    );
  } else if (resolvedIssues.length) {
    text = s__(`ciReport|Code quality improved`);
  } else Eif (newIssues.length) {
    text = s__(`ciReport|Code quality degraded`);
  }
 
  return text;
};
 
export const codequalityPopover = (state) => {
  if (state.status === STATUS_NOT_FOUND) {
    return {
      title: s__('ciReport|Base pipeline codequality artifact not found'),
      content: sprintf(
        s__('ciReport|%{linkStartTag}Learn more about codequality reports %{linkEndTag}'),
        {
          linkStartTag: `<a href="${state.helpPath}" target="_blank" rel="noopener noreferrer">`,
          linkEndTag: `${spriteIcon('external-link', 's16')}</a>`,
        },
        false,
      ),
    };
  }
  return {};
};