Skip to content

Commit

Permalink
add reserved keyword linter to CI (openedx#23499)
Browse files Browse the repository at this point in the history
  • Loading branch information
estute committed Apr 1, 2020
1 parent 3c35f21 commit 9b9e2f7
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 0 deletions.
33 changes: 33 additions & 0 deletions db_keyword_overrides.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# This file is used by the 'check_reserved_keywords' management command to allow specific field names to be overridden
# when checking for conflicts with lists of restricted keywords used in various database/data warehouse tools.
# For more information, see: https://github.com/edx/edx-django-release-util/release_util/management/commands/check_reserved_keywords.py
#
# overrides should be added in the following format:
# - ModelName.field_name
---
MYSQL:
- CornerstoneGlobalConfiguration.key
- CourseCompleteImageConfiguration.default
- DegreedEnterpriseCustomerConfiguration.key
- ExperimentData.key
- ExperimentKeyValue.key
- GeneratedCertificate.key
- HistoricalDegreedEnterpriseCustomerConfiguration.key
- HistoricalExperimentKeyValue.key
- HistoricalGeneratedCertificate.key
- KVStore.key
- LTICredential.key
- NotificationType.key
- OAuth2ProviderConfig.key
- ProctoredExamStudentAllowanceHistory.key
- ProctoredExamStudentAllowance.key
- SAPSuccessFactorsEnterpriseCustomerConfiguration.key
- Settings.interval
- UserCourseTag.key
- UserOrgTag.key
- UserPreference.key
- XAPILRSConfiguration.key
SNOWFLAKE:
- CourseOverview.start
- HistoricalCourseOverview.start
STITCH:
37 changes: 37 additions & 0 deletions pavelib/quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,43 @@ def run_pii_check(options):
fail_quality('pii', full_log)


@task
@needs('pavelib.prereqs.install_python_prereqs')
@timed
def check_keywords():
"""
Check Django model fields for names that conflict with a list of reserved keywords
"""
report_path = os.path.join(Env.REPORT_DIR, 'reserved_keywords')
sh("mkdir -p {}".format(report_path))

overall_status = True
for env, env_settings_file in [('lms', 'lms.envs.test'), ('cms', 'cms.envs.test')]:
report_file = "{}_reserved_keyword_report.csv".format(env)
override_file = os.path.join(Env.REPO_ROOT, "db_keyword_overrides.yml")
try:
sh(
"export DJANGO_SETTINGS_MODULE={settings_file}; "
"python manage.py {app} check_reserved_keywords "
"--override_file {override_file} "
"--report_path {report_path} "
"--report_file {report_file}".format(
settings_file=env_settings_file, app=env, override_file=override_file,
report_path=report_path, report_file=report_file
)
)
except BuildFailure:
overall_status = False

if not overall_status:
fail_quality(
'keywords',
'Failure: reserved keyword checker failed. Reports can be found here: {}'.format(
report_path
)
)


@task
@needs('pavelib.prereqs.install_python_prereqs')
@cmdopts([
Expand Down
2 changes: 2 additions & 0 deletions scripts/generic-ci-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ case "$TEST_SUITE" in
run_paver_quality run_xsscommitlint || { EXIT=1; }
echo "Running PII checker on all Django models..."
run_paver_quality run_pii_check || { EXIT=1; }
echo "Running reserved keyword checker on all Django models..."
run_paver_quality check_keywords || { EXIT=1; }
;;

esac
Expand Down

0 comments on commit 9b9e2f7

Please sign in to comment.