@@ -8,53 +8,32 @@ url="https://api.github.com/repos/$owner_repository/pulls/$pr_number/files"
8
8
echo $url
9
9
10
10
# Get changes in boards.txt file from PR
11
- Patch =$( curl $url | jq -r ' .[] | select(.filename == "boards.txt") | .patch ' )
11
+ Boards_modified_url =$( curl -s $url | jq -r ' .[] | select(.filename == "boards.txt") | .raw_url ' )
12
12
13
- # Extract only changed lines number and count
14
- substring_patch=$( echo " $Patch " | grep -o ' @@[^@]*@@' )
13
+ # Echo the modified boards.txt file URL
14
+ echo " Modified boards.txt file URL:"
15
+ echo $Boards_modified_url
15
16
16
- params_array=()
17
+ # Download the modified boards.txt file
18
+ curl -L -o boards_pr.txt $Boards_modified_url
17
19
18
- IFS=$' \n ' read -d ' ' -ra params <<< $( echo " $substring_patch " | grep -oE ' [-+][0-9]+,[0-9]+' )
20
+ # Compare boards.txt file in the repo with the modified file
21
+ diff=$( diff -u boards.txt boards_pr.txt)
19
22
20
- for param in " ${params[@]} "
21
- do
22
- echo " The parameter is $param "
23
- params_array+=(" $param " )
24
- done
23
+ # Extract added or modified lines (lines starting with '+' or '-')
24
+ modified_lines=$( echo " $diff " | grep -E ' ^[+-][^+-]' )
25
25
26
26
boards_array=()
27
27
previous_board=" "
28
28
file=" boards.txt"
29
29
30
- # Loop through boards.txt file and extract all boards that were added
31
- for (( c = 0 ; c < ${ # params_array[@]} ; c += 2 ))
30
+ # Extract board names from the modified lines, and add them to the boards_array
31
+ while read -r line
32
32
do
33
- deletion_count=$( echo " ${params_array[c]} " | cut -d' ,' -f2 | cut -d' ' -f1 )
34
- addition_line=$( echo " ${params_array[c+1]} " | cut -d' +' -f2 | cut -d' ,' -f1 )
35
- addition_count=$( echo " ${params_array[c+1]} " | cut -d' +' -f2 | cut -d' ,' -f2 | cut -d' ' -f1 )
36
- addition_end=$(( $addition_line + $addition_count ))
37
-
38
- addition_line=$(( $addition_line + 3 ))
39
- addition_end=$(( $addition_end - $deletion_count ))
40
-
41
- echo $addition_line
42
- echo $addition_end
43
-
44
- i=0
45
-
46
- while read -r line
47
- do
48
- i=$(( i+ 1 ))
49
- if [ $i -lt $addition_line ]
50
- then
51
- continue
52
- elif [ $i -gt $addition_end ]
53
- then
54
- break
55
- fi
56
33
board_name=$( echo " $line " | cut -d ' .' -f1 | cut -d ' #' -f1)
57
- if [ " $board_name " != " " ] && [ " $board_name " != " esp32_family" ]
34
+ # remove + or - from the board name at the beginning
35
+ board_name=$( echo " $board_name " | sed ' s/^[+-]//' )
36
+ if [ " $board_name " != " " ] && [ " $board_name " != " +" ] && [ " $board_name " != " -" ] && [ " $board_name " != " esp32_family" ]
58
37
then
59
38
if [ " $board_name " != " $previous_board " ]
60
39
then
63
42
echo " Added 'espressif:esp32:$board_name ' to array"
64
43
fi
65
44
fi
66
- done < " $file "
67
- done
45
+ done <<< " $modified_lines"
68
46
69
47
# Create JSON like string with all boards found and pass it to env variable
70
48
board_count=${# boards_array[@]}
0 commit comments