Skip to content

Commit 13f3a43

Browse files
feat: add issue URL support to CreatePR step
Co-Authored-By: Patched <[email protected]>
1 parent 16d47d3 commit 13f3a43

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

patchwork/steps/CreatePR/CreatePR.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def __init__(self, inputs: dict):
5050
self.pr_body = inputs.get("pr_body", "")
5151
self.title = inputs.get("pr_title", "Patchwork PR")
5252
self.force = bool(inputs.get("force_pr_creation", False))
53+
self.issue_url = inputs.get("issue_url") # Optional GitHub Issue URL to link the PR to
5354
self.base_branch = inputs.get("base_branch")
5455
if self.enabled and self.base_branch is None:
5556
logger.warn("Base branch not provided. Skipping PR creation.")
@@ -106,6 +107,7 @@ def run(self) -> dict:
106107
target_branch_name=self.target_branch,
107108
scm_client=self.scm_client,
108109
force=self.force,
110+
issue_url=self.issue_url, # Add issue URL to link PR with issue
109111
)
110112

111113
logger.info(f"[green]PR created at [link={url}]{url}[/link][/]", extra={"markup": True})
@@ -146,20 +148,26 @@ def create_pr(
146148
target_branch_name: str,
147149
scm_client: ScmPlatformClientProtocol,
148150
force: bool = False,
151+
issue_url: str | None = None, # Optional GitHub Issue URL to link the PR to
149152
):
150153
prs = scm_client.find_prs(repo_slug, original_branch=base_branch_name, feature_branch=target_branch_name)
151154
pr = next(iter(prs), None)
152155
if pr is None:
156+
final_body = body
157+
if issue_url is not None:
158+
issue_info = scm_client.get_slug_and_id_from_url(issue_url)
159+
if issue_info is not None:
160+
_, issue_number = issue_info
161+
final_body = f"{body}\n\nResolves #{issue_number}"
162+
153163
pr = scm_client.create_pr(
154164
repo_slug,
155165
title,
156-
body,
166+
final_body,
157167
base_branch_name,
158168
target_branch_name,
159169
)
160170

161-
pr.set_pr_description(body)
162-
163171
return pr.url()
164172

165173
if force:

patchwork/steps/CreatePR/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
- `pr_title`: Title for the pull request
1111
- `force_pr_creation`: Flag to force creation of the pull request
1212
- `base_branch`: Base branch for the pull request
13+
- `issue_url`: GitHub Issue URL to link the PR to (optional). When provided, adds "Resolves #<ISSUE_NUMBER>" to PR description
1314

1415
## Outputs
1516
- `run() -> dict`: Method to run the pull request creation process with the following output:
1617
- `pr_url`: URL of the created pull request
1718

18-
This module provides functionality to create a pull request on a source control management platform (Github or Gitlab) based on the input data provided. It includes methods for checking required data, handling platform-specific API keys, setting up the pull request parameters, and executing the pull request creation process. The `create_pr` method within the module helps in finding or creating a pull request with necessary details and descriptions. The module also logs information throughout the process for tracking and verification purposes.
19+
This module provides functionality to create a pull request on a source control management platform (Github or Gitlab) based on the input data provided. It includes methods for checking required data, handling platform-specific API keys, setting up the pull request parameters, and executing the pull request creation process. The `create_pr` method within the module helps in finding or creating a pull request with necessary details and descriptions, including the ability to link PRs to GitHub issues. The module also logs information throughout the process for tracking and verification purposes.

patchwork/steps/CreatePR/typed.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class CreatePRInputs(__CreatePRRequiredInputs, total=False):
1616
scm_url: Annotated[str, StepTypeConfig(is_config=True)]
1717
gitlab_api_key: Annotated[str, StepTypeConfig(is_config=True)]
1818
github_api_key: Annotated[str, StepTypeConfig(is_config=True)]
19+
issue_url: str
1920

2021

2122
class CreatePROutputs(TypedDict):

0 commit comments

Comments
 (0)