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 Apr 7, 2023
1 parent 6a6ac89 commit 7fc9195
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 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,44 @@ 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 "📊 ${WHITE}Statistics${NOCOLOR}"
echo -e " ${WHITE}Style${NOCOLOR}: ${stat_style}"
echo -e " ${WHITE}Note${NOCOLOR}: ${stat_note}"
echo -e " ${WHITE}Warning${NOCOLOR}: ${stat_warning}"
echo -e " ${WHITE}Error${NOCOLOR}: ${stat_error}"
}

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

[[ ${INPUT_SEVERITY-} =~ style|note|warning|error ]] && stat_style=$(get_number_of_defects_by_severity "style" "${logs}")
[[ ${INPUT_SEVERITY} =~ note|warning|error ]] && stat_note=$(get_number_of_defects_by_severity "note" "${logs}")
[[ ${INPUT_SEVERITY} =~ warning|error ]] && stat_warning=$(get_number_of_defects_by_severity "warning" "${logs}")
[[ ${INPUT_SEVERITY} == "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

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

0 comments on commit 7fc9195

Please sign in to comment.