From 85b0643a9f4ab240fa0b0f550d52737efebe5598 Mon Sep 17 00:00:00 2001 From: Joe Mancuso Date: Wed, 20 Nov 2024 19:27:51 -0500 Subject: [PATCH] Refine Radon analysis workflow to accurately match methods with changed lines and avoid duplicates --- .github/workflows/radon-anylsis-granular.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/radon-anylsis-granular.yml b/.github/workflows/radon-anylsis-granular.yml index c5ba2d6e..e14560be 100644 --- a/.github/workflows/radon-anylsis-granular.yml +++ b/.github/workflows/radon-anylsis-granular.yml @@ -39,18 +39,26 @@ jobs: RESULTS="" for FILE in $CHANGED_FILES; do echo "Processing file: $FILE" - METHODS=$(radon cc $FILE -s | awk '/^ / {print $NF}') + + # Get method names and their line numbers + METHODS=$(radon cc $FILE -s | grep -oP "^\s*\d+.*\K[^\(]+" || true) echo "Methods found: $METHODS" - # Map changes to specific methods + # Extract the lines that are changed in this file while IFS= read -r LINE; do if [[ $LINE == *"$FILE"* ]]; then LINE_NUMBER=$(echo $LINE | grep -oP '(?<=\+)\d+') + + # Match the method based on line number MATCHING_METHOD=$(radon cc $FILE -s | awk -v line=$LINE_NUMBER '{ if ($1 ~ /^[0-9]+:/ && $1 <= line) method=$NF; if ($1 > line) { print method; exit } }') - RESULTS+="$MATCHING_METHOD (in $FILE)\n" + + # Append method results + if [[ ! " ${RESULTS[@]} " =~ " ${MATCHING_METHOD} " ]]; then + RESULTS+="$MATCHING_METHOD\n" + fi fi done <<< "$(cat changed_lines.diff)" done