Skip to content

Commit

Permalink
feat: Make it valid for ORGS, LABELS, and PEOPLE to be empty (openedx#28
Browse files Browse the repository at this point in the history
)

This was prompted because we actually want LABELS to be empty
as an intermediate step towards removing label creation from openedx-webhooks.

Per the docs on https://pypi.org/project/schema/ (scroll down to "Dictionaries"),
schema validation will fail on empty dictionaries unless you specifically
make the schema `Or(<dict>, {})`. 

The only changes in this PR are wrapping each dict schema in `Or(..., {})`.
I tested locally that this fixes
openedx/openedx-webhooks-data#191

Part of openedx/openedx-webhooks#218
  • Loading branch information
kdmccormick committed May 31, 2023
1 parent f857602 commit 56a51f7
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 54 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ Change Log
This project adheres to Semantic Versioning (https://semver.org/).


2023-05-30
~~~~~~~~~~

* Make it valid for ORGS, LABELS, and PEOPLE to be empty. This was prompted
because we actually want LABELS to be empty as an intermediate step towards
removing label creation from openedx-webhooks.

2023-03-02
~~~~~~~~~~

Expand Down
2 changes: 1 addition & 1 deletion repo_tools_data_schema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Schema for repo-tools-data.
"""

__version__ = '1.0'
__version__ = '1.1'

from .repo_tools_data_schema import validate_labels, validate_orgs, validate_people, validate_salesforce_export
115 changes: 62 additions & 53 deletions repo_tools_data_schema/repo_tools_data_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,52 +140,58 @@ def _check(d):
)

PEOPLE_SCHEMA = Schema(
{
And(github_username, not_data_key): And(
{
'name': not_empty_string,
'email': valid_email,
'agreement': valid_agreement,
Optional('institution'): not_empty_string,
Optional('is_robot'): True,
Optional('jira'): not_empty_string,
Optional('comments'): [str],
Optional('other_emails'): [valid_email],
Optional('before'): {
datetime.date: And(
{
Optional('agreement'): valid_agreement,
Optional('institution'): not_empty_string,
Optional('comments'): [str],
Optional('committer'): COMMITTER_SCHEMA,
},
check_institution,
),
Or(
{
And(github_username, not_data_key): And(
{
'name': not_empty_string,
'email': valid_email,
'agreement': valid_agreement,
Optional('institution'): not_empty_string,
Optional('is_robot'): True,
Optional('jira'): not_empty_string,
Optional('comments'): [str],
Optional('other_emails'): [valid_email],
Optional('before'): {
datetime.date: And(
{
Optional('agreement'): valid_agreement,
Optional('institution'): not_empty_string,
Optional('comments'): [str],
Optional('committer'): COMMITTER_SCHEMA,
},
check_institution,
),
},
Optional('beta'): bool,
Optional('contractor'): bool,
Optional('committer'): COMMITTER_SCHEMA,
Optional('email_ok'): bool,
},
Optional('beta'): bool,
Optional('contractor'): bool,
Optional('committer'): COMMITTER_SCHEMA,
Optional('email_ok'): bool,
},
check_institution,
),
}
check_institution,
),
},
{},
),
)

ORGS_SCHEMA = Schema(
{
str: {
Optional("name"): not_empty_string,
"agreement": Or("institution", "none"),
Optional("contractor"): bool,
Optional("committer"): bool,
Optional("internal-ghorgs"): [str],
Optional(Or("contact", "contact1", "contact2")): {
"name": not_empty_string,
"email": valid_email,
Or(
{
str: {
Optional("name"): not_empty_string,
"agreement": Or("institution", "none"),
Optional("contractor"): bool,
Optional("committer"): bool,
Optional("internal-ghorgs"): [str],
Optional(Or("contact", "contact1", "contact2")): {
"name": not_empty_string,
"email": valid_email,
},
},
},
}
{},
)
)


Expand All @@ -194,19 +200,22 @@ def color(s):


LABELS_SCHEMA = Schema(
{
str: Or(
# A label we don't want:
{
"delete": True,
},
# A label we want:
{
"color": color,
Optional("description"): str,
},
),
},
Or(
{
str: Or(
# A label we don't want:
{
"delete": True,
},
# A label we want:
{
"color": color,
Optional("description"): str,
},
),
},
{},
),
)


Expand Down

0 comments on commit 56a51f7

Please sign in to comment.