|
@@ -315,6 +315,7 @@ async def resolve_issue(
|
|
|
repo_instruction: str | None,
|
|
repo_instruction: str | None,
|
|
|
issue_number: int,
|
|
issue_number: int,
|
|
|
comment_id: int | None,
|
|
comment_id: int | None,
|
|
|
|
|
+ target_branch: str | None = None,
|
|
|
reset_logger: bool = False,
|
|
reset_logger: bool = False,
|
|
|
) -> None:
|
|
) -> None:
|
|
|
"""Resolve a single github issue.
|
|
"""Resolve a single github issue.
|
|
@@ -333,6 +334,7 @@ async def resolve_issue(
|
|
|
repo_instruction: Repository instruction to use.
|
|
repo_instruction: Repository instruction to use.
|
|
|
issue_number: Issue number to resolve.
|
|
issue_number: Issue number to resolve.
|
|
|
comment_id: Optional ID of a specific comment to focus on.
|
|
comment_id: Optional ID of a specific comment to focus on.
|
|
|
|
|
+ target_branch: Optional target branch to create PR against (for PRs).
|
|
|
reset_logger: Whether to reset the logger for multiprocessing.
|
|
reset_logger: Whether to reset the logger for multiprocessing.
|
|
|
"""
|
|
"""
|
|
|
issue_handler = issue_handler_factory(issue_type, owner, repo, token)
|
|
issue_handler = issue_handler_factory(issue_type, owner, repo, token)
|
|
@@ -422,15 +424,32 @@ async def resolve_issue(
|
|
|
try:
|
|
try:
|
|
|
# checkout to pr branch if needed
|
|
# checkout to pr branch if needed
|
|
|
if issue_type == 'pr':
|
|
if issue_type == 'pr':
|
|
|
|
|
+ branch_to_use = target_branch if target_branch else issue.head_branch
|
|
|
logger.info(
|
|
logger.info(
|
|
|
- f'Checking out to PR branch {issue.head_branch} for issue {issue.number}'
|
|
|
|
|
|
|
+ f'Checking out to PR branch {target_branch} for issue {issue.number}'
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ if not branch_to_use:
|
|
|
|
|
+ raise ValueError('Branch name cannot be None')
|
|
|
|
|
+
|
|
|
|
|
+ # Fetch the branch first to ensure it exists locally
|
|
|
|
|
+ fetch_cmd = ['git', 'fetch', 'origin', branch_to_use]
|
|
|
|
|
+ subprocess.check_output(
|
|
|
|
|
+ fetch_cmd,
|
|
|
|
|
+ cwd=repo_dir,
|
|
|
|
|
+ )
|
|
|
|
|
+
|
|
|
|
|
+ # Checkout the branch
|
|
|
|
|
+ checkout_cmd = ['git', 'checkout', branch_to_use]
|
|
|
subprocess.check_output(
|
|
subprocess.check_output(
|
|
|
- ['git', 'checkout', f'{issue.head_branch}'],
|
|
|
|
|
|
|
+ checkout_cmd,
|
|
|
cwd=repo_dir,
|
|
cwd=repo_dir,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+ # Update issue's base_branch if using custom target branch
|
|
|
|
|
+ if target_branch:
|
|
|
|
|
+ issue.base_branch = target_branch
|
|
|
|
|
+
|
|
|
base_commit = (
|
|
base_commit = (
|
|
|
subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo_dir)
|
|
subprocess.check_output(['git', 'rev-parse', 'HEAD'], cwd=repo_dir)
|
|
|
.decode('utf-8')
|
|
.decode('utf-8')
|
|
@@ -553,6 +572,12 @@ def main():
|
|
|
choices=['issue', 'pr'],
|
|
choices=['issue', 'pr'],
|
|
|
help='Type of issue to resolve, either open issue or pr comments.',
|
|
help='Type of issue to resolve, either open issue or pr comments.',
|
|
|
)
|
|
)
|
|
|
|
|
+ parser.add_argument(
|
|
|
|
|
+ '--target-branch',
|
|
|
|
|
+ type=str,
|
|
|
|
|
+ default=None,
|
|
|
|
|
+ help="Target branch to pull and create PR against (for PRs). If not specified, uses the PR's base branch.",
|
|
|
|
|
+ )
|
|
|
|
|
|
|
|
my_args = parser.parse_args()
|
|
my_args = parser.parse_args()
|
|
|
|
|
|
|
@@ -613,6 +638,7 @@ def main():
|
|
|
repo_instruction=repo_instruction,
|
|
repo_instruction=repo_instruction,
|
|
|
issue_number=my_args.issue_number,
|
|
issue_number=my_args.issue_number,
|
|
|
comment_id=my_args.comment_id,
|
|
comment_id=my_args.comment_id,
|
|
|
|
|
+ target_branch=my_args.target_branch,
|
|
|
)
|
|
)
|
|
|
)
|
|
)
|
|
|
|
|
|