Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2] fix(2051): fix function that does not exist #29

Merged

Conversation

yoshwata
Copy link
Contributor

@yoshwata yoshwata commented Dec 7, 2020

Context

Joi.validate is not exist today.

TypeError: Joi.validate is not a function

We shold use schema.validate() instead.

Objective

This PR enables validateConfig function by fixing joi.validate.

References

screwdriver-cd/screwdriver#2051

License

I confirm that this contribution is made under the terms of the license found in the root directory of this repository's source tree and that I have the authority necessary to make this contribution on behalf of its copyright owner.

index.js Outdated
@@ -181,7 +181,7 @@ class EmailNotifier extends NotificationBase {

// Validate the settings email object
static validateConfig(config) {
return Joi.validate(config, SCHEMA_EMAIL);
return SCHEMA_EMAIL.validate(config);
Copy link
Contributor

@ibu1224 ibu1224 Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SCHEMA_EMAIL cannot be validate correctly.
In the case of the above, you have not validate the following

test:
  settings:
    email: ←Not validate.

It is better to use SCHEMA_BUILD_SETTINGS.

Copy link
Contributor

@wahapo wahapo Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to call validate only if it has settings.email, I guess we can't use SCHEMA_BUILD_SETTINGS.
https://github.com/screwdriver-cd/config-parser/pull/105/files

Copy link
Contributor

@ibu1224 ibu1224 Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The role of the validator in this plugin is to return whether the email setting is valid.
If the following yaml may not work properly.

  email:
   image: node12
    requires: [ ~commit, ~pr ]
    settings:
      emaill ←typo:
        addresses:
          - [email protected]
        statuses:
          - SUCCESS
          - FAILURE

When actually used, it works by simply passing the job settings.

Copy link
Contributor

@wahapo wahapo Dec 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If emaill is made available by Custom Notifications, it is not a typo.
https://docs.screwdriver.cd/cluster-management/configure-api#notifications-plugin

I don't think there's a good way to handle it at the moment, we'll just have to verify the contents of the settings.email.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I was confusing SCHEMA_BUILD_SETTINGS and SCHEMA_BUILD_DATA. Probably it should use SCHEMA_BUILD_SETTINGS.

@@ -31,19 +31,19 @@ const SCHEMA_ADDRESSES = Joi.array()
.min(1);
const SCHEMA_STATUSES = Joi.array()
.items(schema.plugins.notifications.schemaStatus)
.min(1);
.min(0);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think 0 statuses acceptable

const SCHEMA_EMAIL = Joi.alternatives().try(
Joi.object().keys({ addresses: SCHEMA_ADDRESSES, statuses: SCHEMA_STATUSES }),
SCHEMA_ADDRESS, SCHEMA_ADDRESSES
);
const SCHEMA_BUILD_SETTINGS = Joi.object()
const SCHEMA_EMAIL_SETTINGS = Joi.object()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fix confusing value name

@yoshwata yoshwata changed the title fix(2051): fix function that does not exist [2] fix(2051): fix function that does not exist Dec 7, 2020
@tkyi tkyi merged commit cbc52b6 into screwdriver-cd:master Dec 7, 2020
@yoshwata yoshwata deleted the fix-removed-function branch December 8, 2020 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants