Skip to content

Commit

Permalink
feat: add defect statistics - console output
Browse files Browse the repository at this point in the history
  • Loading branch information
jamacku committed Aug 10, 2023
1 parent df0d402 commit 9624cf7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ get_fixes () {
# $? - return value is always 0
evaluate_and_print_fixes () {
if [[ -s ../fixes.log ]]; then
gather_statistics "../defects.log"
print_statistics

echo -e "${GREEN}Fixed defects${NOCOLOR}"
csgrep ../fixes.log
else
Expand All @@ -40,10 +43,49 @@ get_defects () {
# $? - return value - 0 on success
evaluate_and_print_defects () {
if [[ -s ../defects.log ]]; then
gather_statistics "../defects.log"
print_statistics

echo -e "${YELLOW}Defects, NEEDS INSPECTION${NOCOLOR}"
csgrep ../defects.log
return 1
fi

echo -e "🥳 ${GREEN}No defects added. Yay!${NOCOLOR}"
}

print_statistics () {
echo -e "::group::📊 ${WHITE}Statistics${NOCOLOR}"

Check warning

Code scanning / shellcheck

WHITE is referenced but not assigned. Warning

WHITE is referenced but not assigned.
[[ -n ${stat_style} ]] && echo -e "Style: ${stat_style}"
[[ -n ${stat_note} ]] && echo -e "Note: ${stat_note}"
[[ -n ${stat_warning} ]] && echo -e "Warning: ${stat_warning}"
[[ -n ${stat_error} ]] && echo -e "Error: ${stat_error}"
echo "::endgroup::"
echo
}

# Function to filter out defects by their severity level
gather_statistics () {
[[ $# -le 0 ]] && return 1
local logs="$1"

[[ ${INPUT_SEVERITY-} == "style" ]] && stat_style=$(get_number_of_defects_by_severity "style" "${logs}")
[[ ${INPUT_SEVERITY} =~ style|note ]] && stat_note=$(get_number_of_defects_by_severity "note" "${logs}")
[[ ${INPUT_SEVERITY} =~ style|note|warning ]] && stat_warning=$(get_number_of_defects_by_severity "warning" "${logs}")
[[ ${INPUT_SEVERITY} =~ style|note|warning|error ]] && stat_error=$(get_number_of_defects_by_severity "error" "${logs}")

export stat_style stat_note stat_warning stat_error
}

get_number_of_defects_by_severity () {
[[ $# -le 1 ]] && return 1
local severity="$1"
local logs="$2"
local defects=0

# echo "get_number_of_defects_by_severity logs:"
# cat "${logs}"

defects=$(grep -c -E "^[^:]+:[0-9]+:[0-9]+: ${severity}.*\[SC[0-9]+\].*$" <<< "${logs}")
echo "${defects}"
}

0 comments on commit 9624cf7

Please sign in to comment.