Skip to content
Open
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
17 changes: 17 additions & 0 deletions format_checker/common_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import re
import csv
import subprocess
import requests
from utils import (
get_committed_lines,
get_uncommitted_lines,
log_info,
log_std_error,
log_esp_error,
log_archived_error,
)


Expand All @@ -23,6 +25,17 @@
}


def check_repo_archived(checked_projects, filename, row, i, log):
project_url = row["Project URL"]
try:
resp = requests.get(project_url)
# Determine if it is an archived project
if "This repository has been archived by the owner. It is now read-only." in resp.text:
log_archived_error(filename, log, i, row, "Project URL")
except requests.exceptions.RequestException as e:
log_esp_error(filename, log, "The check for repo-archived failed due to ERROR:" + str(e))


def check_header(header, valid_dict, filename, log):
"""Validates that the header is correct."""

Expand Down Expand Up @@ -108,6 +121,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)
Expand All @@ -123,6 +137,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_archived.__name__:
check_rule(checked_projects, *params)
continue
check_rule(*params)
else:
log_info(file, log, "There are no changes to be checked")
Expand Down
19 changes: 17 additions & 2 deletions format_checker/pr_checker.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""Implements rule checks for the pr-data.csv file."""

import re
from utils import log_std_error, log_warning
from utils import log_std_error, log_esp_error, log_warning
import requests
from common_checks import (
check_common_rules,
check_row_length,
check_sort,
check_repo_archived,
run_checks,
)

Expand Down Expand Up @@ -117,10 +119,22 @@ def check_status_consistency(filename, row, i, log):
# If it contains a PR link, it should be a valid one
else:
check_pr_link(filename, row, i, log)

if row["Status"] == "RepoArchived":
try:
response = requests.get(row["Project URL"])
# Determine if it is not archived
if "This repository has been archived by the owner. It is now read-only." not in response.text:
log_esp_error(filename, log, "Status should not be \"RepoArchived\" when the repo is not archived.\n" +
"row " + str(i) + ", URL: " + row["Project URL"])
except requests.exceptions.RequestException as e:
# handle(e)
pass

if row["Status"] == "" and row["PR Link"] != "":
check_pr_link(filename, row, i, log)
log_std_error(filename, log, i, row, "Status should not be empty when a PR link is provided.")
log_esp_error(filename, log, "Status should not be empty when a PR link is provided.\n" +
"row " + str(i) + ", URL: " + row["Project URL"])

def check_notes(filename, row, i, log):
"""Checks validity of Notes."""
Expand Down Expand Up @@ -149,6 +163,7 @@ def run_checks_pr(log, commit_range):
check_category,
check_status,
check_status_consistency,
check_repo_archived,
]
run_checks(filename, pr_data, log, commit_range, checks)
check_sort(filename, log)
1 change: 1 addition & 0 deletions format_checker/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
errorhandler==2.0.1
requests==2.18.4
19 changes: 19 additions & 0 deletions format_checker/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,26 @@ def log_esp_error(filename, log, message):
log_esp_error.tracker += 1
log.error("ERROR: On file " + filename + ": " + message)


def log_archived_error(filename, log, line, row, key):
"""Logs a archived-related error."""

# log_archived_error.tracker += 1 # AttributeError: 'function' object has no attribute 'tracker'
log_esp_error.tracker += 1
log.error(
"ERROR: On file "
+ filename
+ ", row "
+ line
+ ":\n"
+ "Archived "
+ key
+ ': "'
+ row[key]
+ '"'
)


def log_warning(filename, log, line, message):
"""Logs a warning."""

Expand Down