Skip to content

Commit

Permalink
Merge pull request #411 from mfocko/github-pr-fork-to-fork
Browse files Browse the repository at this point in the history
Creating PRs from `fork` to `other-fork` on Github

Reviewed-by: https://github.com/apps/packit-as-a-service
  • Loading branch information
softwarefactory-project-zuul[bot] authored May 26, 2020
2 parents 387216b + e8bf43d commit f3d806b
Show file tree
Hide file tree
Showing 4 changed files with 4,832 additions and 3 deletions.
14 changes: 14 additions & 0 deletions ogr/services/github/pull_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from github import UnknownObjectException
from github.Label import Label as GithubLabel
from github.PullRequest import PullRequest as _GithubPullRequest
from github.Repository import Repository as _GithubRepository

from ogr.abstract import PRComment, PRStatus, PullRequest
from ogr.exceptions import GithubAPIException
Expand Down Expand Up @@ -137,13 +138,26 @@ def create(
github_repo = project.parent.github_repo
elif fork_username:
source_branch = f"{fork_username}:{source_branch}"
if fork_username != project.namespace and project.parent is not None:
github_repo = GithubPullRequest.__get_fork(
fork_username, project.parent.github_repo
)

created_pr = github_repo.create_pull(
title=title, body=body, base=target_branch, head=source_branch
)
logger.info(f"PR {created_pr.id} created: {target_branch}<-{source_branch}")
return GithubPullRequest(created_pr, project)

@staticmethod
def __get_fork(fork_username: str, repo: _GithubRepository) -> _GithubRepository:
forks = list(
filter(lambda fork: fork.owner.login == fork_username, repo.get_forks())
)
if not forks:
raise GithubAPIException("Requested fork doesn't exist")
return forks[0]

@staticmethod
def get(project: "ogr_github.GithubProject", id: int) -> "PullRequest":
pr = project.github_repo.get_pull(number=id)
Expand Down
Loading

0 comments on commit f3d806b

Please sign in to comment.