Skip to content

Commit 4619e7a

Browse files
author
Test
committed
- Removed loading of deprecated project.sh in summarize_commit and test_version_extraction bats files to improve maintenance.
- Updated test scripts structure to load necessary helper modules. - Enhanced existing project metadata extraction capabilities.
1 parent c3cd9a0 commit 4619e7a

File tree

7 files changed

+196
-194
lines changed

7 files changed

+196
-194
lines changed

src/giv.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ set -eu
88

99
IFS='
1010
'
11-
11+
GIV_DEBUG="${GIV_DEBUG:-}"
1212
# -------------------------------------------------------------------
1313
# Path detection for libraries, templates, and docs (POSIX compatible)
1414
# -------------------------------------------------------------------

src/history.sh

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,14 @@ build_history() {
154154
printf '### Commit ID %s\n' "$commit" >>"$hist"
155155
printf '**Date:** %s\n' "$(get_commit_date "$commit")" >>"$hist"
156156

157-
157+
print_debug "Getting version for commit $commit"
158158
ver=$(get_project_version "$commit")
159159
if [ -n "$ver" ]; then
160+
print_debug "Version found: $ver"
160161
printf '**Version:** %s\n' "$ver" >>"$hist"
161162
fi
162163

163-
164+
print_debug "Getting message header for commit $commit"
164165
msg=$(get_message_header "$commit")
165166
print_debug "Message header: $msg"
166167
printf '**Message:** %s\n' "$msg" >>"$hist"
@@ -266,7 +267,7 @@ summarize_commit() {
266267
print_debug "Temporary files created: hist=$hist, prompt=$pr, res_file=$res_file"
267268

268269
generate_commit_history "$hist" "$commit" "$pathspec"
269-
sc_version=$(get_commit_version "$commit")
270+
sc_version=$(get_project_version "$commit")
270271
print_debug "Commit version: $sc_version"
271272

272273
summary_template=$(build_commit_summary_prompt "$sc_version" "$hist")
@@ -358,21 +359,6 @@ save_commit_metadata() {
358359
printf 'Message: %s\n' "$(get_message_header "$commit")" >> "$metadata_file"
359360
}
360361

361-
# Function to get the version information for a given commit
362-
get_commit_version() {
363-
commit="$1"
364-
version_file="$(find_version_file)"
365-
366-
if [ -z "$version_file" ]; then
367-
print_debug "No version file found for commit: $commit"
368-
echo ""
369-
return
370-
fi
371-
372-
print_debug "Getting version info for commit $commit from $version_file"
373-
git show "$commit:$version_file" 2>/dev/null | grep -Eo 'version[[:space:]]*[:=][[:space:]]*"[^"]+"' | head -n 1 | sed -E 's/.*[:=][[:space:]]*"([^"]+)"/\1/'
374-
}
375-
376362
summarize_target() {
377363
target="$1"
378364
summaries_file="$2"

src/project/metadata.sh

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,19 @@ get_project_version() {
154154
fi
155155

156156
#print_debug "Using version function: $fn for project type: $project_type"
157-
158157
if command -v "$fn" >/dev/null 2>&1; then
159-
"$fn" "$commit"
158+
ver=""
159+
if ver_out=$("$fn" "$commit" 2>/dev/null); then
160+
ver="$ver_out"
161+
else
162+
#print_debug "Error: $fn failed to execute for commit $commit"
163+
ver=""
164+
fi
165+
#print_debug "Version extracted: $ver"
166+
printf '%s' "$ver"
167+
return 0
160168
else
161-
print_debug "Error: version function $fn not implemented for provider $project_type"
169+
#print_debug "Error: version function $fn not implemented for provider $project_type"
162170
printf ""
163171
return 0
164172
fi
@@ -169,6 +177,15 @@ get_project_version() {
169177
fi
170178
}
171179

180+
get_project_title() {
181+
# Returns the project title from metadata or defaults to directory name
182+
if [ -n "${GIV_METADATA_TITLE}" ]; then
183+
printf '%s' "${GIV_METADATA_TITLE}"
184+
else
185+
dirname=$(basename "$PWD")
186+
printf '%s' "$dirname"
187+
fi
188+
}
172189

173190
load_config_metadata(){
174191
# -------------------------

src/project/providers/provider_custom.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ provider_custom_get_version() {
3939
return 0
4040
fi
4141
# If file is JSON, extract "version" field (case-insensitive)
42-
if grep -i -q '"version"' "$GIV_VERSION_FILE" 2>/dev/null; then
43-
version=$(grep -i '"version"' "$GIV_VERSION_FILE" | sed -En 's/.*"[vV]ersion"[[:space:]]*:[[:space:]]*"([^\"]+)".*/\1/p' | head -n 1)
42+
if grep -i -q 'version' "$GIV_VERSION_FILE" 2>/dev/null; then
43+
#print_debug "Extracting version from file: $GIV_VERSION_FILE"
44+
version=$(grep -i 'version' "$GIV_VERSION_FILE" | sed -En 's/.*[vV]ersion"[[:space:]]*:[[:space:]]*([^\"]+)".*/\1/p' | head -n 1)
4445
# If version is empty or does not match a version pattern, fallback
45-
if [ -z "$version" ] || ! printf '%s' "$version" | grep -Eq '^[vV]?[0-9]+\.[0-9]+\.[0-9]+$'; then
46+
if [ -z "$version" ]; then
4647
parse_version "$(cat "$GIV_VERSION_FILE")"
4748
else
4849
printf '%s' "$version"
@@ -62,7 +63,7 @@ provider_custom_get_version_at_commit() {
6263
return 0
6364
fi
6465
# If file is JSON, extract "version" field (case-insensitive)
65-
if printf '%s' "$file_content" | grep -i -q '"version"'; then
66+
if printf '%s' "$file_content" | grep -i -q 'version'; then
6667
version=$(printf '%s' "$file_content" | grep -i '"version"' | sed -En 's/.*"[vV]ersion"[[:space:]]*:[[:space:]]*"([^\"]+)".*/\1/p' | head -n 1)
6768
# If version is empty or does not match a version pattern, fallback
6869
if [ -z "$version" ] || ! printf '%s' "$version" | grep -Eq '^[vV]?[0-9]+\.[0-9]+\.[0-9]+$'; then
@@ -89,7 +90,7 @@ provider_custom_get_version_at_commit() {
8990
# A string representing the extracted version number, or an empty string if no valid version
9091
# is found in the input.
9192
parse_version() {
92-
#printf 'Parsing version from: %s\n' "$1" >&2
93+
#print_debug "Parsing version from: $1"
9394
# Accepts a string, returns version like v1.2.3 or 1.2.3
9495
echo "$1" | sed -n -E "s/.*['\"]?([vV][0-9]+\.[0-9]+\.[0-9]+)['\"]?.*/\1/p;s/.*['\"]?([0-9]+\.[0-9]+\.[0-9]+)['\"]?.*/\1/p" | head -n 1
9596
}

0 commit comments

Comments
 (0)