def create_branch(repository: Repository, source_branch_name: str, target_branch_name: str) -> Branch: """ Create branch in the forked repository. :param repository: Forked repository. :param source_branch_name: Name of the base branch from which target branch is created. :param target_branch_name: Target name of the new branch. :return: Created branch. """ source_branch = repository.get_branch(source_branch_name) repository.create_git_ref(ref='refs/heads/' + target_branch_name, sha=source_branch.commit.sha) return repository.get_branch(target_branch_name)
def create_pr( repo: Repository, pr_branch_name: str, head: str, file: ContentFile, updated_content: str, pr_title: str, pr_body: str, ): try: repo.get_branch(pr_branch_name) print(f"Branch '{pr_branch_name}' already exist. Skipping update.") return except GithubException as ex: if ex.status != 404: raise pr_branch = repo.create_git_ref(pr_branch_name, head) repo.update_file( file.path, f"{pr_title}\n\n{pr_body}", updated_content, file.sha, branch=pr_branch_name, ) repo.create_pull(title=pr_title, body=pr_body, head=pr_branch.ref, base=BASE_BRANCH)