agentgate 0.1.9 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/notifier.js +45 -17
package/package.json
CHANGED
package/src/lib/notifier.js
CHANGED
|
@@ -7,6 +7,30 @@ import { getSetting, updateQueueNotification } from './db.js';
|
|
|
7
7
|
const DEFAULT_RETRY_ATTEMPTS = 3;
|
|
8
8
|
const DEFAULT_RETRY_DELAY_MS = 5000;
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Find the most relevant result to display (usually last one with a URL, or first failure)
|
|
12
|
+
*/
|
|
13
|
+
function findRelevantResult(results, forError = false) {
|
|
14
|
+
if (!results?.length) return null;
|
|
15
|
+
|
|
16
|
+
if (forError) {
|
|
17
|
+
// For errors, find the first non-ok result
|
|
18
|
+
return results.find(r => !r.ok) || results[results.length - 1];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
// For success, find the last result with a useful URL (PR, issue, etc.)
|
|
22
|
+
// Search backwards to get the most relevant one (e.g., PR URL, not branch ref)
|
|
23
|
+
for (let i = results.length - 1; i >= 0; i--) {
|
|
24
|
+
const r = results[i];
|
|
25
|
+
if (r.body?.html_url || r.body?.url) {
|
|
26
|
+
return r;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Fallback to last result
|
|
31
|
+
return results[results.length - 1];
|
|
32
|
+
}
|
|
33
|
+
|
|
10
34
|
/**
|
|
11
35
|
* Format the notification text for a queue entry
|
|
12
36
|
*/
|
|
@@ -18,29 +42,29 @@ function formatNotification(entry) {
|
|
|
18
42
|
text += `\n→ ${entry.service}/${entry.account_name}`;
|
|
19
43
|
|
|
20
44
|
// Include key result info (e.g., PR URL, issue URL)
|
|
21
|
-
if (entry.results?.length) {
|
|
22
|
-
const
|
|
23
|
-
if (
|
|
45
|
+
if (entry.status === 'completed' && entry.results?.length) {
|
|
46
|
+
const relevantResult = findRelevantResult(entry.results, false);
|
|
47
|
+
if (relevantResult?.body) {
|
|
24
48
|
// GitHub PR/Issue
|
|
25
|
-
if (
|
|
26
|
-
text += `\n→ ${
|
|
49
|
+
if (relevantResult.body.html_url) {
|
|
50
|
+
text += `\n→ ${relevantResult.body.html_url}`;
|
|
27
51
|
}
|
|
28
52
|
// Other useful fields
|
|
29
|
-
else if (
|
|
30
|
-
text += `\n→ ${
|
|
53
|
+
else if (relevantResult.body.url) {
|
|
54
|
+
text += `\n→ ${relevantResult.body.url}`;
|
|
31
55
|
}
|
|
32
56
|
}
|
|
33
57
|
}
|
|
34
58
|
|
|
35
59
|
// Include error info for failures
|
|
36
60
|
if (entry.status === 'failed' && entry.results?.length) {
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
text += `\n→ Error: ${
|
|
40
|
-
} else if (
|
|
41
|
-
text += `\n→ Error: ${
|
|
42
|
-
} else if (
|
|
43
|
-
text += `\n→ Error: HTTP ${
|
|
61
|
+
const failingResult = findRelevantResult(entry.results, true);
|
|
62
|
+
if (failingResult.error) {
|
|
63
|
+
text += `\n→ Error: ${failingResult.error}`;
|
|
64
|
+
} else if (failingResult.body?.message) {
|
|
65
|
+
text += `\n→ Error: ${failingResult.body.message}`;
|
|
66
|
+
} else if (!failingResult.ok && failingResult.status) {
|
|
67
|
+
text += `\n→ Error: HTTP ${failingResult.status}`;
|
|
44
68
|
}
|
|
45
69
|
}
|
|
46
70
|
|
|
@@ -166,10 +190,14 @@ function formatBatchLine(entry) {
|
|
|
166
190
|
let line = `${emoji} #${entry.id.substring(0, 8)} - ${entry.service}/${entry.account_name}`;
|
|
167
191
|
|
|
168
192
|
// Add brief result info
|
|
169
|
-
if (entry.status === 'completed'
|
|
170
|
-
|
|
193
|
+
if (entry.status === 'completed') {
|
|
194
|
+
const relevantResult = findRelevantResult(entry.results, false);
|
|
195
|
+
if (relevantResult?.body?.html_url) {
|
|
196
|
+
line += ` - ${relevantResult.body.html_url}`;
|
|
197
|
+
}
|
|
171
198
|
} else if (entry.status === 'failed') {
|
|
172
|
-
const
|
|
199
|
+
const failingResult = findRelevantResult(entry.results, true);
|
|
200
|
+
const err = failingResult?.error || failingResult?.body?.message || (failingResult && !failingResult.ok ? `HTTP ${failingResult.status || '?'}` : 'Unknown error');
|
|
173
201
|
line += ` - ${err.substring(0, 50)}`;
|
|
174
202
|
} else if (entry.status === 'rejected') {
|
|
175
203
|
line += ` - ${(entry.rejection_reason || 'rejected').substring(0, 50)}`;
|