Skip to content

Commit d0ee97e

Browse files
committed
Send E2E test failures to NC Talk conversion if credentials provided
Change-Id: Ibe20bdb7e57eac536a2e7e7fe12fb2a5df4ed736
1 parent 6247158 commit d0ee97e

File tree

4 files changed

+82
-6
lines changed

4 files changed

+82
-6
lines changed

Readme.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ KORAP_URL="http://localhost:64543" KORAP_USERNAME="user2" KORAP_PASSWORD="passwo
3434
| `SLACK_WEBHOOK_URL` | _(none)_ | Slack webhook URL for test failure notifications (text only) |
3535
| `SLACK_TOKEN` | _(none)_ | Slack bot token for uploading failure screenshots |
3636
| `SLACK_CHANNEL_ID` | `C07CM4JS48H` | Slack channel ID for screenshot uploads (e.g., `C1234567890`) |
37+
| `NC_TALK_URL` | `https://cloud.ids-mannheim.de` | Nextcloud instance URL for Talk notifications |
38+
| `NC_TALK_CONVERSATION` | _(none)_ | Nextcloud Talk conversation token for notifications |
39+
| `NC_TALK_SECRET` | _(none)_ | Nextcloud Talk bot secret for authentication |
3740
| `LC_ALL` | _(system default)_ | Locale setting (recommended: `C` for consistent results) |
3841

3942
### Usage Notes
@@ -54,8 +57,30 @@ Quick setup:
5457

5558
### Notifications
5659

60+
#### Slack Notifications
61+
5762
If you run KorAP-E2E-tests as a cronjob or in scheduled pipelines and
58-
want to get notified about failed tests via slack, set the environment variable `SLACK_WEBHOOK_URL` to the URL of your [slack webhook](https://api.slack.com/messaging/webhooks).
63+
want to get notified about failed tests via Slack, set the environment variable `SLACK_WEBHOOK_URL` to the URL of your [Slack webhook](https://api.slack.com/messaging/webhooks).
64+
65+
For screenshot uploads, also set:
66+
67+
- `SLACK_TOKEN`: Your Slack bot token (starts with `xoxb-`)
68+
- `SLACK_CHANNEL_ID`: The channel ID where screenshots should be posted (e.g., `C07CM4JS48H`)
69+
70+
**Note**: The bot must be invited to the channel, and needs the following permissions:
71+
72+
- `chat:write`
73+
- `files:write`
74+
75+
#### Nextcloud Talk Notifications
76+
77+
To receive test failure notifications in Nextcloud Talk, set these environment variables:
78+
79+
- `NC_TALK_URL`: Your Nextcloud instance URL (default: `https://cloud.ids-mannheim.de`)
80+
- `NC_TALK_CONVERSATION`: The conversation/room token (e.g., `o6toyqx7`)
81+
- `NC_TALK_SECRET`: The bot secret for authentication
82+
83+
The bot must be configured in your Nextcloud Talk settings with the appropriate secret.
5984

6085

6186
## Development and License

package-lock.json

Lines changed: 2 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"license": "APACHE-2.0",
2020
"dependencies": {
2121
"@slack/web-api": "^7.12.0",
22+
"axios": "^1.7.9",
2223
"chai": "^6.2.0",
2324
"form-data": "^4.0.5",
2425
"mocha": "^11.7.4",

test/korap-ui.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const https = require('https');
2+
const crypto = require('crypto');
23
const puppeteer = require('puppeteer-extra');
34
puppeteer.use(require('puppeteer-extra-plugin-user-preferences')({
45
userPrefs: {
@@ -22,11 +23,53 @@ const KORAP_MIN_TOKENS_IN_CORPUS = parseInt(process.env.KORAP_MIN_TOKENS_IN_CORP
2223
const korap_rc = require('../lib/korap_rc.js').new(KORAP_URL)
2324

2425
const slack_webhook = process.env.SLACK_WEBHOOK_URL;
26+
const nc_talk_url = process.env.NC_TALK_URL || 'https://cloud.ids-mannheim.de';
27+
const nc_talk_conversation = process.env.NC_TALK_CONVERSATION;
28+
const nc_talk_secret = process.env.NC_TALK_SECRET;
2529

2630
if (slack_webhook) {
2731
slack = require('slack-notify')(slack_webhook);
2832
}
2933

34+
// Function to send message to Nextcloud Talk
35+
async function sendToNextcloudTalk(message, silent = false) {
36+
if (!nc_talk_conversation || !nc_talk_secret) {
37+
return;
38+
}
39+
40+
try {
41+
const axios = require('axios');
42+
43+
// Generate random header and signature
44+
const randomHeader = crypto.randomBytes(32).toString('hex');
45+
const messageToSign = randomHeader + message;
46+
const signature = crypto.createHmac('sha256', nc_talk_secret)
47+
.update(messageToSign)
48+
.digest('hex');
49+
50+
// Send the message
51+
await axios.post(
52+
`${nc_talk_url}/ocs/v2.php/apps/spreed/api/v1/bot/${nc_talk_conversation}/message`,
53+
{
54+
message: message,
55+
silent: silent
56+
},
57+
{
58+
headers: {
59+
'Content-Type': 'application/json',
60+
'Accept': 'application/json',
61+
'OCS-APIRequest': 'true',
62+
'X-Nextcloud-Talk-Bot-Random': randomHeader,
63+
'X-Nextcloud-Talk-Bot-Signature': signature
64+
}
65+
}
66+
);
67+
console.log('Message sent to Nextcloud Talk successfully');
68+
} catch (error) {
69+
console.error('Failed to send message to Nextcloud Talk:', error.message);
70+
}
71+
}
72+
3073
function ifConditionIt(title, condition, test) {
3174
return condition ? it(title, test) : it.skip(title + " (skipped)", test)
3275
}
@@ -89,6 +132,16 @@ describe('Running KorAP UI end-to-end tests on ' + KORAP_URL, () => {
89132
}
90133
}
91134

135+
// Send notification to Nextcloud Talk
136+
if (nc_talk_conversation && nc_talk_secret) {
137+
try {
138+
const message = `🚨 Test on ${KORAP_URL} failed: **${this.currentTest.title}**`;
139+
await sendToNextcloudTalk(message);
140+
} catch (ncError) {
141+
console.error('Failed to send notification to Nextcloud Talk:', ncError.message);
142+
}
143+
}
144+
92145
// Only take screenshot if it's not one of the initial connectivity/SSL tests
93146
const initialTestTitles = [
94147
'should be reachable',

0 commit comments

Comments
 (0)