def get(name: str, repo: str, limit: int = 10, all: bool = False, web: bool = False): """ Sub-command for REST API mode """ token: Union[str, bool] = utils.check_credential() limiter: Optional[int] = utils.identify_limit(limit, all) table_headers: List[str] = ["Title", "Issues"] if not repo: issues, rate_limit = services.owner_repos(name, token, limiter) else: issues, rate_limit = services.unit_owner_repo(name, repo, token, limiter) # Handle empty issues. if not issues: print(f"Remaining requests {rate_limit}", ) return print("No good first issues found!") # Handle displaying issues on browser. if web: html_data = tabulate(issues, table_headers, tablefmt="html") return utils.web_server(html_data) print( tabulate(issues, table_headers, tablefmt="fancy_grid", showindex=True)) print(f"Remaining requests {rate_limit}") print("Happy Hacking")
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:")
def get(name: str, repo: str, limit: int, all: bool, web: bool): """ Sub-command for REST API mode """ token: Union[str, bool] = utils.check_credential() limiter: Optional[int] = utils.identify_limit(limit, all) table_headers: List[str] = ["Title", "Issues"] if not repo: issues, rate_limit = services.owner_repos(name, token, limiter) else: issues, rate_limit = services.unit_owner_repo(name, repo, token, limiter) # Handle empty issues. 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 displaying issues on browser. if web: html_data = tabulate(issues, 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, 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")
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")
def test_identify_limit(limit, all, expected): """ Check correctness of `limiter` value returned. """ assert identify_limit(limit, all) == expected