-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Expand file tree
/
Copy pathutils.ts
More file actions
194 lines (186 loc) · 4.47 KB
/
Copy pathutils.ts
File metadata and controls
194 lines (186 loc) · 4.47 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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import { isRecordLike } from '@sim/utils/object'
/**
* Shared repository output schema
*/
export const repositoryOutputs = {
id: {
type: 'number',
description: 'Repository ID',
},
node_id: {
type: 'string',
description: 'Repository node ID',
},
name: {
type: 'string',
description: 'Repository name',
},
full_name: {
type: 'string',
description: 'Repository full name (owner/repo)',
},
private: {
type: 'boolean',
description: 'Whether the repository is private',
},
html_url: {
type: 'string',
description: 'Repository HTML URL',
},
description: {
type: 'string',
description: 'Repository description',
},
fork: {
type: 'boolean',
description: 'Whether the repository is a fork',
},
url: {
type: 'string',
description: 'Repository API URL',
},
homepage: {
type: 'string',
description: 'Repository homepage URL',
},
size: {
type: 'number',
description: 'Repository size in KB',
},
stargazers_count: {
type: 'number',
description: 'Number of stars',
},
watchers_count: {
type: 'number',
description: 'Number of watchers',
},
language: {
type: 'string',
description: 'Primary programming language',
},
forks_count: {
type: 'number',
description: 'Number of forks',
},
open_issues_count: {
type: 'number',
description: 'Number of open issues',
},
default_branch: {
type: 'string',
description: 'Default branch name',
},
owner: {
login: {
type: 'string',
description: 'Owner username',
},
id: {
type: 'number',
description: 'Owner ID',
},
avatar_url: {
type: 'string',
description: 'Owner avatar URL',
},
html_url: {
type: 'string',
description: 'Owner profile URL',
},
},
} as const
/**
* Shared sender/user output schema
*/
export const userOutputs = {
login: {
type: 'string',
description: 'Username',
},
id: {
type: 'number',
description: 'User ID',
},
node_id: {
type: 'string',
description: 'User node ID',
},
avatar_url: {
type: 'string',
description: 'Avatar URL',
},
html_url: {
type: 'string',
description: 'Profile URL',
},
user_type: {
type: 'string',
description: 'User type (User, Bot, Organization)',
},
} as const
/**
* Checks whether a delivered GitHub event matches the expected trigger
* configuration, used for event filtering in the webhook processor.
*
* GitHub fires `issue_comment` for comments on both issues and pull
* requests, and `pull_request` with action `closed` for both a merge and a
* close-without-merge; the `validator` entries disambiguate those cases via
* `issue.pull_request` (present only on PR comments) and
* `pull_request.merged` respectively.
*/
export function isGitHubEventMatch(
triggerId: string,
eventType: string,
action?: string,
payload?: unknown
): boolean {
const eventMap: Record<
string,
{
event: string
actions?: string[]
validator?: (payload: Record<string, unknown>) => boolean
}
> = {
github_issue_opened: { event: 'issues', actions: ['opened'] },
github_issue_closed: { event: 'issues', actions: ['closed'] },
github_issue_comment: {
event: 'issue_comment',
validator: (p) => !isRecordLike(p.issue) || !p.issue.pull_request,
},
github_pr_opened: { event: 'pull_request', actions: ['opened'] },
github_pr_closed: {
event: 'pull_request',
actions: ['closed'],
validator: (p) => isRecordLike(p.pull_request) && p.pull_request.merged === false,
},
github_pr_merged: {
event: 'pull_request',
actions: ['closed'],
validator: (p) => isRecordLike(p.pull_request) && p.pull_request.merged === true,
},
github_pr_comment: {
event: 'issue_comment',
validator: (p) => isRecordLike(p.issue) && !!p.issue.pull_request,
},
github_pr_reviewed: { event: 'pull_request_review', actions: ['submitted'] },
github_push: { event: 'push' },
github_release_published: { event: 'release', actions: ['published'] },
github_workflow_run: { event: 'workflow_run' },
}
const config = eventMap[triggerId]
if (!config) {
return true
}
if (config.event !== eventType) {
return false
}
if (config.actions && action && !config.actions.includes(action)) {
return false
}
if (config.validator) {
return config.validator(isRecordLike(payload) ? payload : {})
}
return true
}