File tree Expand file tree Collapse file tree 6 files changed +110
-6
lines changed
Expand file tree Collapse file tree 6 files changed +110
-6
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,29 @@ replace_tokens() {
279279 ' " $@ "
280280}
281281
282+ # replace_metadata: Replaces placeholders in stdin with values from GIV_METADATA_ environment variables.
283+ #
284+ # Usage:
285+ # replace_metadata < summary_file > output_file
286+ replace_metadata () {
287+ awk '
288+ BEGIN {
289+ ORS = ""
290+ }
291+ {
292+ line = $0
293+ for (v in ENVIRON) {
294+ if (v ~ /^GIV_METADATA_/) {
295+ name = substr(v, 14)
296+ gsub("\\[" name "\\]", ENVIRON[v], line)
297+ }
298+ }
299+ print line "\n"
300+ }
301+ '
302+ }
303+
304+
282305# build_prompt: fill a prompt template with tokens and diff content
283306#
284307# Usage:
@@ -378,12 +401,12 @@ build_prompt() {
378401 export GIV_TOKEN_EXAMPLE=" ${example:- ${GIV_TOKEN_EXAMPLE} } "
379402 export GIV_TOKEN_RULES=" ${rules:- ${GIV_TOKEN_RULES} } "
380403
381- # combine template + instructions, then replace tokens using diff as summary
404+ # combine template + instructions, then replace metadata and tokens using diff as summary
382405 {
383406 cat " ${template_file} "
384407 printf ' \nOutput just the final content—no extra commentary or code fencing. '
385408 printf ' Use only information contained in this prompt and the summaries provided above.\n'
386- } | replace_tokens " ${summary_file} "
409+ } | replace_tokens " ${summary_file} " | replace_metadata " ${summary_file} "
387410
388411 return
389412}
Original file line number Diff line number Diff line change @@ -16,9 +16,11 @@ metadata_init() {
1616 # -------------------------
1717 print_debug " Determining project provider for type: ${GIV_PROJECT_TYPE:- auto} "
1818 if [ " ${GIV_PROJECT_TYPE} " = " custom" ]; then
19+ # shellcheck disable=SC1091
1920 [ -f " ${GIV_HOME} /project_provider.sh" ] && . " ${GIV_HOME} /project_provider.sh"
2021 elif [ " ${GIV_PROJECT_TYPE} " = " auto" ]; then
2122 for f in " ${GIV_LIB_DIR} /project/providers" /* .sh; do
23+ # shellcheck disable=SC1090
2224 [ -f " $f " ] && . " $f "
2325 done
2426 for fn in $( set | awk -F' =' ' /^provider_.*_detect=/ { sub("()","",$1); print $1 }' ) ; do
@@ -28,6 +30,7 @@ metadata_init() {
2830 fi
2931 done
3032 else
33+ # shellcheck disable=SC1090
3134 . " ${GIV_LIB_DIR} /project/providers/provider_${GIV_PROJECT_TYPE} .sh" || return 1
3235 DETECTED_PROVIDER=" provider_${GIV_PROJECT_TYPE} _detect"
3336 fi
@@ -93,6 +96,7 @@ metadata_init() {
9396 # Export for current shell
9497 # -------------------------
9598 set -a
99+ # shellcheck disable=SC1090
96100 . " $ENV_FILE "
97101 set +a
98102}
Original file line number Diff line number Diff line change 22
33[ SUMMARY]
44
5+ ## Project Overview
6+
7+ [ TITLE]
8+ [ AUTHOR]
9+ [ URL]
10+ [ DESCRIPTION]
11+
512## Instructions
613
714Write one comprehensive release notes document [ PROJECT_TITLE] [ VERSION] from the provided change summaries, following these guidelines:
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ export GIV_HOME="$BATS_TEST_DIRNAME/.giv"
1616export GIV_TMP_DIR=" $BATS_TEST_DIRNAME /.giv/.tmp"
1717
1818setup () {
19+ mkdir -p " $GIV_TMP_DIR "
1920 TMPDIR_REPO=" $( mktemp -d -p " $GIV_TMP_DIR " ) "
2021 cd " $TMPDIR_REPO "
2122 rm -f input.md
@@ -116,20 +117,20 @@ EOF
116117 assert_output " "
117118}
118119
119- @test " fails if template missing" {
120+ @test " build_prompt fails if template missing" {
120121 run build_prompt --template missing.md --summary diff.txt
121122 [ " $status " -ne 0 ]
122123 assert_output " template file not found: missing.md"
123124}
124125
125- @test " fails if diff missing" {
126+ @test " build_prompt fails if diff missing" {
126127 write_file template.md " Hello"
127128 run build_prompt --template template.md --summary missing.txt
128129 [ " $status " -ne 0 ]
129130 assert_output " diff file not found: missing.txt"
130131}
131132
132- @test " injects summary into prompt" {
133+ @test " build_prompt injects summary into prompt" {
133134 write_file template.md \
134135 " Summary:" \
135136 " [SUMMARY]" \
@@ -151,7 +152,7 @@ Output just the final content—no extra commentary or code fencing. Use only in
151152EOF
152153}
153154
154- @test " replaces all optional tokens" {
155+ @test " build_prompt replaces all optional tokens" {
155156 write_file template.md \
156157 " Project: [PROJECT_TITLE]" \
157158 " Version: [VERSION]" \
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bats
2+
3+ load ' test_helper/bats-support/load'
4+ load ' test_helper/bats-assert/load'
5+ load " $BATS_TEST_DIRNAME /../src/config.sh"
6+ load " $BATS_TEST_DIRNAME /../src/system.sh"
7+ load " $BATS_TEST_DIRNAME /../src/project.sh"
8+ load " $BATS_TEST_DIRNAME /../src/llm.sh"
9+
10+ setup () {
11+ export GIV_METADATA_TITLE=" Test Title"
12+ export GIV_METADATA_DESCRIPTION=" Test Description"
13+ export GIV_METADATA_VERSION=" 1.0.0"
14+ echo " [TITLE] - [DESCRIPTION] - [VERSION]" > template.txt
15+ echo " Summary content here." > summary.txt
16+ }
17+
18+ teardown () {
19+ unset GIV_METADATA_TITLE
20+ unset GIV_METADATA_DESCRIPTION
21+ unset GIV_METADATA_VERSION
22+ rm -f template.txt summary.txt
23+ }
24+
25+ @test " build_prompt calls replace_metadata and replace_tokens" {
26+ run build_prompt --template template.txt --summary summary.txt
27+ assert_success
28+ assert_output " Test Title - Test Description - 1.0.0\nOutput just the final content—no extra commentary or code fencing. Use only information contained in this prompt and the summaries provided above."
29+ }
Original file line number Diff line number Diff line change 1+ #! /usr/bin/env bats
2+
3+ load ' test_helper/bats-support/load'
4+ load ' test_helper/bats-assert/load'
5+ load " $BATS_TEST_DIRNAME /../src/config.sh"
6+ load " $BATS_TEST_DIRNAME /../src/system.sh"
7+ load " $BATS_TEST_DIRNAME /../src/llm.sh"
8+ export GIV_TMP_DIR=" $BATS_TEST_DIRNAME /.giv/.tmp"
9+
10+ setup () {
11+ export GIV_METADATA_TITLE=" Test Title"
12+ export GIV_METADATA_DESCRIPTION=" Test Description"
13+ export GIV_METADATA_VERSION=" 1.0.0"
14+ export GIV_DEBUG=" true"
15+ export -p GIV_METADATA_TITLE
16+ export -p GIV_METADATA_DESCRIPTION
17+ export -p GIV_METADATA_VERSION
18+ cd " $GIV_TMP_DIR "
19+ }
20+
21+ teardown () {
22+ unset GIV_METADATA_TITLE
23+ unset GIV_METADATA_DESCRIPTION
24+ unset GIV_METADATA_VERSION
25+ }
26+
27+ @test " replace_metadata replaces placeholders with GIV_METADATA_ variables" {
28+ echo " [TITLE] - [DESCRIPTION] - [VERSION]" > input.txt
29+ run env GIV_METADATA_TITLE=" Test Title" GIV_METADATA_DESCRIPTION=" Test Description" GIV_METADATA_VERSION=" 1.0.0" bash -c " cat input.txt | source $BATS_TEST_DIRNAME /../src/llm.sh; replace_metadata"
30+ assert_success
31+ assert_output " Test Title - Test Description - 1.0.0"
32+ }
33+
34+ @test " replace_metadata handles missing variables gracefully" {
35+ echo " [TITLE] - [MISSING] - [VERSION]" > input.txt
36+ run env GIV_METADATA_TITLE=" Test Title" GIV_METADATA_DESCRIPTION=" Test Description" GIV_METADATA_VERSION=" 1.0.0" bash -c " cat input.txt | source $BATS_TEST_DIRNAME /../src/llm.sh; replace_metadata"
37+ assert_success
38+ assert_output " Test Title - [MISSING] - 1.0.0"
39+ }
40+
You can’t perform that action at this time.
0 commit comments