Пример #1
0
async def backport_task_asyncio(
    commit_hash, branch, *, issue_number, created_by, merged_by
):
    """Backport a commit into a branch."""

    oauth_token = os.environ.get("GH_AUTH")
    async with aiohttp.ClientSession() as session:
        gh = gh_aiohttp.GitHubAPI(
            session, "python/cpython", oauth_token=oauth_token, cache=cache
        )

        if not util.is_cpython_repo():
            # cd to cpython if we're not already in it
            if "cpython" in os.listdir("."):
                os.chdir("./cpython")
            else:
                print(f"pwd: {os.getcwd()}, listdir: {os.listdir('.')}")

                await util.comment_on_pr(
                    gh,
                    issue_number,
                    f"""{util.get_participants(created_by, merged_by)}, Something is wrong... I can't backport for now.
                                   Please backport using [cherry_picker](https://pypi.org/project/cherry-picker/) on command line.
                                   ```
                                   cherry_picker {commit_hash} {branch}
                                   ```
                                   """,
                )
                await util.assign_pr_to_core_dev(gh, issue_number, merged_by)
        cp = cherry_picker.CherryPicker(
            "origin", commit_hash, [branch], prefix_commit=False
        )
        try:
            cp.backport()
        except cherry_picker.BranchCheckoutException:
            await util.comment_on_pr(
                gh,
                issue_number,
                f"""Sorry {util.get_participants(created_by, merged_by)}, I had trouble checking out the `{branch}` backport branch.
                                Please backport using [cherry_picker](https://pypi.org/project/cherry-picker/) on command line.
                                ```
                                cherry_picker {commit_hash} {branch}
                                ```
                                """,
            )
            await util.assign_pr_to_core_dev(gh, issue_number, merged_by)
            cp.abort_cherry_pick()
        except cherry_picker.CherryPickException:
            await util.comment_on_pr(
                gh,
                issue_number,
                f"""Sorry, {util.get_participants(created_by, merged_by)}, I could not cleanly backport this to `{branch}` due to a conflict. 
                                Please backport using [cherry_picker](https://pypi.org/project/cherry-picker/) on command line.
                                ```
                                cherry_picker {commit_hash} {branch}
                                ```
                                """,
            )
            await util.assign_pr_to_core_dev(gh, issue_number, merged_by)
            cp.abort_cherry_pick()
Пример #2
0
def backport_task(commit_hash, branch, *, issue_number, created_by, merged_by):
    """Backport a commit into a branch."""
    if not util.is_cpython_repo():
        # cd to cpython if we're not already in it
        if "cpython" in os.listdir('.'):
            os.chdir('./cpython')
        else:
            print(f"pwd: {os.pwd()}, listdir: {os.listdir('.')}")
            util.comment_on_pr(
                issue_number,
                f"""{util.get_participants(created_by, merged_by)}, Something is wrong... I can't backport for now.
                               Please backport using [cherry_picker](https://pypi.org/project/cherry-picker/) on command line."""
            )
    cp = cherry_picker.CherryPicker('origin', commit_hash, [branch])
    try:
        cp.backport()
    except cherry_picker.BranchCheckoutException:
        util.comment_on_pr(
            issue_number,
            f"""Sorry {util.get_participants(created_by, merged_by)}, I had trouble checking out the `{branch}` backport branch.
                            Please backport using [cherry_picker](https://pypi.org/project/cherry-picker/) on command line."""
        )
        cp.abort_cherry_pick()
    except cherry_picker.CherryPickException:
        util.comment_on_pr(
            issue_number,
            f"""Sorry, {util.get_participants(created_by, merged_by)}, I could not cleanly backport this to `{branch}` due to a conflict. 
                            Please backport using [cherry_picker](https://pypi.org/project/cherry-picker/) on command line."""
        )
        cp.abort_cherry_pick()