This repository has been archived by the owner on Jul 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.ts
101 lines (96 loc) · 2.78 KB
/
github.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
export type GithubWebRepository = {
id: number
name: string
full_name: string
private: boolean
git_url: string
ssh_url: string
}
export type GitHubWebhookPayload = {
ref: string
repository: GithubWebRepository
}
export type GitHubWebhookIssuesEvent = GitHubWebhookPayload & {
action: string
issue: {
number: number
title: string
body: string
url: string
repository_url: string
labels_url: string
comments_url: string
events_url: string
html_url: string
id: number
node_id: string
user: {
login: string
id: number
node_id: string
avatar_url: string
gravatar_id: string
url: string
html_url: string
followers_url: string
following_url: string
gists_url: string
starred_url: string
subscriptions_url: string
organizations_url: string
repos_url: string
events_url: string
received_events_url: string
type: string
site_admin: boolean
}
labels: {
id: number
node_id: string
url: string
name: string
color: string
default: boolean
description: string
}[]
locked: boolean
assignee: null
assignees: []
milestone: null
comments: number
created_at: string
updated_at: string
closed_at: null
author_association: string
active_lock_reason: null
reactions: {
url: string
total_count: number
'+1': number
'-1': number
laugh: number
hooray: number
confused: number
heart: number
rocket: number
eyes: number
}
timeline_url: string
performed_via_github_app: null
state_reason: null
}
}
export function toIssueTemplate(template:string, payload: GitHubWebhookIssuesEvent): string {
return template
.replace("{{title}}", payload.issue.title)
.replace("{{body}}", payload.issue.body)
.replace("{{url}}", payload.issue.html_url)
.replace("{{author}}", payload.issue.user.login)
.replace("{{author_url}}", payload.issue.user.html_url)
.replace("{{created_at}}", payload.issue.created_at)
.replace("{{updated_at}}", payload.issue.updated_at)
.replace("{{labels}}", payload.issue.labels.map(l => l.name).join(", "))
.replace("{{comments}}", payload.issue.comments.toString())
.replace("{{reactions}}", payload.issue.reactions.total_count.toString())
.replace("{{repository}}", payload.repository.name)
}