From e46197f33e8264800e75ae3ff1fa6e52429cd891 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 29 Oct 2024 15:37:14 +0100 Subject: [PATCH] add missing depedency for email format support --- CHANGELOG.md | 1 + plugins/nf-schema/build.gradle | 1 + .../validation/ValidateParametersTest.groovy | 52 +++++++++++++++++++ .../src/testResources/nextflow_schema.json | 4 +- 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 01759d3..12ef25a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ ## Bug fixes 1. Fixed a bug in `samplesheetToList` that caused output mixing when the function was used more than once in channel operators. +2. Added a missing depencency for email format validation. ## Improvements diff --git a/plugins/nf-schema/build.gradle b/plugins/nf-schema/build.gradle index 3d72ac6..c4ee257 100644 --- a/plugins/nf-schema/build.gradle +++ b/plugins/nf-schema/build.gradle @@ -56,6 +56,7 @@ dependencies { compileOnly 'org.pf4j:pf4j:3.4.1' implementation 'org.json:json:20240303' implementation 'dev.harrel:json-schema:1.5.0' + implementation 'com.sanctionco.jmail:jmail:1.6.3' // Needed for e-mail format validation // test configuration testImplementation "io.nextflow:nextflow:$nextflowVersion" diff --git a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy index 8636ac0..55448e6 100644 --- a/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy +++ b/plugins/nf-schema/src/test/nextflow/validation/ValidateParametersTest.groovy @@ -1095,4 +1095,56 @@ class ValidateParametersTest extends Dsl2Spec{ !stdout } + def 'should validate an email' () { + given: + def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString() + def SCRIPT = """ + params.input = 'src/testResource/samplesheet.csv' + params.outdir = 'src/testResources/testDir' + params.email = "test@domain.com" + include { validateParameters } from 'plugin/nf-schema' + + validateParameters(parameters_schema: '$schema') + """ + + when: + def config = [:] + def result = new MockScriptRunner(config).setScript(SCRIPT).execute() + def stdout = capture + .toString() + .readLines() + .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } + + then: + noExceptionThrown() + !stdout + } + + def 'should validate an email - failure' () { + given: + def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString() + def SCRIPT = """ + params.input = 'src/testResource/samplesheet.csv' + params.outdir = 'src/testResources/testDir' + params.email = "thisisnotanemail" + include { validateParameters } from 'plugin/nf-schema' + + validateParameters(parameters_schema: '$schema') + """ + + when: + def config = [:] + def result = new MockScriptRunner(config).setScript(SCRIPT).execute() + def stdout = capture + .toString() + .readLines() + .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } + + + then: + def error = thrown(SchemaValidationException) + error.message.contains("* --email (thisisnotanemail): \"thisisnotanemail\" is not a valid email address") + !stdout + } + } \ No newline at end of file diff --git a/plugins/nf-schema/src/testResources/nextflow_schema.json b/plugins/nf-schema/src/testResources/nextflow_schema.json index 7dcf103..1fb1565 100644 --- a/plugins/nf-schema/src/testResources/nextflow_schema.json +++ b/plugins/nf-schema/src/testResources/nextflow_schema.json @@ -30,9 +30,9 @@ "email": { "type": "string", "description": "Email address for completion summary.", + "format": "email", "fa_icon": "fas fa-envelope", - "help_text": "Set this parameter to your e-mail address to get a summary e-mail with details of the run sent to you when the workflow exits. If set in your user config file (`~/.nextflow/config`) then you don't need to specify this on the command line for every run.", - "pattern": "^([a-zA-Z0-9_\\-\\.]+)@([a-zA-Z0-9_\\-\\.]+)\\.([a-zA-Z]{2,5})$" + "help_text": "Set this parameter to your e-mail address to get a summary e-mail with details of the run sent to you when the workflow exits. If set in your user config file (`~/.nextflow/config`) then you don't need to specify this on the command line for every run." }, "multiqc_title": { "type": "string",