Skip to content
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

Adds support for providing custom PR string template in config #524

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions eden/scm/edenscm/ext/github/pull_request_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import re
from typing import List, Tuple
import string

from .gh_submit import Repository

Expand All @@ -16,6 +17,7 @@ def create_pull_request_title_and_body(
pr_numbers_and_num_commits: List[Tuple[int, int]],
pr_numbers_index: int,
repository: Repository,
template: str,
) -> Tuple[str, str]:
r"""Returns (title, body) for the pull request.

Expand Down Expand Up @@ -48,19 +50,28 @@ def create_pull_request_title_and_body(
owner, name = repository.get_upstream_owner_and_name()
pr = pr_numbers_and_num_commits[pr_numbers_index][0]
reviewstack_url = f"https://reviewstack.dev/{owner}/{name}/pull/{pr}"
if not template:
body = string.Template(f'''
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default template logic works as expected.

$commit_msg
$horizontal_rule
Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack]({reviewstack_url}).
$bulleted_list
''')
else:
body = string.Template(template)
Copy link
Contributor Author

@discentem discentem Feb 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This "works" as in doesn't crash at runtime but none of the template variables are injected properly yet. Any ideas what I am doing wrong? Static strings are injected properly.

~/sl/bin/sl pr submit --config pr.template="$commit_msg\n$horizontal_rule\nStack created with [Sapling](https://sapling-scm.com).\n$bulleted_list"

results in

\n\nStack created with [Sapling](https://sapling-scm.com).\n

bulleted_list = "\n".join(
[
_format_stack_entry(pr_number, index, pr_numbers_index, num_commits)
for index, (pr_number, num_commits) in enumerate(pr_numbers_and_num_commits)
]
)
title = firstline(commit_msg)
body = f"""{commit_msg}
{_HORIZONTAL_RULE}
Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack]({reviewstack_url}).
{bulleted_list}
"""
return title, body
tbody = body.safe_substitute(
commit_msg=commit_msg,
horizontal_rule=_HORIZONTAL_RULE,
bulleted_list=bulleted_list,
)
return title, tbody


_STACK_ENTRY = re.compile(r"^\* (__->__ )?#([1-9]\d*).*$")
Expand Down
2 changes: 2 additions & 0 deletions eden/scm/edenscm/ext/github/submit.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,13 @@ async def rewrite_pull_request_body(

head_commit_data = partition[0]
commit_msg = head_commit_data.get_msg()

title, body = create_pull_request_title_and_body(
commit_msg,
pr_numbers_and_num_commits,
index,
repository,
template=ui.config("pr", "template", default="")
)
pr = head_commit_data.pr
assert pr
Expand Down