-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to send message via webhooks (#50)
* fix line endings * WIP: send via slack webhook * send via webhooks - unit test * update doco * fix lint * fix doco * version bump * add '
- Loading branch information
1 parent
841e88f
commit a6fe210
Showing
9 changed files
with
435 additions
and
41 deletions.
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
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 |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"dependencies": { | ||
"@slack/web-api": "^6.8.1", | ||
"@slack/webhook": "^6.1.0", | ||
"https-proxy-agent": "^7.0.1" | ||
}, | ||
"devDependencies": { | ||
|
@@ -18,7 +19,7 @@ | |
"eslint-plugin-prettier": "^4.2.1", | ||
"nyc": "^15.1.0", | ||
"prettier": "^2.7.1", | ||
"ts-mockito": "^2.6.1", | ||
"ts-sinon": "^2.0.2", | ||
"typescript": "^4.7.4" | ||
}, | ||
"scripts": { | ||
|
@@ -28,7 +29,7 @@ | |
"lint": "npx eslint . --ext .ts" | ||
}, | ||
"name": "playwright-slack-report", | ||
"version": "1.1.21", | ||
"version": "1.1.22", | ||
"main": "index.js", | ||
"types": "dist/index.d.ts", | ||
"repository": "[email protected]:ryanrosello-og/playwright-slack-report.git", | ||
|
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
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,54 @@ | ||
import { Block, KnownBlock } from '@slack/types'; | ||
import { IncomingWebhook, IncomingWebhookResult } from '@slack/webhook'; | ||
import { SummaryResults } from '.'; | ||
import { generateBlocks } from './LayoutGenerator'; | ||
|
||
export default class SlackWebhookClient { | ||
private webhook: IncomingWebhook; | ||
|
||
constructor(webhook: IncomingWebhook) { | ||
this.webhook = webhook; | ||
} | ||
|
||
async sendMessage({ | ||
customLayout, | ||
customLayoutAsync, | ||
maxNumberOfFailures, | ||
summaryResults, | ||
disableUnfurl, | ||
}: { | ||
customLayout: Function | undefined; | ||
customLayoutAsync: Function | undefined; | ||
maxNumberOfFailures: number; | ||
summaryResults: SummaryResults; | ||
disableUnfurl: boolean; | ||
}): Promise<{ outcome: string }> { | ||
let blocks: (Block | KnownBlock)[]; | ||
if (customLayout) { | ||
blocks = customLayout(summaryResults); | ||
} else if (customLayoutAsync) { | ||
blocks = await customLayoutAsync(summaryResults); | ||
} else { | ||
blocks = await generateBlocks(summaryResults, maxNumberOfFailures); | ||
} | ||
let result: IncomingWebhookResult; | ||
try { | ||
result = await this.webhook.send({ | ||
blocks, | ||
unfurl_links: !disableUnfurl, | ||
}); | ||
} catch (error) { | ||
return { | ||
outcome: `error: ${JSON.stringify(error, null, 2)}`, | ||
}; | ||
} | ||
if (result && result.text === 'ok') { | ||
return { | ||
outcome: result.text, | ||
}; | ||
} | ||
return { | ||
outcome: '😵 Failed to send webhook message, ensure your webhook url is valid', | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.