-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
associate-issue-with-sentry.ts
51 lines (44 loc) · 1.46 KB
/
associate-issue-with-sentry.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const body = process.env.GITHUB_ISSUE_BODY;
const SENTRY_AUTH_TOKEN = process.env.SENTRY_AUTH_TOKEN;
if (!body || !SENTRY_AUTH_TOKEN) {
throw new Error("Missing environment variables");
}
const id = body.indexOf("<!-- sentry_id: ");
const endIdLine = body.indexOf(" -->", id + 1);
if (!(id > -1 && endIdLine > -1)) {
throw new Error("Missing sentry_id");
}
const sentryId = body.slice(id + "<!-- sentry_id: ".length, endIdLine).trim();
if (!sentryId) {
throw new Error("Missing sentry_id");
}
const response = await fetch(`https://sentry.io/api/0/organizations/4507155222364160/eventids/${sentryId}/`, {
headers: {
Authorization: `Bearer ${SENTRY_AUTH_TOKEN}`,
},
});
if (!response.ok) {
throw new Error(`Failed to fetch Sentry event: ${response.statusText}`);
}
const json = await response.json();
const groupId = json?.groupId;
if (!groupId) {
throw new Error("Missing groupId");
}
const issueResponse = await fetch(`https://sentry.io/api/0/issues/${groupId}/`, {
headers: {
Authorization: `Bearer ${SENTRY_AUTH_TOKEN}`,
},
});
if (!issueResponse.ok) {
throw new Error(`Failed to fetch Sentry issue: ${issueResponse.statusText}`);
}
const { shortId, permalink } = await issueResponse.json();
if (!shortId || !permalink) {
throw new Error("Missing shortId or permalink");
}
console.log(`Sentry ID: ${shortId}`);
console.log(`Sentry permalink: ${permalink}`);
await Bun.write("sentry-id.txt", shortId);
await Bun.write("sentry-link.txt", permalink);
export {};