mirror of
https://github.com/sherlock-project/sherlock
synced 2024-11-24 21:03:04 +00:00
Overload --json
to accept pull request data and remove --pull-request
parameter
This commit is contained in:
parent
e84c5fce37
commit
270fbf6473
1 changed files with 16 additions and 20 deletions
|
@ -655,14 +655,6 @@ def main():
|
||||||
default=None,
|
default=None,
|
||||||
help="Load data from a JSON file or an online, valid, JSON file.",
|
help="Load data from a JSON file or an online, valid, JSON file.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
|
||||||
"--pull-request",
|
|
||||||
"-pr",
|
|
||||||
action="store",
|
|
||||||
dest="pull_request",
|
|
||||||
default=None,
|
|
||||||
help="Load data.json file from a specific pull request.",
|
|
||||||
)
|
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--timeout",
|
"--timeout",
|
||||||
action="store",
|
action="store",
|
||||||
|
@ -787,23 +779,27 @@ def main():
|
||||||
|
|
||||||
# Create object with all information about sites we are aware of.
|
# Create object with all information about sites we are aware of.
|
||||||
try:
|
try:
|
||||||
if args.local and args.pull_request is None:
|
if args.local:
|
||||||
sites = SitesInformation(
|
sites = SitesInformation(
|
||||||
os.path.join(os.path.dirname(__file__), "resources/data.json")
|
os.path.join(os.path.dirname(__file__), "resources/data.json")
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# Check for conflicting --json and --pull-request arguments
|
|
||||||
if args.json_file is not None and args.pull_request is not None:
|
|
||||||
print("You cannot use both --json and --pull-request at the same time.")
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
json_file_location = args.json_file
|
json_file_location = args.json_file
|
||||||
if args.pull_request is not None:
|
if args.json_file:
|
||||||
pull_url = f"https://api.github.com/repos/sherlock-project/sherlock/pulls/{args.pull_request}"
|
# If --json parameter is a number, interpret it as a pull request number
|
||||||
pull_request_raw = requests.get(pull_url).text
|
if args.json_file.isnumeric():
|
||||||
pull_request_json = json_loads(pull_request_raw)
|
pull_number = args.json_file
|
||||||
head_commit_sha = pull_request_json["head"]["sha"]
|
pull_url = f"https://api.github.com/repos/sherlock-project/sherlock/pulls/{pull_number}"
|
||||||
json_file_location = f"https://raw.githubusercontent.com/sherlock-project/sherlock/{head_commit_sha}/sherlock_project/resources/data.json"
|
pull_request_raw = requests.get(pull_url).text
|
||||||
|
pull_request_json = json_loads(pull_request_raw)
|
||||||
|
|
||||||
|
# Check if it's a valid pull request
|
||||||
|
if "message" in pull_request_json:
|
||||||
|
print(f"ERROR: Pull request #{pull_number} not found.")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
head_commit_sha = pull_request_json["head"]["sha"]
|
||||||
|
json_file_location = f"https://raw.githubusercontent.com/sherlock-project/sherlock/{head_commit_sha}/sherlock_project/resources/data.json"
|
||||||
|
|
||||||
sites = SitesInformation(json_file_location)
|
sites = SitesInformation(json_file_location)
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
|
Loading…
Reference in a new issue