Пример #1
0
def gql(name: str,
        repo: str,
        limit: int = 10,
        all: bool = False,
        web: bool = False):
    """
    Sub-command for GraphQL mode.
    """
    issues: Optional[Iterable] = None
    rate_limit: int = 0

    # Check for GitHub Token.
    token: Union[str, bool] = utils.check_credential()

    # Identify the flags passed.
    query, variables, mode = services.identify_mode(name, repo, user)

    # Spinner
    spinner = Halo(text="Fetching repos...", spinner="dots")
    spinner.start()

    # API Call
    response = services.caller(token, query, variables)

    spinner.succeed("Repos fetched.")

    # Data Filtering
    if mode == "org" or mode == "user":
        issues, rate_limit = services.org_user_pipeline(response, mode)

    if mode == "repo":
        issues, rate_limit = services.extract_repo_issues(response)

    table_headers: List = ["Title", "Issue URL"]

    # No good first issues found.
    if not issues:
        print(f"Remaining requests:dash:: {rate_limit}")

        return print("No good first issues found!:mask:")
    # Handle limiting the output displayed.
    limiter = utils.identify_limit(limit, all)

    # Handle displaying issues on browser.
    if web:
        html_data = tabulate(issues[:limiter], table_headers, tablefmt="html")
        return utils.web_server(html_data)

    print(
        tabulate(
            issues[:limiter],
            table_headers,
            tablefmt="fancy_grid",
            showindex=True,
        ))

    print(f"Remaining requests:dash:: {rate_limit}")
    print("Happy Hacking :tada::zap::rocket:")
Пример #2
0
def gql_rate_limit() -> int:
    """
    Fetch rate_limit for GraphQL API.
    """
    token: Union[str, bool] = check_credential()

    # Spinner
    spinner = Halo(text="Getting rate limit...", spinner="dots")
    spinner.start()

    payload: Dict = services.caller(token, rate_limit_query, {})

    spinner.succeed("rate limit")

    return payload["data"].get("rateLimit").get("remaining")
Пример #3
0
def search(
    name: str,
    repo: str,
    user: bool,
    web: bool,
    limit: int,
    all: bool,
    hacktoberfest: bool,
):
    """
    Search for good first issue on organization or users.
    """

    if name is None and not hacktoberfest:
        utils.print_help_msg(search)
        sys.exit()

    issues: Optional[Iterable] = None
    rate_limit: int = 0

    # Check for GitHub Token.
    token: Union[str, bool] = utils.check_credential()

    # Identify the flags passed.
    query, variables, mode = services.identify_mode(name, repo, user,
                                                    hacktoberfest)

    # Spinner
    spinner = Halo(text="Fetching repos...", spinner="dots")
    spinner.start()

    # API Call
    response = services.caller(token, query, variables)

    spinner.succeed("Repos fetched.")

    # Data Filtering
    if mode in ["org", "user"]:
        issues, rate_limit = services.org_user_pipeline(response, mode)

    if mode == "repo":
        issues, rate_limit = services.extract_repo_issues(response)

    if mode == "search":
        issues, rate_limit = services.extract_search_results(response)

    table_headers: List = ["Title", "Issue URL"]

    # No good first issues found.
    if not issues:
        console.print(
            f"Remaining requests:dash:: {rate_limit}",
            style="bold green",
        )

        return console.print(
            "No good first issues found!:mask:",
            style="bold red",
        )
    # Handle limiting the output displayed.
    limiter = utils.identify_limit(limit, all)

    # Handle displaying issues on browser.
    if web:
        html_data = tabulate(issues[:limiter], table_headers, tablefmt="html")
        return utils.web_server(html_data)

    issue_count: int = len(issues)
    row_ids: List[int] = utils.get_row_ids(issue_count, limiter)
    print(
        tabulate(
            issues[:limiter],
            table_headers,
            tablefmt="fancy_grid",
            showindex=row_ids,
        ))

    console.print(f"Remaining requests:dash:: {rate_limit}",
                  style="bold green")
    console.print("Happy Hacking :tada::zap::rocket:", style="bold blue")