forked from Txio-labs/txio-telegram-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatters.ts
More file actions
65 lines (59 loc) · 2.64 KB
/
Copy pathformatters.ts
File metadata and controls
65 lines (59 loc) · 2.64 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import type { EmitterWebhookEvent } from "@octokit/webhooks";
import { escapeHtml } from "../utils/html.js";
function link(url: string, label: string): string {
return `<a href="${url}">${escapeHtml(label)}</a>`;
}
export function formatIssueEvent({ payload }: EmitterWebhookEvent<"issues">): string {
const { action, issue, repository } = payload;
const icon = action === "opened" ? "🆕" : action === "reopened" ? "🔁" : "✅";
return (
`${icon} Issue ${action} in ${link(repository.html_url, repository.full_name)}\n` +
`${link(issue.html_url, `#${issue.number} ${issue.title}`)}\n` +
`by ${escapeHtml(issue.user?.login ?? "unknown")}`
);
}
export function formatPullRequestEvent({
payload,
}: EmitterWebhookEvent<"pull_request">): string {
const { action, pull_request: pr, repository } = payload;
const merged = action === "closed" && pr.merged;
const label = merged ? "merged" : action;
const icon = action === "opened" ? "🆕" : merged ? "🎉" : action === "reopened" ? "🔁" : "❌";
return (
`${icon} Pull request ${label} in ${link(repository.html_url, repository.full_name)}\n` +
`${link(pr.html_url, `#${pr.number} ${pr.title}`)}\n` +
`by ${escapeHtml(pr.user?.login ?? "unknown")}`
);
}
export function formatMergeConflictEvent(
pr: { html_url: string; number: number; title: string },
repository: { html_url: string; full_name: string },
): string {
return (
`⚠️ Merge conflict on ${link(repository.html_url, repository.full_name)}\n` +
`${link(pr.html_url, `#${pr.number} ${pr.title}`)} can't be merged — needs to be updated with the base branch.`
);
}
export function formatWorkflowRunEvent({
payload,
}: EmitterWebhookEvent<"workflow_run">): string | null {
const { workflow_run: run, repository } = payload;
if (run.status !== "completed") return null;
const icon = run.conclusion === "success" ? "✅" : run.conclusion === "cancelled" ? "⚪" : "❌";
return (
`${icon} CI ${run.conclusion} for ${link(repository.html_url, repository.full_name)}\n` +
`${link(run.html_url, run.name ?? "workflow")} on ${escapeHtml(run.head_branch ?? "unknown")}`
);
}
export function formatDeploymentStatusEvent({
payload,
}: EmitterWebhookEvent<"deployment_status">): string {
const { deployment_status: status, deployment, repository } = payload;
const icon = status.state === "success" ? "🚀" : status.state === "failure" || status.state === "error" ? "❌" : "⏳";
return (
`${icon} Deploy ${status.state} — ${escapeHtml(deployment.environment)} (${link(
repository.html_url,
repository.full_name,
)})\n` + (status.log_url ? link(status.log_url, "logs") : "")
);
}