Skip to content

Commit bdc1633

Browse files
committed
Add optional PR title prompt to PR creation
1 parent 78cbcc5 commit bdc1633

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed

ai-code-git.el

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ branch for the current branch PR. Otherwise, ask for the relevant pull
183183
request or issue URL."
184184
(let* ((review-mode (ai-code--pull-or-review-pr-mode-choice))
185185
(init-prompt
186-
(if (eq review-mode 'send-current-branch-pr)
186+
(if (eq review-mode 'send-current-branch-pr)
187187
(progn
188188
(unless (magit-toplevel)
189189
(user-error "Not inside a Git repository"))
@@ -192,9 +192,12 @@ request or issue URL."
192192
(ai-code--default-pr-target-branch current-branch))
193193
(target-branch
194194
(ai-code-read-string "Target branch to merge into: "
195-
default-target-branch)))
195+
default-target-branch))
196+
(pr-title
197+
(ai-code-read-string
198+
"PR title (optional, leave empty for AI to generate): ")))
196199
(ai-code--build-send-current-branch-pr-init-prompt
197-
review-source current-branch target-branch)))
200+
review-source current-branch target-branch pr-title)))
198201
(let* ((url-prompt (ai-code--pull-or-review-url-prompt review-mode))
199202
(target-url (ai-code-read-string url-prompt)))
200203
(ai-code--build-pr-init-prompt review-source target-url review-mode))))
@@ -207,6 +210,7 @@ request or issue URL."
207210
(defun ai-code--pull-or-review-pr-mode-choice ()
208211
"Prompt user to choose analysis mode for a pull request or issue."
209212
;; DONE: add a choice: send out PR for current branch. The feature will ask user the target branch to merge. By default, it should be parent branch of current branch. AI should send out PR with description. The description should looks like it's written by the author, and it should be short.
213+
;; DONE: for send out PR feature, it should ask user about the PR title. If user does not provide one, AI should generate a concise title based on the code change
210214
(let* ((review-mode-alist '(("Review the PR" . review-pr)
211215
("Check unresolved feedback" . check-feedback)
212216
("Investigate issue" . investigate-issue)
@@ -298,24 +302,32 @@ request or issue URL."
298302
"Create the pull request using the backend's PR creation capability. "
299303
"Do not treat this as a PR review flow before the PR exists."))))
300304

301-
(defun ai-code--build-send-current-branch-pr-init-prompt (review-source current-branch target-branch)
302-
"Build a PR creation prompt for REVIEW-SOURCE, CURRENT-BRANCH, and TARGET-BRANCH."
305+
(defun ai-code--build-send-current-branch-pr-init-prompt
306+
(review-source current-branch target-branch &optional pr-title)
307+
"Build a PR creation prompt.
308+
REVIEW-SOURCE, CURRENT-BRANCH, TARGET-BRANCH, and PR-TITLE
309+
define the PR request."
303310
(let ((source-instruction
304-
(ai-code--send-current-branch-pr-source-instruction review-source)))
311+
(ai-code--send-current-branch-pr-source-instruction review-source))
312+
(title-instruction
313+
(if (string-empty-p (or pr-title ""))
314+
"2. Generate a concise PR title based on the code change.\n"
315+
(format "2. Use this PR title exactly: %s\n" pr-title))))
305316
(format "Create a pull request from branch %s into %s.
306317
307318
%s
308319
309320
PR Creation Steps:
310321
1. Inspect the current branch changes and open or send out a pull request into %s.
311-
2. Write a concise PR description that sounds like it was written by the author, but do not make it too short.
312-
3. Keep the description focused on the problem, the approach, and the most important verification, with enough detail for reviewers to understand the change quickly.
313-
4. Aim for a compact but complete description, roughly a short summary plus 2 to 3 brief supporting paragraphs or bullet points.
314-
5. Return the final PR URL and the exact description that was used."
322+
%s3. Write a concise PR description that sounds like it was written by the author, but do not make it too short.
323+
4. Keep the description focused on the problem, the approach, and the most important verification, with enough detail for reviewers to understand the change quickly.
324+
5. Aim for a compact but complete description, roughly a short summary plus 2 to 3 brief supporting paragraphs or bullet points.
325+
6. Return the final PR URL, the exact PR title, and the exact description that were used."
315326
current-branch
316327
target-branch
317328
source-instruction
318-
target-branch)))
329+
target-branch
330+
title-instruction)))
319331

320332
;;;###autoload
321333
(defun ai-code-pull-or-review-diff-file ()

test/test_ai-code-git.el

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,8 @@ When .gitignore is missing some entries, they should be added."
316316
(cond
317317
((string= prompt "Target branch to merge into: ")
318318
(or initial-input "main"))
319+
((string= prompt "PR title (optional, leave empty for AI to generate): ")
320+
"")
319321
((string= prompt "Enter PR creation prompt: ")
320322
initial-input)
321323
(t initial-input))))
@@ -324,9 +326,12 @@ When .gitignore is missing some entries, they should be added."
324326
(setq captured-inserted-prompt prompt))))
325327
(ai-code--pull-or-review-pr-with-source 'gh-cli)
326328
(should (member "Target branch to merge into: " captured-read-prompts))
329+
(should (member "PR title (optional, leave empty for AI to generate): "
330+
captured-read-prompts))
327331
(should (member "Enter PR creation prompt: " captured-read-prompts))
328332
(should-not (member "Enter review prompt: " captured-read-prompts))
329-
(should (string-match-p "feature/improve-pr-flow" captured-inserted-prompt)))))
333+
(should (string-match-p "feature/improve-pr-flow" captured-inserted-prompt))
334+
(should (string-match-p "generate a concise pr title" (downcase captured-inserted-prompt))))))
330335

331336
(ert-deftest ai-code-test-pull-or-review-diff-file-prepare-pr-description-github-mcp ()
332337
"When choosing PR description mode, prompt should ask AI to draft a PR description."

0 commit comments

Comments
 (0)