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

Feature/teams hook #1798

Merged
merged 11 commits into from
Sep 6, 2022
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
email_template.html
adaptivecard.json
docs/api/_build
testing

1 change: 1 addition & 0 deletions nf_core/pipeline-template/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
email_template.html
adaptivecard.json
.nextflow*
work/
data/
Expand Down
67 changes: 67 additions & 0 deletions nf_core/pipeline-template/assets/adaptivecard.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"type": "message",
"attachments": [
{
"contentType": "application/vnd.microsoft.card.adaptive",
"contentUrl": null,
"content": {
"\$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"msteams": {
"width": "Full"
},
"type": "AdaptiveCard",
"version": "1.2",
"body": [
{
"type": "TextBlock",
"size": "Large",
"weight": "Bolder",
"color": "<% if (success) { %>Good<% } else { %>Attention<%} %>",
"text": "{{ name }} v${version} - ${runName}",
"wrap": true
},
{
"type": "TextBlock",
"spacing": "None",
"text": "Completed at ${dateComplete} (duration: ${duration})",
"isSubtle": true,
"wrap": true
},
{
"type": "TextBlock",
"text": "<% if (success) { %>Pipeline completed successfully!<% } else { %>Pipeline completed with errors. The full error message was: ${errorReport}.<% } %>",
"wrap": true
},
{
"type": "TextBlock",
"text": "The command used to launch the workflow was as follows:",
"wrap": true
},
{
"type": "TextBlock",
"text": "${commandLine}",
"isSubtle": true,
"wrap": true
}
],
"actions": [
{
"type": "Action.ShowCard",
"title": "Pipeline Configuration",
"card": {
"type": "AdaptiveCard",
"\$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
"body": [
{
"type": "FactSet",
"facts": [<% out << summary.collect{ k,v -> "{\"title\": \"$k\", \"value\" : \"$v\"}"}.join(",\n") %>
]
}
]
}
}
]
}
}
]
}
55 changes: 55 additions & 0 deletions nf_core/pipeline-template/lib/NfcoreTemplate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,61 @@ class NfcoreTemplate {
output_tf.withWriter { w -> w << email_txt }
}

//
// Construct and send adaptive card
// https://adaptivecards.io
//
public static void adaptivecard(workflow, params, summary_params, projectDir, log, multiqc_report=[]) {
matthdsm marked this conversation as resolved.
Show resolved Hide resolved
def hook_url = params.hook_url

def summary = [:]
for (group in summary_params.keySet()) {
summary << summary_params[group]
}

def misc_fields = [:]
misc_fields['start'] = workflow.start
misc_fields['complete'] = workflow.complete
misc_fields['scriptfile'] = workflow.scriptFile
misc_fields['scriptid'] = workflow.scriptId
if (workflow.repository) misc_fields['repository'] = workflow.repository
if (workflow.commitId) misc_fields['commitid'] = workflow.commitId
if (workflow.revision) misc_fields['revision'] = workflow.revision
misc_fields['nxf_version'] = workflow.nextflow.version
misc_fields['nxf_build'] = workflow.nextflow.build
misc_fields['nxf_timestamp'] = workflow.nextflow.timestamp

def msg_fields = [:]
msg_fields['version'] = workflow.manifest.version
msg_fields['runName'] = workflow.runName
msg_fields['success'] = workflow.success
msg_fields['dateComplete'] = workflow.complete
msg_fields['duration'] = workflow.duration
msg_fields['exitStatus'] = workflow.exitStatus
msg_fields['errorMessage'] = (workflow.errorMessage ?: 'None')
msg_fields['errorReport'] = (workflow.errorReport ?: 'None')
msg_fields['commandLine'] = workflow.commandLine
msg_fields['projectDir'] = workflow.projectDir
msg_fields['summary'] = summary << misc_fields

// Render the JSON template
def engine = new groovy.text.GStringTemplateEngine()
def hf = new File("$projectDir/assets/adaptivecard.json")
def json_template = engine.createTemplate(hf).make(msg_fields)
def json_message = json_template.toString()

// POST
def post = new URL(hook_url).openConnection();
post.setRequestMethod("POST")
post.setDoOutput(true)
post.setRequestProperty("Content-Type", "application/json")
post.getOutputStream().write(json_message.getBytes("UTF-8"));
def postRC = post.getResponseCode();
if (! postRC.equals(200)) {
println(post.getErrorStream().getText());
matthdsm marked this conversation as resolved.
Show resolved Hide resolved
matthdsm marked this conversation as resolved.
Show resolved Hide resolved
}
}

//
// Print pipeline summary on completion
//
Expand Down
1 change: 1 addition & 0 deletions nf_core/pipeline-template/nextflow.config
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ params {
email_on_fail = null
plaintext_email = false
monochrome_logs = false
hook_url = null
help = false
validate_params = true
show_hidden_params = false
Expand Down
7 changes: 7 additions & 0 deletions nf_core/pipeline-template/nextflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@
"fa_icon": "fas fa-palette",
"hidden": true
},
"hook_url": {
"type": "string",
"description": "Incoming hook URL for messaging service",
"fa_icon": "fas fa-people-group",
"help_text": "Incoming hook URL for messaging service. Currently, only MS Teams is supported.",
"hidden": true
},
"multiqc_config": {
"type": "string",
"description": "Custom config file to supply to MultiQC.",
Expand Down
3 changes: 3 additions & 0 deletions nf_core/pipeline-template/workflows/pipeline.nf
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ workflow.onComplete {
NfcoreTemplate.email(workflow, params, summary_params, projectDir, log, multiqc_report)
}
NfcoreTemplate.summary(workflow, params, log)
if (params.hook_url) {
NfcoreTemplate.adaptivecard(workflow, params, summary_params, projectDir, log, multiqc_report)
matthdsm marked this conversation as resolved.
Show resolved Hide resolved
}
}

/*
Expand Down