Esempio n. 1
0
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)
Esempio n. 2
0
def create_pull_request(github_repo: Repository, source_branch: str, destination_branch: str, label: str):
    print('Creating pull request...')
    pull_request = github_repo.create_pull(
        title=PULL_REQUEST_TITLE_TEMPLATE.format(source_branch, destination_branch),
        body=PULL_REQUEST_DESCRIPTION.format(source_branch, destination_branch),
        base=destination_branch,
        head=source_branch)
    pull_request.add_to_labels(label)
    print(f'Created pull request {pull_request.url} with label {label}')
Esempio n. 3
0
def create_or_edit_pr(title: str, body: str, skills_repo: Repository,
                      user, branch: str):
    base = skills_repo.default_branch
    head = '{}:{}'.format(user.login, branch)
    pulls = list(skills_repo.get_pulls(base=base, head=head))
    if pulls:
        pull = pulls[0]
        if 'mycroft-skills-kit' in pull.body:
            pull.edit(title, body)
        else:
            raise PRModified('Not updating description since it was not autogenerated')
        return pull
    else:
        return skills_repo.create_pull(title, body, base=base, head=head)
Esempio n. 4
0
def create_or_edit_pr(title: str, body: str, skills_repo: Repository,
                      user, branch: str, repo_branch: str):
    base = repo_branch
    head = '{}:{}'.format(user.login, branch)
    pulls = list(skills_repo.get_pulls(base=base, head=head))
    if pulls:
        pull = pulls[0]
        if 'mycroft-skills-kit' in pull.body:
            pull.edit(title, body)
        else:
            raise PRModified('Not updating description since it was not autogenerated')
        return pull
    else:
        try:
            return skills_repo.create_pull(title, body, base=base, head=head)
        except GithubException as e:
            if e.status == 422:
                raise SkillNameTaken(title) from e
            raise
Esempio n. 5
0
 def create_pull_request(repository: Repository,
                         base_branch: Branch,
                         head_branch: Branch,
                         title: str,
                         body: str = "") -> PullRequest:
     """
     Create Pull Request in the forked repository
     :param repository: Forked Repository.
     :param base_branch: Base branch of the PR.
     :param head_branch: Target branch of the PR.
     :param title: Title of the PR.
     :param body: Content of the PR. like Summary etc.
     :return: Created Pull Request.
     """
     LOGGER.info("Creating Pull Request...")
     pull_request = repository.create_pull(title=title,
                                           body=body,
                                           base=base_branch.name,
                                           head=head_branch.name)
     LOGGER.info("Created Pull Request <%s>.", pull_request.title)
     return pull_request