-
Notifications
You must be signed in to change notification settings - Fork 4
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
Added Slack/Teams notifications #43
Open
wfondrie
wants to merge
1
commit into
main
Choose a base branch
from
features/slack
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "TalusBio/nf-encyclopedia - ${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})" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,4 +41,53 @@ class TalusTemplate { | |
def email_html = html_template.toString() | ||
return [subject, email_html] | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: This looks very clean |
||
// | ||
// Construct and send a notification to a web server as JSON | ||
// e.g. Microsoft Teams and Slack | ||
// | ||
public static void IM_notification(workflow, params, projectDir) { | ||
def hook_url = params.hook_url | ||
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 summary = [:] | ||
def msg_fields = [:] | ||
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.replaceFirst(/ +--hook_url +[^ ]+/, "") | ||
msg_fields['projectDir'] = workflow.projectDir | ||
msg_fields['summary'] = summary << misc_fields | ||
|
||
// Render the JSON template | ||
def engine = new groovy.text.GStringTemplateEngine() | ||
// 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() | ||
|
||
// 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ params { | |
report_dir = 'reports' /** \type{str} Where reports will be saved. */ | ||
mzml_dir = 'mzml' /** \type{str} Where mzML files will be saved. */ | ||
email = null /** \type{str} An email to alert on completion. */ | ||
hook_url = null /** \type{str} A URL for Slack notifications */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you link the slack docs to know how to get one? :D please... |
||
|
||
/** \group{Grouping Parameters} */ | ||
/** \type{boolean} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could you rename this as
.j2.json
, just to know that it is a template while browsing the file tree? (not critical, feel free to disregard)