Skip to content

Commit

Permalink
feat: Added event to notify discord in fails functions (wppconnect-te…
Browse files Browse the repository at this point in the history
  • Loading branch information
icleitoncosta authored Aug 16, 2024
1 parent 530038b commit adfe289
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
13 changes: 12 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
outputs:
versions: ${{ steps.versions.outputs.result }}

test:
test_wa_versions:
needs: provide_wa_versions
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -92,6 +92,14 @@ jobs:
- name: Install Dependencies
run: npm ci || npm install

- name: Set environment variables
run: |
if [ "${{ github.actor }}" = "renovate" ]; then
echo "SEND_WEBHOOK_FAILURE=true" >> $GITHUB_ENV
else
echo "SEND_WEBHOOK_FAILURE=false" >> $GITHUB_ENV
fi
- name: Test modules resolution
uses: nick-invision/retry@v3
with:
Expand All @@ -100,3 +108,6 @@ jobs:
command: npm run update-module-id -- --dry-run
env:
WA_VERSION: '${{matrix.versions }}'
DISCORD_WEBHOOK_URL_FAILURE: '${{ secrets.DISCORD_WEBHOOK_URL_FAILURE }}'
SEND_WEBHOOK_FAILURE: '${{ env.SEND_WEBHOOK_FAILURE }}'
URL_ACTION: 'https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}'
19 changes: 19 additions & 0 deletions src/tools/updateModuleID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import * as fs from 'fs';
import fetch from 'node-fetch';
import * as path from 'path';
import { JSDoc, Node, Project } from 'ts-morph';

Expand Down Expand Up @@ -97,6 +98,24 @@ async function start() {

for (const moduleName of Object.keys(result)) {
if (!result[moduleName]) {
if (
process.env['SEND_WEBHOOK_FAILURE'] &&
process.env['DISCORD_WEBHOOK_URL_FAILURE']
) {
const message = {
content: `**Alert:**\nModule not found: ${moduleName}. v: ${version}\n\n See more at: ${process.env['URL_ACTION']}`,
};

await fetch(process.env['DISCORD_WEBHOOK_URL_FAILURE'], {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(message),
}).catch((error) =>
console.error('Error on send message to discord:', error)
);
}
exitCode = 1;
console.error(`Module not found: ${moduleName}`);
}
Expand Down

0 comments on commit adfe289

Please sign in to comment.