forked from adoptium/aqa-test-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit_hunter.sh
More file actions
45 lines (37 loc) · 1.12 KB
/
commit_hunter.sh
File metadata and controls
45 lines (37 loc) · 1.12 KB
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
#!/usr/bin/env bash
#
# .github/scripts/commit_hunter.sh
#
# Arg1: the full GitHub comment body
#
set -euo pipefail
COMMENT="$1"
# 1) Remove leading /gitcompare line
BODY="${COMMENT#*\/gitcompare}"
# 2) Normalize Windows line endings
BODY="${BODY//$'\r'/}"
# 3) Split on the first line containing only dashes (allowing spaces)
# We use awk for robustness
GOOD=$(printf '%s\n' "$BODY" \
| awk 'BEGIN{sep="---"}
$0 ~ "^[[:space:]]*" sep "[[:space:]]*$" { exit }
{print}')
BAD=$(printf '%s\n' "$BODY" \
| awk 'BEGIN{sep="---"}
$0 ~ "^[[:space:]]*" sep "[[:space:]]*$" {found=1; next}
found {print}')
# 4) Trim blank lines
trim() { printf '%s\n' "$1" | sed '/^[[:space:]]*$/d'; }
GOOD=$(trim "$GOOD")
BAD=$(trim "$BAD")
# >>> Now you have two variables, GOOD and BAD, containing exactly what you need.
# For example:
echo "Comparing these SHAs from GOOD:"
echo "$GOOD" | grep -oE '[0-9a-f]{7,}'
echo
echo "…against BAD:"
echo "$BAD" | grep -oE '[0-9a-f]{7,}'
echo
# 5) Call your existing compare routine.
# Pass GOOD and BAD as multi-line arguments:
./commit_hunter_core.sh "$GOOD" "$BAD"