-
Notifications
You must be signed in to change notification settings - Fork 22
Feat: Add current-branch PR creation option #287
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -15,6 +15,17 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (require 'ai-code-prompt-mode) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function helm-gtags-create-tags "helm-gtags" (dir &optional label)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function magit-anything-modified-p "magit" ()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function magit-branch-p "magit" (branch)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function magit-branch-read-args "magit-branch" (prompt)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function magit-call-git "magit-git" (&rest args)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function magit-diff-visit-directory "magit-diff" (directory)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function magit-git-lines "magit-git" (&rest args)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function magit-git-output "magit-git" (&rest args)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function magit-git-string "magit-git" (&rest args)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function magit-rev-verify "magit-git" (rev)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function magit-run-git "magit-git" (&rest args)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (declare-function magit-worktree-status "magit-worktree" ()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (defcustom ai-code-init-project-gtags-label "pygments" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Default label passed to Helm-Gtags when initializing a project. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -40,7 +51,7 @@ Candidate values: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (defvar ai-code-files-dir-name) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (defun ai-code--git-ignored-repo-file-p (file root) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Return non-nil when FILE should be ignored for repo candidates." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Return non-nil when FILE should be ignored for repo candidates under ROOT." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (when (and file root) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (let ((ignore-dir (file-truename (expand-file-name ai-code-files-dir-name root))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (truename (file-truename file))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -120,7 +131,7 @@ PR Description Steps: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pr-url source-instruction))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (defun ai-code--build-pr-ci-check-init-prompt (review-source pr-url) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Build CI checks review prompt for REVIEW-SOURCE with PR-URL." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Build a CI check review prompt for REVIEW-SOURCE with PR-URL." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (let ((source-instruction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (ai-code--pull-or-review-source-instruction review-source 'review-ci-checks))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (format "Review GitHub CI checks for pull request: %s | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -168,19 +179,31 @@ CI Checks Review Steps: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (defun ai-code--pull-or-review-pr-with-source (review-source) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "Ask for a target URL and send a prompt for REVIEW-SOURCE to AI." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (let* ((review-mode (ai-code--pull-or-review-pr-mode-choice)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (url-prompt (ai-code--pull-or-review-url-prompt review-mode)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (target-url (ai-code-read-string url-prompt)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (init-prompt (ai-code--build-pr-init-prompt review-source target-url review-mode)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (init-prompt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (if (eq review-mode 'send-current-branch-pr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (let* ((current-branch (ai-code--require-current-branch)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (default-target-branch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (ai-code--default-pr-target-branch current-branch)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (target-branch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (ai-code-read-string "Target branch to merge into: " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| default-target-branch))) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (ai-code--build-send-current-branch-pr-init-prompt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| review-source current-branch target-branch)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+184
to
+191
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (let* ((current-branch (ai-code--require-current-branch)) | |
| (default-target-branch | |
| (ai-code--default-pr-target-branch current-branch)) | |
| (target-branch | |
| (ai-code-read-string "Target branch to merge into: " | |
| default-target-branch))) | |
| (ai-code--build-send-current-branch-pr-init-prompt | |
| review-source current-branch target-branch)) | |
| (progn | |
| (unless (magit-toplevel) | |
| (user-error "Not inside a Git repository")) | |
| (let* ((current-branch (ai-code--require-current-branch)) | |
| (default-target-branch | |
| (ai-code--default-pr-target-branch current-branch)) | |
| (target-branch | |
| (ai-code-read-string "Target branch to merge into: " | |
| default-target-branch))) | |
| (ai-code--build-send-current-branch-pr-init-prompt | |
| review-source current-branch target-branch))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed locally. The current-branch PR path now validates that the command is running inside a Git repository before it tries to resolve branch information, so the failure mode is explicit and user-facing. This will be included in the next PR update.
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the user chooses "Send out PR for current branch", the minibuffer prompt still says "Enter review prompt". Consider changing this prompt (conditionally) to something neutral like "Enter prompt" or "Enter PR creation prompt" to avoid misleading wording in the new flow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed locally. The current-branch PR path now uses a dedicated minibuffer label (Enter PR creation prompt:) instead of the review-specific prompt text. This will be included in the next PR update.
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There’s a leftover implementation note (;; DONE: ...) inside ai-code--pull-or-review-pr-mode-choice. This kind of comment becomes stale quickly and adds noise to the interactive path; please remove it (or convert it into a proper issue/commit message) before merging.
| ;; 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keeping this comment intentionally. The original implementation requirement for this task explicitly asked to preserve the existing comment in place and change it to a DONE-prefixed form after implementing the feature, so removing it here would conflict with that requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid hardcoding main as fallback PR target
When ai-code--default-pr-target-branch cannot infer an upstream and neither main nor master exists, it still returns "main". In repositories whose integration branch is named differently (for example develop or trunk), accepting this default causes the generated PR-creation flow to target a non-existent branch, which can make the downstream gh pr create step fail. The fallback should be derived from an actual existing default branch (e.g., remote HEAD/default branch) instead of an unconditional literal.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed locally. The fallback logic now checks origin/HEAD first and uses the repository's actual remote default branch when upstream is unavailable, instead of unconditionally falling back to "main". This will be included in the next PR update.
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ai-code--default-pr-target-branch is new and contains non-trivial branching (upstream parsing, normalization, main/master fallback), but there are no tests covering these behaviors. Add focused ERT tests that mock magit-git-string/magit-branch-p to validate upstream-derived defaults and the fallback selection logic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed locally. I added focused coverage for the new default-target-branch behavior, including the remote default branch fallback path and the current-branch PR prompt flow. This will be included in the next PR update.
Copilot
AI
Apr 11, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR creation prompt reuses ai-code--pull-or-review-source-instruction’s default (review) instruction, which currently tells the backend to "fetch pull request details and review comments". For a PR-creation flow, this instruction is misleading (especially before the PR exists). Add a dedicated review-mode case (e.g., send-current-branch-pr) with backend-specific instructions for creating the PR (gh: gh pr create, MCP: create PR via API), and pass that mode here.
| (defun ai-code--build-send-current-branch-pr-init-prompt (review-source current-branch target-branch) | |
| "Build a PR creation prompt for REVIEW-SOURCE, CURRENT-BRANCH, and TARGET-BRANCH." | |
| (let ((source-instruction | |
| (ai-code--pull-or-review-source-instruction review-source))) | |
| (defun ai-code--send-current-branch-pr-source-instruction (review-source) | |
| "Return PR-creation instructions for REVIEW-SOURCE." | |
| (pcase review-source | |
| ((or 'gh 'github-cli 'github) | |
| (concat | |
| "Use GitHub CLI to create the pull request. " | |
| "Run `gh pr create` with the current branch as the head branch, " | |
| "target the requested base branch, and include the final title and body.")) | |
| ((or 'mcp 'github-mcp) | |
| (concat | |
| "Use the available MCP/API GitHub tools to create the pull request directly. " | |
| "Do not fetch review comments for a PR that does not exist yet; " | |
| "create the PR first, then return the resulting PR URL.")) | |
| (_ | |
| (concat | |
| "Create the pull request using the backend's PR creation capability. " | |
| "Do not treat this as a PR review flow and do not fetch review comments " | |
| "before the PR exists.")))) | |
| (defun ai-code--build-send-current-branch-pr-init-prompt (review-source current-branch target-branch) | |
| "Build a PR creation prompt for REVIEW-SOURCE, CURRENT-BRANCH, and TARGET-BRANCH." | |
| (let ((source-instruction | |
| (ai-code--send-current-branch-pr-source-instruction review-source))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed locally. I added a dedicated source-instruction path for current-branch PR creation so this flow no longer reuses review-oriented instructions about fetching PR details or review comments before the PR exists. This will be included in the next PR update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ai-code--pull-or-review-pr-with-sourceno longer always asks for a URL (it can branch into current-branch PR creation), but the docstring still says it "Ask[s] for a target URL". Update the docstring to reflect both flows so it stays accurate for callers/readers.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed locally. I updated the docstring to describe both flows: the current-branch PR creation path and the URL-based review/issue path. This will be included in the next PR update.