Beispiel #1
0
def main():
    for repo_name in config.REPO_PATHS:
        repo = CONN.get_repo(repo_name)
        print(repo.name)
        events_c = Counter()

        events = list(repo.get_events())
        ev = [x.type for x in events]
        events_c.update(ev)

        for e in events:
            data = dict(username=e.actor.login,
                        created_at=str(e.created_at.date()),
                        type=e.type)
            print(data)

            p = e.payload
            payload_data = dict(
                action=p.get("action"),
                comments=p.get("comment"),
                pull_request=p.get("pull_request"),
                issue=p.get("issue"),
            )
            for k, v in payload_data.items():
                if v:
                    if isinstance(v, dict):
                        new_v = list(v.keys())
                        payload_data[k] = new_v
            pprint.pprint(payload_data)
        print()

    pprint.pprint(events_c.most_common())
Beispiel #2
0
def check_user(username):
    """
    Request a username on Github and raise an error if it cannot be retrieved.

    :param str username: Name of Github user or organization.

    :return: None
    :raises: ValueError
    """
    print(username, end=" ")
    try:
        CONN.get_user(username)
        print("OK")
    except UnknownObjectException:
        print()
        raise ValueError(f"Could not find username: {username}")
Beispiel #3
0
def main():
    """
    Main command-line function to demonstration iterating through commits on
    a branch. All commits in the branch's history are printed, including ones
    that come from merging a feature branch into master. There is an escape
    though in the traversal to avoid printing a commit which has been seen
    before in the traversal.
    """
    #
    # A good showcase of a repo with many branches.
    #

    repo = CONN.get_repo("Python/CPython")

    fetched_branches = list(repo.get_branches())
    branch_dict = {x.name: x for x in fetched_branches}

    branch_list = []
    for b in ("master", "develop"):
        branch = branch_dict.pop(b, None)
        if branch:
            branch_list.append(branch)

    remaining = branch_dict.values()
    branch_list.extend(remaining)

    for branch in branch_list:
        print(f"Branch: {branch.name}")

        head_commit = branch.commit
        print(head_commit)
    print()

    #
    # Showcase iterating through commits on a repo with few branches.
    #

    # Note that seen commits are only keep track of here within a branch and
    # then it resets. If you want to avoid counting the same activity across
    # branches then this must be handled differently.

    repo = CONN.get_repo("MichaelCurrin/aggre-git")
    for branch in repo.get_branches():
        head_commit = branch.commit
        traverse_commits_short(head_commit)
Beispiel #4
0
def main():
    """
    Command-line entry-point.
    """
    print(f"Search query:")
    print(f"    {SEARCH_QUERY}")

    issues_resp = CONN.search_issues(SEARCH_QUERY)
    display(issues_resp)
Beispiel #5
0
def main():
    repos = [CONN.get_repo(repo_name) for repo_name in config.REPO_PATHS]

    for repo in repos:
        print(repo.name)
        for commit in repo.get_commits():
            data = extract(commit)
            pprint.pprint(data)
            print()
        print()
Beispiel #6
0
def check_repo(repo_path):
    """
    Request a Gitub repo by path and raise an error if it cannot be retrieved.

    The lazy parameter must be used when retrieving repos in order
    to fail immediately. This parameter does not exist for `.get_users()`.

    :param repo_path: str in the format "some_user/some_repo_name".

    :return: None
    :raises: ValueError
    """
    print(repo_path, end=" ")
    try:
        CONN.get_repo(repo_path, lazy=False)
        print("OK")
    except UnknownObjectException:
        print()
        raise ValueError(f"Could not find repo: {repo_path}")
Beispiel #7
0
def main():
    for repo_name in config.REPO_PATHS:
        repo = CONN.get_repo(repo_name)
        issues_resp = repo.get_issues()

        for issue in issues_resp:
            issue_data = extract(issue)
            pprint.pprint(issue_data)
        print()
    print("===========")
Beispiel #8
0
def main():
    repos = [CONN.get_repo(repo_name) for repo_name in config.REPO_PATHS]

    for repo in repos:
        print(f"### REPO: {repo.name} ###")
        print()

        for pr in repo.get_pulls():
            report(pr)
            print("---")
        print()
Beispiel #9
0
def main():
    for repo_name in config.REPO_PATHS:
        repo = CONN.get_repo(repo_name)
        print(repo.name)

        for comment in repo.get_issues_comments():
            data = {
                "username": comment.user.login,
                "date": str(comment.created_at.date()),
            }
            print(data)
        print()
Beispiel #10
0
def main():
    """
    Main command-line entry-point.
    """
    login = config.REPO_OWNER
    user = CONN.get_user(login)

    print("Profile details")
    print_profile_details(user)

    print("Counts")
    print_counts(user)
Beispiel #11
0
def main():
    try:
        o = CONN.get_organization(config.REPO_OWNER)
    except UnknownObjectException:
        msg = (f"Could not finder organization: {config.REPO_OWNER}."
               f" Did you provide a user by accident?")
        raise ValueError(msg)

    try:
        for t in o.get_teams():
            print_details(t)
    except UnknownObjectException:
        msg = f"Unable to access teams for org: {config.REPO_OWNER}"

        raise ValueError(msg)
Beispiel #12
0
def main():
    try:
        o = CONN.get_organization(config.REPO_OWNER)
    except UnknownObjectException:
        msg = (f"Could not find organization: {config.REPO_OWNER}."
               f" Did you provide a user by accident?")
        raise ValueError(msg)

    teams = list(o.get_teams())

    print(f"Teams: {len(teams)}\n")

    for t in teams:
        print(f"Team: {t.name}")
        print("---")

        for m in t.get_members():
            user.print_details(m)
            print()
        print()
Beispiel #13
0
def main():
    for repo_name in config.REPO_PATHS:
        repo = CONN.get_repo(repo_name)
        print(repo.name)
        print()

        prs = repo.get_pulls()

        for pr in prs:
            print(pr.title)

            reviews = list(pr.get_reviews())
            if reviews:
                for rev in reviews:
                    # 'COMMENTED' 'APPROVED' 'DISMISSED' 'CHANGES_REQUESTED'
                    print(rev.state)
                    print(str(rev.submitted_at.date()))
                    print(rev.user.login)
            else:
                print("skip")
            print()
Beispiel #14
0
def main():
    for repo_name in config.REPO_PATHS:
        repo = CONN.get_repo(repo_name)
        print(repo.name)

        for comment in repo.get_pulls_comments():
            data = dict(
                date=str(comment.created_at.date()),
                username=comment.user.login,
                reactions=[],
            )

            reactions = list(comment.get_reactions())
            for r in reactions:
                reaction_data = {
                    "username": r.user.login,
                    "content": r.content,
                    "date": str(r.created_at.date()),
                }
                data["reactions"].append(reaction_data)
                pprint.pprint(data)
Beispiel #15
0
def main():
    org = CONN.get_organization(config.REPO_OWNER)
    details = extract(org)
    print(details)
Beispiel #16
0
def main():
    repo = CONN.get_repo("Python/CPython")
    display_repo(repo)

    repo = CONN.get_repo("MichaelCurrin/aggre-git")
    display_repo(repo)
Beispiel #17
0
def main():
    login = config.REPO_OWNER
    user = CONN.get_user(login)

    for event in user.get_events():
        print_details(event)