Exemplo n.º 1
0
def open_useful_compares(pat: str, origin: str):
    gh = Github(pat)
    origin = gh.get_repo(origin)
    repo_branches = extract_branches(origin)

    pr_branches = extract_branches(origin, from_pulls=True)

    # Iterate through forks, getting each one's branches.
    # From that list, remove all branches that exist in origin,
    # and all branches in all PRs
    forks: Repository = origin.get_forks()
    for fork in forks:
        heads = reduce_to_potential_pr_heads(fork, pr_branches, origin)
        heads = [construct_fork_label(fork, branch) for branch in heads]

        for head in heads:
            input("Press Enter to review potential PR from {}".format(head))
            compare_in_browser(origin, head)
            wait_for_api(gh)
Exemplo n.º 2
0
def open_useful_compares(pat: str, origin: str):
    gh = Github(pat)
    repo = gh.get_repo(origin)
    repo_branches = extract_branches(repo)

    pr_branches = extract_branches(repo, from_pulls=True)

    # Iterate through forks, getting each one's branches.
    # From that list, remove all branches that exist in origin,
    # and all branches in PRs
    forks: object = repo.get_forks()
    for f in forks:
        check_branches = reduce_to_potential_pr_heads(extract_branches(f),
                                                      pr_branches,
                                                      repo_branches)
        compare_labels = set(
            map(lambda b: f.owner.login + ":" + b, check_branches))

        for c in compare_labels:
            input("Press Enter to review potential PR from {}".format(c))
            compare_in_browser(to_compare=c, base_url=construct_base_url(repo))
            wait_for_api(gh)
Exemplo n.º 3
0
def reduce_to_potential_pr_heads(fork: Repository, pr_branches: Set[str],
                                 origin: Repository) -> Set[str]:
    """
    Finds all branches in a fork and removes those which do not need to be
    passed on to compare_in_browser().

    :return: All branches contain unmerged changes, but aren't in an open PR.
    """

    fork_branches = extract_branches(fork)

    # Remove branches for which a PR is open first...
    potential_pr_branches = fork_branches.difference(pr_branches)

    # ... and those either identical or simply behind origin:default
    potential_pr_branches = potential_pr_branches.difference(
        head for head in potential_pr_branches
        if get_compare_status(origin, fork, head) != "diverged")

    return potential_pr_branches
Exemplo n.º 4
0
def test_extract_branches():
    assert ("branch-in-pr-1" and "branch-in-pr-2") in pr_branches
    assert ("master" and "12-test-branch") in extract_branches(repo)
Exemplo n.º 5
0
from popr.prep_compare_base_url import prep_compare_base_url
from popr.extract_branches import extract_branches
from popr.reduce_to_potential_pr_heads import reduce_to_potential_pr_heads

# Setup test objects
repo: Repository = Github().get_repo("katrinleinweber/poPR")
fork: Repository = [
    f for f in repo.get_forks() if f.owner.login == "poPR-test"
][0]


def test_version():
    assert __version__ == "0.1.0"


pr_branches = extract_branches(repo, from_pulls=True)


def test_extract_branches():
    assert ("branch-in-pr-1" and "branch-in-pr-2") in pr_branches
    assert ("master" and "12-test-branch") in extract_branches(repo)


def test_reduce_to_potential_pr_heads():
    potential_branches = reduce_to_potential_pr_heads(fork, pr_branches, repo)
    assert ("branch-1-without-PR"
            and "branch-2-without-PR") in potential_branches
    assert ("12-test-branch"
            and "branch-without-diff") not in potential_branches

Exemplo n.º 6
0
def test_extract_branches():
    assert extract_branches(repo, from_pulls=True) == {
        "branch-in-pr-1",
        "branch-in-pr-2",
    }
    assert extract_branches(repo) == {"master"}