-
Notifications
You must be signed in to change notification settings - Fork 38
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
feat: Add possibility to provide onSuccess function #53
Conversation
@BeyondEvil makes sense to me 👍 |
I like this concept! Could you add the example (or a similar one) to the docs? |
@@ -0,0 +1,37 @@ | |||
const chunkifyArray = (messageLines, maxLength, delimiter) => { |
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.
What does this do? Is this used somewhere or is it meant to be imported by our users?
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.
It's called here.
I figured the logic deserved it's own function. For readability, extendability, and usability. :)
lib/chunkifier.js
Outdated
let chunk = line + delimiter | ||
if ((message + chunk).length > maxLength) { | ||
resultLines.push(message.trimEnd()) | ||
message = chunk |
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.
what does this line do?
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.
I should probably explain the algorithm "inline". I'll add that when I add docs and tests.
But basically we have messageLines
which is an array of all the text split newline (\n
) and we have the maxLength
which is the size of each message chunk
So for each item in messageLines
we test if adding a new chunk
will put us over the limit (maxLength
). If it does we "reset" message
with this new chunk (line 10).
If it doesn't put us over, we keep concatenating the chunks to message
.
Hope that makes sense! 😂 @juliuscc
I take that as I should add docs and tests and turn this into a proper PR. 😊 |
c5123b6
to
f40134a
Compare
Some tests added. Will add more tests and docs tomorrow. |
Haha yes! I later saw that there wasn't any doc-updates 😁 I think the concept is great! 👍 |
That's it for tests. I'll try and add docs tomorrow. I named the test-files according to convention. Will rename the other test-files in a separate PR. |
6388a77
to
4529cb3
Compare
4529cb3
to
fbd419c
Compare
I'd say this is ready for review now @juliuscc @hannesrabo @AndrewLeedham 😊 |
|
||
If a function is provided with either the `onSuccessFunction` or `onFailFunction` options, it will be used for the respective slack message. The function should return an object that follows the [Slack API message structure](https://api.slack.com/docs/message-formatting). The function is passed two objects, `pluginConfig` and `context`, the same objects that are passed to [plugins](https://github.com/semantic-release/semantic-release/blob/master/docs/developer-guide/plugin.md#plugin-developer-guide). | ||
|
||
**Note**: This only works with a [configuration file](https://semantic-release.gitbook.io/semantic-release/usage/configuration#configuration-file) that exports an object (see below for an example). |
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.
Not sure if this is actually true? 🤔
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.
Hmm, I can not think of a way to make it work otherwise. Let's keep it like that unless someone corrects us 😁
@@ -21,7 +21,7 @@ Add the plugin to your npm-project: | |||
$ npm install semantic-release-slack-bot -D | |||
``` | |||
|
|||
The corresponding slack app has be installed in you slack workspace as well. Follow the instructions under [configuration](#configuration) for more information. | |||
The corresponding slack app has to be installed in your slack workspace as well. Follow the instructions under [configuration](#configuration) for more information. |
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.
Great that you have cleaned up in the Readme! I didn't know that there were that many spelling mistakes 😅
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.
This all looks great to me! 👍
Thanks for the hard work! @BeyondEvil 🥇 |
🎉 This PR is included in version 1.7.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## 1.0.0 (2025-01-10) ### ⚠ BREAKING CHANGES * **core:** We only support v18+ of Node and v20+ of semantic-release now. semantic-release library introduced a new version v20 which introduces several breaking changes, including but not limited Node v18 as requirement. More information can be found [here](https://github.com/semantic-release/semantic-release/releases/tag/v20.0.0). * Drops support for Node 10. semantic-release-slack-bot supports Node 14+ from this version. * Drops support for Node 8. semantic-release-slack-bot supports Node 10+ from this version. ### Features * add maxLength option ([juliuscc#27](https://github.com/pinginc/semantic-release-slack-bot/issues/27)) e4000b2, closes juliuscc#26 * add onFail and onSuccess template options c075e91 * add option to specify slack app name ([juliuscc#83](https://github.com/pinginc/semantic-release-slack-bot/issues/83)) 89ee876 * add option to specify slack icon ([juliuscc#80](https://github.com/pinginc/semantic-release-slack-bot/issues/80)) 47952b0 * Add packageName as a config option ([juliuscc#34](https://github.com/pinginc/semantic-release-slack-bot/issues/34)) bf323ca * Add possibility to provide onSuccess function ([juliuscc#53](https://github.com/pinginc/semantic-release-slack-bot/issues/53)) 1cb7fab * add slackWebhook as configuration option ([juliuscc#17](https://github.com/pinginc/semantic-release-slack-bot/issues/17)) d3df2b4, closes juliuscc#16 * add support for token/channel option ([juliuscc#79](https://github.com/pinginc/semantic-release-slack-bot/issues/79)) aa1eef6, closes juliuscc#73 * Added a new message form that is published upon a build failure. 6f4afc6 * Added a nicer looking web page. 96b73ad * Added integration with slack d541e59 * Added option to disable notifications 1117583 * allow to have a custom configuration per branches ([juliuscc#63](https://github.com/pinginc/semantic-release-slack-bot/issues/63)) cab5394 * allow to override slack channel when using webhook ([juliuscc#81](https://github.com/pinginc/semantic-release-slack-bot/issues/81)) 83b4699 * allows a custom environment variable name for Slack webhook ([juliuscc#36](https://github.com/pinginc/semantic-release-slack-bot/issues/36)) a8bec27 * **core:** upgrade semantic-release to version v20 ([juliuscc#104](https://github.com/pinginc/semantic-release-slack-bot/issues/104)) 54ee3bd, closes juliuscc#103 * Empty commit to trigger major release 526e3ef * **Error message:** Improve error message with a good description a5f7a7b * Finalized notification messages b8ade21 * implement automatic conversion of Release Notes from Markdown to Slack Markdown f7b1955 * Include package name in notification 20e7a62 * **Logger:** Added logger c22afba * Made button icon better aligned 3b1e420 * Made index page nice f424e7f * Nicer error message 2e4a1c2 * Nicer slack message 8ef7a68 * **Notifications:** Added text for notification 1084b5e * OWL-2911: fork project ([#3](#3)) faee31d * **templating:** Merged changes with new templating system and updated some details 90d01b6, closes #2 * update semantic release version ([juliuscc#85](https://github.com/pinginc/semantic-release-slack-bot/issues/85)) 4a31a5f ### Bug Fixes * add keyword (but actually force ci to publish) 07b918d * add protocol to url starting with git@ ([juliuscc#31](https://github.com/pinginc/semantic-release-slack-bot/issues/31)) 8baf727 * Added a favicon 8c806ea * Added immediate logging of api exceptions 5679b4e, closes juliuscc#19 * Added verifyCondition hook to check for the correct environment variable aa82207, closes #1 * adjust ci f12f7e9 * Avoid truncating in the middle of markdown ([juliuscc#20](https://github.com/pinginc/semantic-release-slack-bot/issues/20)) bc373f9 * bump peer dependency ([juliuscc#38](https://github.com/pinginc/semantic-release-slack-bot/issues/38)) 6103a60 * bumps semantic-release requirement to <19 ([juliuscc#77](https://github.com/pinginc/semantic-release-slack-bot/issues/77)) 8d844ec * **ci:** Added checkout to deploy 8b7ffd6 * **ci:** Restored cached filed before deploying e106418 * **ci:** test2 f9df42f * **ci:** Tried fixing a ci config bug 5c1aea9 * **dependencies:** Added missing dependency 93b12f4 * Fix dependencies 7956978 * Fixed how messages are truncated acec2b5, closes juliuscc#19 * Fixed spelling of JSON fb558a1 * **getrepoinfo:** fix for other TLD checking in repo url ([juliuscc#33](https://github.com/pinginc/semantic-release-slack-bot/issues/33)) 22d83db * make ci work 818fe92 * minor refactor d3e66f2 * npm audit fix 3f1956e * **package.json:** Made project public 4430fae * remove hashtag from version number ([juliuscc#94](https://github.com/pinginc/semantic-release-slack-bot/issues/94)) 7795cda, closes juliuscc#93 * rename wrongly named file 7383085 * repo_url typo e30d3a1 * simplify code and add tests ([juliuscc#22](https://github.com/pinginc/semantic-release-slack-bot/issues/22)) cff4304 * slack token missing bearer prefix ([juliuscc#84](https://github.com/pinginc/semantic-release-slack-bot/issues/84)) 1d410f7 * slackToken based message returns a JSON object ([juliuscc#89](https://github.com/pinginc/semantic-release-slack-bot/issues/89)) e85e59c * **success:** Fixed linting error in success 4e7c7ed * support more vendors ([juliuscc#25](https://github.com/pinginc/semantic-release-slack-bot/issues/25)) c0c378a * **template:** fix replacement of a multiple occurence of the same variable ([juliuscc#46](https://github.com/pinginc/semantic-release-slack-bot/issues/46)) 73c2238 * **test:** test1 02af17f * Truncate release notes on "onSuccessTemplate" ([juliuscc#23](https://github.com/pinginc/semantic-release-slack-bot/issues/23)) ad3b0af, closes juliuscc#21 * truncated release notes > 3000 chars b5a861c * Update creation of tag link in default success template ([juliuscc#90](https://github.com/pinginc/semantic-release-slack-bot/issues/90)) 9f4c735, closes juliuscc#82 * update peer dependency to allow future semantic release versions ([juliuscc#108](https://github.com/pinginc/semantic-release-slack-bot/issues/108)) 4a89801 * updated green color 7b63086 * upgrade micromatch ([juliuscc#123](https://github.com/pinginc/semantic-release-slack-bot/issues/123)) 34e721a * use package_name on fail message ([juliuscc#109](https://github.com/pinginc/semantic-release-slack-bot/issues/109)) 214aef0 * Used the linter c4c0f3d * **verify-conditions:** Added check for non existant package name dc5f1c1, closes #4 ### Other * Add possibility to turn off truncation ([juliuscc#52](https://github.com/pinginc/semantic-release-slack-bot/issues/52)) 32cf994 * Add screenshot e785e3a * add semantic release 8c20cb5 * Add slack badge 4726b05 * Added a lint stage to the ci 57bf855 * Added colaborator to license 30f6fd5 * Added lambda and redirect page d1089d2 * Added printers with all valid properties b925a19 * Added security related instructions 297f9ca * Added stuff a7eea92 * Added two better screenshots 9e6208c * append Template to options 899ba64 * Bump dependencies ([juliuscc#55](https://github.com/pinginc/semantic-release-slack-bot/issues/55)) 3c499f3 * bump slackify-markdown ([juliuscc#69](https://github.com/pinginc/semantic-release-slack-bot/issues/69)) c8cb52b * Create PRIVACY.md d47e989 * feat(ci): aa6a5f5 * Finalized truncation of too long messages 53b563f * fix circleci badge link d32447b * fixed old title dc897d9 * Fixes nicer indentation in code snippets 1b0af6a * github_path > repo_path + added repo_url 907d2d8 * Initial commit 390f1bb * Makes code in Readme.md nicer 8e55982 * Merge branch 'AndrewLeedham-master' 329c85a * Merge branch 'master' of github.com:juliuscc/semantic-release-slack-bot ce4c896 * Merge pull request [juliuscc#11](https://github.com/pinginc/semantic-release-slack-bot/issues/11) from juliuscc/dependabot/npm_and_yarn/lodash.template-4.5.0 83cb943 * Merge pull request [#5](#5) from thopaw/fix-message-length 3c5a70d * Merge remote-tracking branch 'origin/master' 9f415b3 * **naming:** Rename test files ([juliuscc#54](https://github.com/pinginc/semantic-release-slack-bot/issues/54)) be18847 * npm init 2b6c206 * **prettier:** changes tab indentation to 2 space indentation ([juliuscc#32](https://github.com/pinginc/semantic-release-slack-bot/issues/32)) f1aa538 * **Readme.md:** First draft of readme 49ec79d * **readme:** add templating options 7efa3e2 * **Readme:** Added build status shield 8f3ba60 * **Readme:** Minor update on readme to make more idiomatic 5d330dc * **Reamde:** Made docs look nicer cb4e01f * refactored lambda script 9947f86 * Removed comments 2612c08 * Removed comments 9c98379 * Removed trash 4ed30aa * Removed unnecessary log line. 37e0df5, closes juliuscc#43 * Rename wiki/index.html to docs/index.html 14db594 * **slackChannel:** missing # in slackChannel ([juliuscc#100](https://github.com/pinginc/semantic-release-slack-bot/issues/100)) e7d1c4d * test a6d9916 * Update README.md 41a32e1 * Update README.md 63582af * Upload screenshot 6946c87 * Uppdated deployment URL 3ffea71
This adds two new options:
onSuccessFunction
onFailFunction
Both functions takes
pluginConfig
andcontext
as arguments so that the user has access to all the Semantic Release configuration. They also take precedence over the respective template option (we can change this of course, I don't have a strong opinion either way).Before I add documentation and tests, I just want to make sure we're fine with this type of addition. @juliuscc @hannesrabo cc: @AndrewLeedham (it was your idea after all)
See also #39 and #26
Example config (tested, but with irrelevant parts removed)