diff --git a/format_checker/common_checks.py b/format_checker/common_checks.py index a656a3e10..44fb23e03 100644 --- a/format_checker/common_checks.py +++ b/format_checker/common_checks.py @@ -3,6 +3,7 @@ import re import csv import subprocess +import requests from utils import ( get_committed_lines, get_uncommitted_lines, @@ -14,7 +15,7 @@ # Contains regexes for columns that are commmon to pr-data and tic-fic-data common_data = { - "Project URL": re.compile(r"(https:\/\/github.com)(\/(\w|\.|-)+){2}"), + "Project URL": re.compile(r"(https:\/\/github.com\/([\w|\.|-]+)\/([\w|\.|-]+))"), "SHA": re.compile(r"\b[0-9a-f]{40}\b"), "Module Path": re.compile(r"((\w|\.|-)+(\/|\w|\.|-)*)|^$"), "Fully-Qualified Name": re.compile( @@ -23,6 +24,27 @@ } +def check_repo_sanity(checked_projects, filename, row, i, log): + project_url = row["Project URL"] + if project_url in checked_projects: + return + checked_projects.add(project_url) + + match = common_data["Project URL"].fullmatch(project_url) + author = match.group(2) + repo = match.group(3) + + url = "https://api.github.com/repos/{}/{}".format(author, repo) + try: + resp = requests.get(url).json() + # Determine if it is a forked project + if resp.get("fork"): + log_esp_error(filename, log, f"{author}/{repo} is a forked repo") + except requests.exceptions.RequestException as e: + # handle(e) + pass + + def check_header(header, valid_dict, filename, log): """Validates that the header is correct.""" @@ -108,6 +130,7 @@ def run_checks(file, data_dict, log, commit_range, checks): if "1" in uncommitted_lines or "1" in committed_lines: check_header(list(header.values()), data_dict, file, log) if uncommitted_lines != [] or committed_lines != []: + checked_projects = set() for i, row in enumerate(info): i += 2 line = str(i) @@ -123,6 +146,9 @@ def run_checks(file, data_dict, log, commit_range, checks): if check_rule.__name__ == check_row_length.__name__: check_rule(len(header), *params) continue + if check_rule.__name__ == check_repo_sanity.__name__: + check_rule(checked_projects, *params) + continue check_rule(*params) else: log_info(file, log, "There are no changes to be checked") diff --git a/format_checker/pr_checker.py b/format_checker/pr_checker.py index 4f3be9339..947f319c3 100644 --- a/format_checker/pr_checker.py +++ b/format_checker/pr_checker.py @@ -7,6 +7,7 @@ check_row_length, check_sort, run_checks, + check_repo_sanity ) @@ -149,6 +150,7 @@ def run_checks_pr(log, commit_range): check_category, check_status, check_status_consistency, + check_repo_sanity ] run_checks(filename, pr_data, log, commit_range, checks) check_sort(filename, log) diff --git a/format_checker/requirements.txt b/format_checker/requirements.txt index 556ccd5aa..253f6b014 100644 --- a/format_checker/requirements.txt +++ b/format_checker/requirements.txt @@ -1 +1,2 @@ errorhandler==2.0.1 +requests==2.18.4 \ No newline at end of file