Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added input validation. #5

Merged
merged 1 commit into from
Feb 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions RepoSize/model.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import argparse
import re
import sys

parser =argparse.ArgumentParser(prog="reposize",description="Find the size of the specifed Github repository. Used this way: python reposize lucidrains/toolformer-pytorch",epilog="Thanks for using %(prog)s!")

parser.add_argument("<user/repo>")
parser.add_argument("-v","--version",action="version",version="%(prog)s 1.0.0")
parser.add_argument("repository")
parser.add_argument("-v","--version",action="version",version="%(prog)s 1.1.0")

arguments = parser.parse_args()
target_repo = arguments.repository

pattern = "^[a-zA-Z0-9_.-]+\/[a-zA-Z0-9_.-]+$"

match = re.match(pattern, target_repo)
try:
if not match:
raise ValueError("Invalid input")
except ValueError as e:
print(e)
print("Please enter a valid Github repository in the form <user>/<repository>")
sys.exit(1)


2 changes: 1 addition & 1 deletion RepoSize/reposize.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import model

def requester(request):

response = requests.get(
"https://api.github.com/repos/"+str(request)
)
Expand Down