@atomist/slack-messages
Advanced tools
Comparing version 0.4.0 to 0.5.0
@@ -10,4 +10,19 @@ # Change Log | ||
[Unreleased]: https://github.com/atomist/slack-messages/compare/0.4.0...HEAD | ||
[Unreleased]: https://github.com/atomist/slack-messages/compare/0.5.0...HEAD | ||
## [0.5.0] | ||
[0.5.0]: https://github.com/atomist/slack-messages/compare/0.4.0...0.5.0 | ||
### Added | ||
- Added explicit `atChannel` that renders as `@channel` in Slack | ||
### Fixed | ||
- Fixes #8 (TypeError: key.charAt is not a function) | ||
- Slack helper function will render empty string when given undefined values | ||
### Changed | ||
- **BREAKING** Renamed `atUser` to `user` | ||
- **BREAKING** Renamed `atChannel` with channel id, channel name to `channel` | ||
## [0.4.0] - 2017-05-10 | ||
@@ -14,0 +29,0 @@ |
{ | ||
"name": "@atomist/slack-messages", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"author": "Atomist, Inc", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -106,7 +106,7 @@ # @atomist/slack-messages | ||
// @some-user (Slack will display user name for provided user ID) | ||
atUser("U123"); | ||
user("U123"); | ||
=> "<@U123>" | ||
// #some-channel (Slack will display channel name for provided channel ID) | ||
atChannel("C123"); | ||
channel("C123"); | ||
=> "<#C123>" | ||
@@ -225,2 +225,2 @@ ``` | ||
[atomist]: https://www.atomist.com/ | ||
[slack]: https://join.atomist.com | ||
[slack]: https://join.atomist.com |
import { ResponseMessage } from "@atomist/rug/operations/Handlers"; | ||
/** | ||
* | ||
*/ | ||
export declare function renderError(msg: string, correlationId?: string): ResponseMessage; | ||
export declare function renderSuccess(msg: string): ResponseMessage; |
@@ -5,2 +5,5 @@ "use strict"; | ||
var Handlers_1 = require("@atomist/rug/operations/Handlers"); | ||
/** | ||
* | ||
*/ | ||
function renderError(msg, correlationId) { | ||
@@ -35,3 +38,3 @@ try { | ||
catch (ex) { | ||
return new Handlers_1.ResponseMessage("Error rendering success message " + ex); | ||
return renderError("Error rendering success message " + ex); | ||
} | ||
@@ -38,0 +41,0 @@ } |
@@ -7,2 +7,3 @@ import { Presentable } from "@atomist/rug/operations/Handlers"; | ||
*/ | ||
export declare function emptyString(str: string): boolean; | ||
/** | ||
@@ -17,3 +18,2 @@ * Escapes special Slack characters. | ||
export declare function url(fullUrl: string, label?: string): string; | ||
export declare function emptyString(str: string): boolean; | ||
/** | ||
@@ -23,10 +23,11 @@ * Mentions user (e.g. @anna). | ||
*/ | ||
export declare function atUser(userId: string, userName?: string): string; | ||
export declare function user(userId: string, userName?: string): string; | ||
/** | ||
* Mentions channel (e.g. #general). | ||
* When both userId and channelName are omitted will render @channel. | ||
* Otherwise will mention specific channel by channelId. | ||
* Will mention specific channel by channelId. | ||
* When channelName is provided will add readable channel name. | ||
*/ | ||
export declare function atChannel(channelId?: string, channelName?: string): string; | ||
export declare function channel(channelId: string, channelName?: string): string; | ||
/** Mentions @channel */ | ||
export declare function atChannel(): string; | ||
/** Mentions here (@here) */ | ||
@@ -33,0 +34,0 @@ export declare function atHere(): string; |
@@ -8,2 +8,6 @@ "use strict"; | ||
*/ | ||
function emptyString(str) { | ||
return !str || str === "" || str === undefined; | ||
} | ||
exports.emptyString = emptyString; | ||
/** | ||
@@ -13,3 +17,3 @@ * Escapes special Slack characters. | ||
function escape(text) { | ||
if (text && text !== "") { | ||
if (!emptyString(text)) { | ||
return text | ||
@@ -21,3 +25,3 @@ .replace(/&/, "&") | ||
else { | ||
return text; | ||
return ""; | ||
} | ||
@@ -31,14 +35,13 @@ } | ||
function url(fullUrl, label) { | ||
if (label && label !== "") { | ||
if (!emptyString(fullUrl) && !emptyString(label)) { | ||
return "<" + fullUrl + "|" + escape(label) + ">"; | ||
} | ||
else { | ||
else if (!emptyString(fullUrl)) { | ||
return "<" + fullUrl + ">"; | ||
} | ||
else { | ||
return ""; | ||
} | ||
} | ||
exports.url = url; | ||
function emptyString(str) { | ||
return !str || str === ""; | ||
} | ||
exports.emptyString = emptyString; | ||
/** | ||
@@ -48,28 +51,35 @@ * Mentions user (e.g. @anna). | ||
*/ | ||
function atUser(userId, userName) { | ||
if (!emptyString(userName)) { | ||
function user(userId, userName) { | ||
if (!emptyString(userId) && !emptyString(userName)) { | ||
return "<@" + userId + "|" + userName + ">"; | ||
} | ||
else { | ||
else if (!emptyString(userId)) { | ||
return "<@" + userId + ">"; | ||
} | ||
else { | ||
return ""; | ||
} | ||
} | ||
exports.atUser = atUser; | ||
exports.user = user; | ||
/** | ||
* Mentions channel (e.g. #general). | ||
* When both userId and channelName are omitted will render @channel. | ||
* Otherwise will mention specific channel by channelId. | ||
* Will mention specific channel by channelId. | ||
* When channelName is provided will add readable channel name. | ||
*/ | ||
function atChannel(channelId, channelName) { | ||
if (emptyString(channelId) && emptyString(channelName)) { | ||
return "<!channel>"; | ||
function channel(channelId, channelName) { | ||
if (!emptyString(channelId) && !emptyString(channelName)) { | ||
return "<#" + channelId + "|" + channelName + ">"; | ||
} | ||
else if (emptyString(channelName)) { | ||
else if (!emptyString(channelId)) { | ||
return "<#" + channelId + ">"; | ||
} | ||
else { | ||
return "<#" + channelId + "|" + channelName + ">"; | ||
return ""; | ||
} | ||
} | ||
exports.channel = channel; | ||
/** Mentions @channel */ | ||
function atChannel() { | ||
return "<!channel>"; | ||
} | ||
exports.atChannel = atChannel; | ||
@@ -89,10 +99,3 @@ /** Mentions here (@here) */ | ||
if (pretty === void 0) { pretty = false; } | ||
return JSON.stringify(message, function (key, val) { | ||
if (key.charAt(0) !== "_") { | ||
return val; | ||
} | ||
else { | ||
return undefined; | ||
} | ||
}, pretty ? 4 : 0); | ||
return JSON.stringify(message, null, pretty ? 4 : 0); | ||
} | ||
@@ -107,3 +110,8 @@ exports.render = render; | ||
function bold(text) { | ||
return "*" + text + "*"; | ||
if (!emptyString(text)) { | ||
return "*" + text + "*"; | ||
} | ||
else { | ||
return ""; | ||
} | ||
} | ||
@@ -113,3 +121,8 @@ exports.bold = bold; | ||
function italic(text) { | ||
return "_" + text + "_"; | ||
if (!emptyString(text)) { | ||
return "_" + text + "_"; | ||
} | ||
else { | ||
return ""; | ||
} | ||
} | ||
@@ -119,3 +132,8 @@ exports.italic = italic; | ||
function strikethrough(text) { | ||
return "~" + text + "~"; | ||
if (!emptyString(text)) { | ||
return "~" + text + "~"; | ||
} | ||
else { | ||
return ""; | ||
} | ||
} | ||
@@ -125,3 +143,8 @@ exports.strikethrough = strikethrough; | ||
function codeLine(text) { | ||
return "`" + text + "`"; | ||
if (!emptyString(text)) { | ||
return "`" + text + "`"; | ||
} | ||
else { | ||
return ""; | ||
} | ||
} | ||
@@ -131,3 +154,8 @@ exports.codeLine = codeLine; | ||
function codeBlock(text) { | ||
return "```" + text + "```"; | ||
if (!emptyString(text)) { | ||
return "```" + text + "```"; | ||
} | ||
else { | ||
return ""; | ||
} | ||
} | ||
@@ -137,3 +165,8 @@ exports.codeBlock = codeBlock; | ||
function listItem(item) { | ||
return "\u2022 " + item; | ||
if (!emptyString(item)) { | ||
return "\u2022 " + item; | ||
} | ||
else { | ||
return "•"; | ||
} | ||
} | ||
@@ -140,0 +173,0 @@ exports.listItem = listItem; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
42736
335
225
0