Skip to content

Commit

Permalink
Merge branch 'dev' into subworkflowsupdate
Browse files Browse the repository at this point in the history
  • Loading branch information
mirpedrol authored Nov 16, 2022
2 parents e489008 + 955e763 commit e1e0fdc
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 7 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
email_template.html
adaptivecard.json
slackreport.json
docs/api/_build
testing

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- Track from where modules and subworkflows are installed ([#1999](https://github.com/nf-core/tools/pull/1999))
- Substitute ModulesCommand and SubworkflowsCommand by ComponentsCommand ([#2000](https://github.com/nf-core/tools/pull/2000))
- Don't print source file + line number on logging messages (except when verbose) ([#2015](https://github.com/nf-core/tools/pull/2015))
- Extended the chat notifications to Slack ([#1829](https://github.com/nf-core/tools/pull/1829))

### Modules

Expand Down
1 change: 1 addition & 0 deletions nf_core/pipeline-template/.prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
email_template.html
adaptivecard.json
slackreport.json
.nextflow*
work/
data/
Expand Down
34 changes: 34 additions & 0 deletions nf_core/pipeline-template/assets/slackreport.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"attachments": [
{
"fallback": "Plain-text summary of the attachment.",
"color": "<% if (success) { %>good<% } else { %>danger<%} %>",
"author_name": "sanger-tol/readmapping v${version} - ${runName}",
"author_icon": "https://www.nextflow.io/docs/latest/_static/favicon.ico",
"text": "<% if (success) { %>Pipeline completed successfully!<% } else { %>Pipeline completed with errors<% } %>",
"fields": [
{
"title": "Command used to launch the workflow",
"value": "```${commandLine}```",
"short": false
}
<%
if (!success) { %>
,
{
"title": "Full error message",
"value": "```${errorReport}```",
"short": false
},
{
"title": "Pipeline configuration",
"value": "<% out << summary.collect{ k,v -> k == "hook_url" ? "_${k}_: (_hidden_)" : ( ( v.class.toString().contains('Path') || ( v.class.toString().contains('String') && v.contains('/') ) ) ? "_${k}_: `${v}`" : (v.class.toString().contains('DateTime') ? ("_${k}_: " + v.format(java.time.format.DateTimeFormatter.ofLocalizedDateTime(java.time.format.FormatStyle.MEDIUM))) : "_${k}_: ${v}") ) }.join(",\n") %>",
"short": false
}
<% }
%>
],
"footer": "Completed at <% out << dateComplete.format(java.time.format.DateTimeFormatter.ofLocalizedDateTime(java.time.format.FormatStyle.MEDIUM)) %> (duration: ${duration})"
}
]
}
13 changes: 8 additions & 5 deletions nf_core/pipeline-template/lib/NfcoreTemplate.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ class NfcoreTemplate {
}

//
// Construct and send adaptive card
// https://adaptivecards.io
// Construct and send a notification to a web server as JSON
// e.g. Microsoft Teams and Slack
//
public static void adaptivecard(workflow, params, summary_params, projectDir, log) {
public static void IM_notification(workflow, params, summary_params, projectDir, log) {
def hook_url = params.hook_url

def summary = [:]
Expand Down Expand Up @@ -178,13 +178,16 @@ class NfcoreTemplate {
msg_fields['exitStatus'] = workflow.exitStatus
msg_fields['errorMessage'] = (workflow.errorMessage ?: 'None')
msg_fields['errorReport'] = (workflow.errorReport ?: 'None')
msg_fields['commandLine'] = workflow.commandLine
msg_fields['commandLine'] = workflow.commandLine.replaceFirst(/ +--hook_url +[^ ]+/, "")
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")
// Different JSON depending on the service provider
// Defaults to "Adaptive Cards" (https://adaptivecards.io), except Slack which has its own format
def json_path = hook_url.contains("hooks.slack.com") ? "slackreport.json" : "adaptivecard.json"
def hf = new File("$projectDir/assets/${json_path}")
def json_template = engine.createTemplate(hf).make(msg_fields)
def json_message = json_template.toString()

Expand Down
2 changes: 1 addition & 1 deletion nf_core/pipeline-template/nextflow_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@
"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.",
"help_text": "Incoming hook URL for messaging service. Currently, MS Teams and Slack are supported.",
"hidden": true
},
"multiqc_config": {
Expand Down
2 changes: 1 addition & 1 deletion nf_core/pipeline-template/workflows/pipeline.nf
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ workflow.onComplete {
}
NfcoreTemplate.summary(workflow, params, log)
if (params.hook_url) {
NfcoreTemplate.adaptivecard(workflow, params, summary_params, projectDir, log)
NfcoreTemplate.IM_notification(workflow, params, summary_params, projectDir, log)
}
}

Expand Down

0 comments on commit e1e0fdc

Please sign in to comment.