Merge pull request #2356 from bytexenon/pr-option
Overload `--json` to fetch via PR number
This commit is contained in:
@@ -784,7 +784,24 @@ def main():
|
||||
os.path.join(os.path.dirname(__file__), "resources/data.json")
|
||||
)
|
||||
else:
|
||||
sites = SitesInformation(args.json_file)
|
||||
json_file_location = args.json_file
|
||||
if args.json_file:
|
||||
# If --json parameter is a number, interpret it as a pull request number
|
||||
if args.json_file.isnumeric():
|
||||
pull_number = args.json_file
|
||||
pull_url = f"https://api.github.com/repos/sherlock-project/sherlock/pulls/{pull_number}"
|
||||
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)
|
||||
except Exception as error:
|
||||
print(f"ERROR: {error}")
|
||||
sys.exit(1)
|
||||
|
||||
Reference in New Issue
Block a user