Browse Source

️ Restore `commit_in_place` input in `translate.yml` (#16216)

master
Yurii Motov 18 hours ago
committed by GitHub
parent
commit
b26a476a9c
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 5
      .github/workflows/translate.yml
  2. 52
      scripts/translate.py

5
.github/workflows/translate.yml

@ -30,6 +30,11 @@ on:
type: string type: string
required: false required: false
default: "" default: ""
commit_in_place:
description: Commit changes directly instead of making a PR
type: boolean
required: false
default: false
max: max:
description: Maximum number of items to translate (e.g. 10) description: Maximum number of items to translate (e.g. 10)
type: number type: number

52
scripts/translate.py

@ -421,6 +421,9 @@ def make_pr(
command: Annotated[str | None, typer.Option(envvar="COMMAND")] = None, command: Annotated[str | None, typer.Option(envvar="COMMAND")] = None,
github_token: Annotated[str, typer.Option(envvar="GITHUB_TOKEN")], github_token: Annotated[str, typer.Option(envvar="GITHUB_TOKEN")],
github_repository: Annotated[str, typer.Option(envvar="GITHUB_REPOSITORY")], github_repository: Annotated[str, typer.Option(envvar="GITHUB_REPOSITORY")],
commit_in_place: Annotated[
bool, typer.Option(envvar="COMMIT_IN_PLACE", show_default=True)
] = False,
) -> None: ) -> None:
print("Setting up GitHub Actions git user") print("Setting up GitHub Actions git user")
repo = git.Repo(Path(__file__).absolute().parent.parent) repo = git.Repo(Path(__file__).absolute().parent.parent)
@ -432,14 +435,22 @@ def make_pr(
["git", "config", "user.email", "pr-submit[bot]@users.noreply.github.com"], ["git", "config", "user.email", "pr-submit[bot]@users.noreply.github.com"],
check=True, check=True,
) )
branch_name = "translate" current_branch = repo.active_branch.name
if language: if current_branch == "master" and commit_in_place:
branch_name += f"-{language}" print("Can't commit directly to master")
if command: raise typer.Exit(code=1)
branch_name += f"-{command}" if not commit_in_place:
branch_name += f"-{secrets.token_hex(4)}" branch_name = "translate"
print(f"Creating a new branch {branch_name}") if language:
subprocess.run(["git", "checkout", "-b", branch_name], check=True) branch_name += f"-{language}"
if command:
branch_name += f"-{command}"
branch_name += f"-{secrets.token_hex(4)}"
print(f"Creating a new branch {branch_name}")
subprocess.run(["git", "checkout", "-b", branch_name], check=True)
else:
branch_name = current_branch
print(f"Committing in place on branch {branch_name}")
print("Adding updated files") print("Adding updated files")
git_path = Path("docs") git_path = Path("docs")
subprocess.run(["git", "add", str(git_path)], check=True) subprocess.run(["git", "add", str(git_path)], check=True)
@ -452,17 +463,20 @@ def make_pr(
subprocess.run(["git", "commit", "-m", message], check=True) subprocess.run(["git", "commit", "-m", message], check=True)
print("Pushing branch") print("Pushing branch")
subprocess.run(["git", "push", "origin", branch_name], check=True) subprocess.run(["git", "push", "origin", branch_name], check=True)
print("Creating PR") if not commit_in_place:
g = Github(github_token) print("Creating PR")
gh_repo = g.get_repo(github_repository) g = Github(github_token)
body = ( gh_repo = g.get_repo(github_repository)
message body = (
+ "\n\nThis PR was created automatically using LLMs." message
+ f"\n\nIt uses the prompt file https://github.com/fastapi/fastapi/blob/master/docs/{language}/llm-prompt.md." + "\n\nThis PR was created automatically using LLMs."
+ "\n\nIn most cases, it's better to make PRs updating that file so that the LLM can do a better job generating the translations than suggesting changes in this PR." + f"\n\nIt uses the prompt file https://github.com/fastapi/fastapi/blob/master/docs/{language}/llm-prompt.md."
) + "\n\nIn most cases, it's better to make PRs updating that file so that the LLM can do a better job generating the translations than suggesting changes in this PR."
pr = gh_repo.create_pull(title=message, body=body, base="master", head=branch_name) )
print(f"Created PR: {pr.number}") pr = gh_repo.create_pull(
title=message, body=body, base="master", head=branch_name
)
print(f"Created PR: {pr.number}")
print("Finished") print("Finished")

Loading…
Cancel
Save