mirror of
https://forgejo.stefka.eu/jiriks74/create-pull-request.git
synced 2025-01-18 16:01:06 +01:00
Add PR creation from Fork
This commit is contained in:
parent
ac9f92d6e7
commit
e48dab0c1c
9 changed files with 48 additions and 12 deletions
22
dist/cpr/create_or_update_pull_request.py
vendored
22
dist/cpr/create_or_update_pull_request.py
vendored
|
@ -56,25 +56,37 @@ def create_or_update_pull_request(
|
|||
team_reviewers,
|
||||
project_name,
|
||||
project_column_name,
|
||||
request_to_parent,
|
||||
):
|
||||
if request_to_parent is None:
|
||||
request_to_parent = False
|
||||
else:
|
||||
request_to_parent = request_to_parent.lower() in ['true', '1', 't', 'y', 'yes', 'on']
|
||||
|
||||
github_repo = head_repo = Github(github_token).get_repo(github_repository)
|
||||
if request_to_parent:
|
||||
github_repo = github_repo.parent
|
||||
if github_repo is None:
|
||||
raise ValueError("The repository is not a fork. The parameter request-to-parent should be set to false.")
|
||||
|
||||
head_branch = f"{head_repo.owner.login}:{branch}"
|
||||
|
||||
# Create the pull request
|
||||
github_repo = Github(github_token).get_repo(github_repository)
|
||||
try:
|
||||
pull_request = github_repo.create_pull(
|
||||
title=title, body=body, base=base, head=branch
|
||||
title=title, body=body, base=base, head=head_branch
|
||||
)
|
||||
print(f"Created pull request #{pull_request.number} ({branch} => {base})")
|
||||
print(f"Created pull request #{pull_request.number} ({head_branch} => {github_repo.owner.login}:{base})")
|
||||
except GithubException as e:
|
||||
if e.status == 422:
|
||||
# A pull request exists for this branch and base
|
||||
head_branch = "{}:{}".format(github_repository.split("/")[0], branch)
|
||||
# Get the pull request
|
||||
pull_request = github_repo.get_pulls(
|
||||
state="open", base=base, head=head_branch
|
||||
)[0]
|
||||
# Update title and body
|
||||
pull_request.as_issue().edit(title=title, body=body)
|
||||
print(f"Updated pull request #{pull_request.number} ({branch} => {base})")
|
||||
print(f"Updated pull request #{pull_request.number} ({head_branch} => {github_repo.owner.login}:{base})")
|
||||
else:
|
||||
print(str(e))
|
||||
raise
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue