Skip to content

Commit f2d3128

Browse files
committed
Fix a bug with not updating an already-generated AI summary when git-grok prompt changes
1 parent 377ed8d commit f2d3128

File tree

1 file changed

+25
-13
lines changed

1 file changed

+25
-13
lines changed

git-grok

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ AI_PROMPT_INJECT_PLACEHOLDER = f"""
7171
- Your goal is to detect the single best place for this "{AI_PLACEHOLDER}"
7272
marker injection and inject it there. At the place where a human-readable
7373
summary would be expected.
74-
- You are not allowed to remove a single character in the PR template!
74+
- You are NOT ALLOWED to remove a single character in the PR template!
75+
- You are NOT ALLOWED to add any new lines to the PR template EXCEPT that
76+
"{AI_PLACEHOLDER}" marker! I.e. you must always add exactly one new line
77+
with that marker, not more.
78+
- Never wrap anything with markdown blocks or something like that. Follow
79+
the rules above!
7580
- Never change sub-headers, surrounding text etc. there.
7681
- Do not delete any sections, even if those sections appear empty.
7782
- Only include the response text in that part. Don't add any comments or
@@ -747,6 +752,7 @@ class Main:
747752

748753
assert commit.url is not None
749754
pr = self.gh_get_pr(url=commit.url)
755+
body = pr.body
750756

751757
self.settings_load()
752758
if self.settings:
@@ -758,7 +764,7 @@ class Main:
758764
rules_hash = ai_hash_extract(injected_text.text)
759765
if rules_hash != self.ai_get_rules_hash():
760766
commit.title = pr.title
761-
pr.body = self.process_build_pr_body_with_ai(
767+
body = self.process_build_pr_body_with_ai(
762768
commit=commit,
763769
pr_template=injected_text.template_with_placeholder,
764770
)
@@ -769,6 +775,7 @@ class Main:
769775
head_commit_hash=commit.hash,
770776
pr_numbers=pr_numbers,
771777
pr_number_current=pr_number_current,
778+
body=body,
772779
)
773780

774781
#
@@ -784,10 +791,13 @@ class Main:
784791
return pr_template or ""
785792

786793
self.print_ai_generating()
794+
pr_template = pr_template or AI_DEFAULT_PR_TEMPLATE
787795

788796
injected_text = self.ai_generate_injected_text(
789-
prompt_inject_placeholder=self.ai_build_prompt_inject_placeholder(
790-
pr_template=pr_template or AI_DEFAULT_PR_TEMPLATE,
797+
prompt_inject_placeholder=(
798+
pr_template
799+
if AI_PLACEHOLDER in pr_template
800+
else self.ai_build_prompt_inject_placeholder(pr_template=pr_template)
791801
),
792802
prompt_generate_summary=self.ai_build_prompt_generate_summary(
793803
title=commit.title,
@@ -929,12 +939,13 @@ class Main:
929939
head_commit_hash: str,
930940
pr_numbers: list[int],
931941
pr_number_current: int | None,
942+
body: str,
932943
) -> tuple[Pr, PrUpsertResult]:
933944
if base_branch is None:
934945
base_branch = self.remote_base_branch
935946

936-
new_body = body_suffix_upsert(
937-
body=pr.body,
947+
body = body_suffix_upsert(
948+
body=body,
938949
pr_numbers=pr_numbers,
939950
pr_number_current=pr_number_current,
940951
)
@@ -945,7 +956,7 @@ class Main:
945956

946957
if (
947958
pr.base_branch == base_branch
948-
and pr.body == new_body
959+
and pr.body == body
949960
and pr.state == "OPEN"
950961
and (MIDDLE_PR_LABEL in pr.labels) == is_middle_pr
951962
):
@@ -1027,11 +1038,11 @@ class Main:
10271038
"--body-file",
10281039
"-",
10291040
],
1030-
input=new_body,
1041+
input=body,
10311042
)
10321043

10331044
pr.base_branch = base_branch
1034-
pr.body = new_body
1045+
pr.body = body
10351046
return pr, upsert_result
10361047

10371048
#
@@ -1490,12 +1501,13 @@ class Main:
14901501
def ai_generate_injected_text(
14911502
self,
14921503
*,
1493-
prompt_inject_placeholder: AiPrompt,
1504+
prompt_inject_placeholder: AiPrompt | str,
14941505
prompt_generate_summary: AiPrompt,
14951506
) -> AiInjectedText:
1496-
task_inject_placeholder = Task(
1497-
self.ai_send_request,
1498-
prompt=prompt_inject_placeholder,
1507+
task_inject_placeholder = (
1508+
Task(lambda: prompt_inject_placeholder)
1509+
if isinstance(prompt_inject_placeholder, str)
1510+
else Task(self.ai_send_request, prompt=prompt_inject_placeholder)
14991511
)
15001512
task_generate_summary = Task(
15011513
self.ai_send_request,

0 commit comments

Comments
 (0)