@bernierllc/github-parser 1.2.5 → 1.4.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/dist/errors.d.ts +11 -0
- package/dist/errors.js +24 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -1
- package/package.json +7 -2
- package/.eslintrc.cjs +0 -33
- package/CHANGELOG.md +0 -99
- package/__tests__/github-parser.test.ts +0 -865
- package/jest.config.cjs +0 -30
- package/src/github-parser.ts +0 -213
- package/src/index.ts +0 -16
- package/src/types.ts +0 -89
- package/tsconfig.json +0 -23
|
@@ -1,865 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
Copyright (c) 2025 Bernier LLC
|
|
3
|
-
|
|
4
|
-
This file is licensed to the client under a limited-use license.
|
|
5
|
-
The client may use and modify this code *only within the scope of the project it was delivered for*.
|
|
6
|
-
Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import { GitHubParser } from '../src';
|
|
10
|
-
|
|
11
|
-
describe('GitHubParser', () => {
|
|
12
|
-
let parser: GitHubParser;
|
|
13
|
-
|
|
14
|
-
beforeEach(() => {
|
|
15
|
-
parser = new GitHubParser();
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it('should create a GitHub parser', () => {
|
|
19
|
-
expect(parser).toBeInstanceOf(GitHubParser);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('should parse push webhook payload', () => {
|
|
23
|
-
const payload = {
|
|
24
|
-
ref: 'refs/heads/main',
|
|
25
|
-
repository: {
|
|
26
|
-
id: 123,
|
|
27
|
-
name: 'test-repo',
|
|
28
|
-
full_name: 'owner/test-repo',
|
|
29
|
-
owner: {
|
|
30
|
-
login: 'owner',
|
|
31
|
-
type: 'User'
|
|
32
|
-
},
|
|
33
|
-
default_branch: 'main',
|
|
34
|
-
html_url: 'https://github.com/owner/test-repo',
|
|
35
|
-
private: false
|
|
36
|
-
},
|
|
37
|
-
commits: [
|
|
38
|
-
{
|
|
39
|
-
id: 'abc123',
|
|
40
|
-
message: 'Test commit',
|
|
41
|
-
author: {
|
|
42
|
-
name: 'Test User',
|
|
43
|
-
email: 'test@example.com',
|
|
44
|
-
username: 'testuser'
|
|
45
|
-
},
|
|
46
|
-
timestamp: '2025-01-28T00:00:00Z',
|
|
47
|
-
url: 'https://github.com/owner/test-repo/commit/abc123',
|
|
48
|
-
added: ['file1.ts'],
|
|
49
|
-
removed: [],
|
|
50
|
-
modified: []
|
|
51
|
-
}
|
|
52
|
-
]
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
const result = parser.parse(payload);
|
|
56
|
-
|
|
57
|
-
expect(result.type).toBe('push');
|
|
58
|
-
expect(result.repository.name).toBe('test-repo');
|
|
59
|
-
expect(result.commits).toHaveLength(1);
|
|
60
|
-
expect(result.commits?.[0].sha).toBe('abc123');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('should extract repository information', () => {
|
|
64
|
-
const payload = {
|
|
65
|
-
repository: {
|
|
66
|
-
id: 456,
|
|
67
|
-
name: 'repo',
|
|
68
|
-
full_name: 'user/repo',
|
|
69
|
-
owner: {
|
|
70
|
-
login: 'user',
|
|
71
|
-
type: 'Organization'
|
|
72
|
-
},
|
|
73
|
-
default_branch: 'develop',
|
|
74
|
-
html_url: 'https://github.com/user/repo',
|
|
75
|
-
private: true
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const repo = parser.extractRepository(payload);
|
|
80
|
-
|
|
81
|
-
expect(repo.id).toBe(456);
|
|
82
|
-
expect(repo.name).toBe('repo');
|
|
83
|
-
expect(repo.fullName).toBe('user/repo');
|
|
84
|
-
expect(repo.owner.login).toBe('user');
|
|
85
|
-
expect(repo.private).toBe(true);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('should extract commits from push webhook', () => {
|
|
89
|
-
const payload = {
|
|
90
|
-
commits: [
|
|
91
|
-
{
|
|
92
|
-
id: 'commit1',
|
|
93
|
-
message: 'First commit',
|
|
94
|
-
author: { name: 'Author', email: 'author@example.com' },
|
|
95
|
-
timestamp: '2025-01-28T00:00:00Z',
|
|
96
|
-
url: 'https://github.com/owner/repo/commit/commit1',
|
|
97
|
-
added: ['file1.ts'],
|
|
98
|
-
removed: ['file2.ts'],
|
|
99
|
-
modified: ['file3.ts']
|
|
100
|
-
}
|
|
101
|
-
]
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
const commits = parser.extractCommits(payload);
|
|
105
|
-
|
|
106
|
-
expect(commits).toHaveLength(1);
|
|
107
|
-
expect(commits[0].sha).toBe('commit1');
|
|
108
|
-
expect(commits[0].additions).toBe(1);
|
|
109
|
-
expect(commits[0].deletions).toBe(1);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('should extract single commit', () => {
|
|
113
|
-
const payload = {
|
|
114
|
-
commit: {
|
|
115
|
-
sha: 'def456',
|
|
116
|
-
message: 'Single commit',
|
|
117
|
-
author: { name: 'Developer', email: 'dev@example.com' },
|
|
118
|
-
timestamp: '2025-01-28T12:00:00Z',
|
|
119
|
-
url: 'https://github.com/owner/repo/commit/def456',
|
|
120
|
-
additions: 10,
|
|
121
|
-
deletions: 5,
|
|
122
|
-
modified: ['file1.ts', 'file2.ts']
|
|
123
|
-
}
|
|
124
|
-
};
|
|
125
|
-
|
|
126
|
-
const commit = parser.extractCommit(payload);
|
|
127
|
-
|
|
128
|
-
expect(commit).not.toBeNull();
|
|
129
|
-
expect(commit?.sha).toBe('def456');
|
|
130
|
-
expect(commit?.message).toBe('Single commit');
|
|
131
|
-
expect(commit?.additions).toBe(10);
|
|
132
|
-
expect(commit?.deletions).toBe(5);
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
it('should return null when no commit exists', () => {
|
|
136
|
-
const payload = {};
|
|
137
|
-
const commit = parser.extractCommit(payload);
|
|
138
|
-
expect(commit).toBeNull();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it('should normalize pull_request event type', () => {
|
|
142
|
-
const payload = {
|
|
143
|
-
pull_request: { number: 1 },
|
|
144
|
-
repository: {
|
|
145
|
-
id: 1,
|
|
146
|
-
name: 'repo',
|
|
147
|
-
full_name: 'user/repo',
|
|
148
|
-
owner: { login: 'user', type: 'User' },
|
|
149
|
-
default_branch: 'main',
|
|
150
|
-
html_url: 'https://github.com/user/repo',
|
|
151
|
-
private: false
|
|
152
|
-
}
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
const result = parser.parse(payload);
|
|
156
|
-
expect(result.type).toBe('pull_request');
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
it('should normalize issues event type', () => {
|
|
160
|
-
const payload = {
|
|
161
|
-
issue: { number: 1 },
|
|
162
|
-
repository: {
|
|
163
|
-
id: 1,
|
|
164
|
-
name: 'repo',
|
|
165
|
-
full_name: 'user/repo',
|
|
166
|
-
owner: { login: 'user', type: 'User' },
|
|
167
|
-
default_branch: 'main',
|
|
168
|
-
html_url: 'https://github.com/user/repo',
|
|
169
|
-
private: false
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const result = parser.parse(payload);
|
|
174
|
-
expect(result.type).toBe('issues');
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('should normalize release event type', () => {
|
|
178
|
-
const payload = {
|
|
179
|
-
release: { tag_name: 'v1.0.0' },
|
|
180
|
-
repository: {
|
|
181
|
-
id: 1,
|
|
182
|
-
name: 'repo',
|
|
183
|
-
full_name: 'user/repo',
|
|
184
|
-
owner: { login: 'user', type: 'User' },
|
|
185
|
-
default_branch: 'main',
|
|
186
|
-
html_url: 'https://github.com/user/repo',
|
|
187
|
-
private: false
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
const result = parser.parse(payload);
|
|
192
|
-
expect(result.type).toBe('release');
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it('should handle explicit X-GitHub-Event header', () => {
|
|
196
|
-
const payload = {
|
|
197
|
-
'X-GitHub-Event': 'push',
|
|
198
|
-
repository: {
|
|
199
|
-
id: 1,
|
|
200
|
-
name: 'repo',
|
|
201
|
-
full_name: 'user/repo',
|
|
202
|
-
owner: { login: 'user', type: 'User' },
|
|
203
|
-
default_branch: 'main',
|
|
204
|
-
html_url: 'https://github.com/user/repo',
|
|
205
|
-
private: false
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const eventType = parser.normalizeEventType(payload);
|
|
210
|
-
expect(eventType).toBe('push');
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
it('should extract action from payload', () => {
|
|
214
|
-
const payload = {
|
|
215
|
-
action: 'opened',
|
|
216
|
-
pull_request: { number: 1 },
|
|
217
|
-
repository: {
|
|
218
|
-
id: 1,
|
|
219
|
-
name: 'repo',
|
|
220
|
-
full_name: 'user/repo',
|
|
221
|
-
owner: { login: 'user', type: 'User' },
|
|
222
|
-
default_branch: 'main',
|
|
223
|
-
html_url: 'https://github.com/user/repo',
|
|
224
|
-
private: false
|
|
225
|
-
}
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
const result = parser.parse(payload);
|
|
229
|
-
expect(result.action).toBe('opened');
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it('should extract branch from ref', () => {
|
|
233
|
-
const payload = {
|
|
234
|
-
ref: 'refs/heads/feature-branch',
|
|
235
|
-
repository: {
|
|
236
|
-
id: 1,
|
|
237
|
-
name: 'repo',
|
|
238
|
-
full_name: 'user/repo',
|
|
239
|
-
owner: { login: 'user', type: 'User' },
|
|
240
|
-
default_branch: 'main',
|
|
241
|
-
html_url: 'https://github.com/user/repo',
|
|
242
|
-
private: false
|
|
243
|
-
},
|
|
244
|
-
commits: []
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
const result = parser.parse(payload);
|
|
248
|
-
expect(result.branch).toBe('feature-branch');
|
|
249
|
-
expect(result.ref).toBe('refs/heads/feature-branch');
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
it('should extract sender information', () => {
|
|
253
|
-
const payload = {
|
|
254
|
-
ref: 'refs/heads/main',
|
|
255
|
-
sender: {
|
|
256
|
-
login: 'octocat',
|
|
257
|
-
type: 'User'
|
|
258
|
-
},
|
|
259
|
-
repository: {
|
|
260
|
-
id: 1,
|
|
261
|
-
name: 'repo',
|
|
262
|
-
full_name: 'user/repo',
|
|
263
|
-
owner: { login: 'user', type: 'User' },
|
|
264
|
-
default_branch: 'main',
|
|
265
|
-
html_url: 'https://github.com/user/repo',
|
|
266
|
-
private: false
|
|
267
|
-
},
|
|
268
|
-
commits: []
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
const result = parser.parse(payload);
|
|
272
|
-
expect(result.sender).toEqual({
|
|
273
|
-
login: 'octocat',
|
|
274
|
-
type: 'User'
|
|
275
|
-
});
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it('should handle commit with committer fallback', () => {
|
|
279
|
-
const payload = {
|
|
280
|
-
commits: [
|
|
281
|
-
{
|
|
282
|
-
id: 'xyz789',
|
|
283
|
-
message: 'Commit with committer',
|
|
284
|
-
committer: { name: 'Committer', email: 'committer@example.com' },
|
|
285
|
-
timestamp: '2025-01-28T00:00:00Z',
|
|
286
|
-
url: 'https://github.com/owner/repo/commit/xyz789',
|
|
287
|
-
added: [],
|
|
288
|
-
removed: [],
|
|
289
|
-
modified: []
|
|
290
|
-
}
|
|
291
|
-
]
|
|
292
|
-
};
|
|
293
|
-
|
|
294
|
-
const commits = parser.extractCommits(payload);
|
|
295
|
-
expect(commits[0].author.name).toBe('Committer');
|
|
296
|
-
expect(commits[0].author.email).toBe('committer@example.com');
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it('should handle empty commits array', () => {
|
|
300
|
-
const payload = {
|
|
301
|
-
commits: []
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
const commits = parser.extractCommits(payload);
|
|
305
|
-
expect(commits).toHaveLength(0);
|
|
306
|
-
});
|
|
307
|
-
|
|
308
|
-
it('should handle missing commits field', () => {
|
|
309
|
-
const payload = {};
|
|
310
|
-
|
|
311
|
-
const commits = parser.extractCommits(payload);
|
|
312
|
-
expect(commits).toHaveLength(0);
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
it('should throw error when repository is missing', () => {
|
|
316
|
-
const payload = {};
|
|
317
|
-
|
|
318
|
-
expect(() => parser.extractRepository(payload)).toThrow('Repository information not found in payload');
|
|
319
|
-
});
|
|
320
|
-
|
|
321
|
-
it('should handle unknown event type', () => {
|
|
322
|
-
const payload = {
|
|
323
|
-
repository: {
|
|
324
|
-
id: 1,
|
|
325
|
-
name: 'repo',
|
|
326
|
-
full_name: 'user/repo',
|
|
327
|
-
owner: { login: 'user', type: 'User' },
|
|
328
|
-
default_branch: 'main',
|
|
329
|
-
html_url: 'https://github.com/user/repo',
|
|
330
|
-
private: false
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
const result = parser.parse(payload);
|
|
335
|
-
expect(result.type).toBe('unknown');
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
it('should handle commit without timestamp', () => {
|
|
339
|
-
const payload = {
|
|
340
|
-
commits: [
|
|
341
|
-
{
|
|
342
|
-
id: 'no-time',
|
|
343
|
-
message: 'No timestamp',
|
|
344
|
-
author: { name: 'Author', email: 'author@example.com' },
|
|
345
|
-
url: 'https://github.com/owner/repo/commit/no-time',
|
|
346
|
-
added: [],
|
|
347
|
-
removed: [],
|
|
348
|
-
modified: []
|
|
349
|
-
}
|
|
350
|
-
]
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
const commits = parser.extractCommits(payload);
|
|
354
|
-
expect(commits[0].timestamp).toBeInstanceOf(Date);
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
it('should parse non-push event with commit field', () => {
|
|
358
|
-
const payload = {
|
|
359
|
-
'X-GitHub-Event': 'status',
|
|
360
|
-
commit: {
|
|
361
|
-
sha: 'abc123',
|
|
362
|
-
message: 'Status update',
|
|
363
|
-
author: { name: 'Bot', email: 'bot@example.com' },
|
|
364
|
-
timestamp: '2025-01-28T00:00:00Z',
|
|
365
|
-
url: 'https://github.com/owner/repo/commit/abc123',
|
|
366
|
-
additions: 0,
|
|
367
|
-
deletions: 0,
|
|
368
|
-
modified: []
|
|
369
|
-
},
|
|
370
|
-
repository: {
|
|
371
|
-
id: 1,
|
|
372
|
-
name: 'repo',
|
|
373
|
-
full_name: 'user/repo',
|
|
374
|
-
owner: { login: 'user', type: 'User' },
|
|
375
|
-
default_branch: 'main',
|
|
376
|
-
html_url: 'https://github.com/user/repo',
|
|
377
|
-
private: false
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
const result = parser.parse(payload);
|
|
382
|
-
expect(result.type).toBe('status');
|
|
383
|
-
expect(result.commit).toBeDefined();
|
|
384
|
-
expect(result.commit?.sha).toBe('abc123');
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
it('should handle event type with action field', () => {
|
|
388
|
-
const payload = {
|
|
389
|
-
action: 'published',
|
|
390
|
-
repository: {
|
|
391
|
-
id: 1,
|
|
392
|
-
name: 'repo',
|
|
393
|
-
full_name: 'user/repo',
|
|
394
|
-
owner: { login: 'user', type: 'User' },
|
|
395
|
-
default_branch: 'main',
|
|
396
|
-
html_url: 'https://github.com/user/repo',
|
|
397
|
-
private: false
|
|
398
|
-
}
|
|
399
|
-
};
|
|
400
|
-
|
|
401
|
-
const eventType = parser.normalizeEventType(payload);
|
|
402
|
-
expect(eventType).toBe('published');
|
|
403
|
-
});
|
|
404
|
-
|
|
405
|
-
it('should handle event type with type field', () => {
|
|
406
|
-
const payload = {
|
|
407
|
-
type: 'CheckSuiteEvent',
|
|
408
|
-
repository: {
|
|
409
|
-
id: 1,
|
|
410
|
-
name: 'repo',
|
|
411
|
-
full_name: 'user/repo',
|
|
412
|
-
owner: { login: 'user', type: 'User' },
|
|
413
|
-
default_branch: 'main',
|
|
414
|
-
html_url: 'https://github.com/user/repo',
|
|
415
|
-
private: false
|
|
416
|
-
}
|
|
417
|
-
};
|
|
418
|
-
|
|
419
|
-
const eventType = parser.normalizeEventType(payload);
|
|
420
|
-
expect(eventType).toBe('checksuiteevent');
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
it('should handle ref without refs/heads prefix', () => {
|
|
424
|
-
const payload = {
|
|
425
|
-
ref: 'main',
|
|
426
|
-
repository: {
|
|
427
|
-
id: 1,
|
|
428
|
-
name: 'repo',
|
|
429
|
-
full_name: 'user/repo',
|
|
430
|
-
owner: { login: 'user', type: 'User' },
|
|
431
|
-
default_branch: 'main',
|
|
432
|
-
html_url: 'https://github.com/user/repo',
|
|
433
|
-
private: false
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
const result = parser.parse(payload);
|
|
438
|
-
expect(result.ref).toBe('main');
|
|
439
|
-
expect(result.branch).toBe('main');
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
it('should handle commit with author username', () => {
|
|
443
|
-
const payload = {
|
|
444
|
-
commits: [
|
|
445
|
-
{
|
|
446
|
-
id: 'with-username',
|
|
447
|
-
message: 'Has username',
|
|
448
|
-
author: {
|
|
449
|
-
name: 'Developer',
|
|
450
|
-
email: 'dev@example.com',
|
|
451
|
-
username: 'devuser'
|
|
452
|
-
},
|
|
453
|
-
timestamp: '2025-01-28T00:00:00Z',
|
|
454
|
-
url: 'https://github.com/owner/repo/commit/with-username',
|
|
455
|
-
added: [],
|
|
456
|
-
removed: [],
|
|
457
|
-
modified: []
|
|
458
|
-
}
|
|
459
|
-
]
|
|
460
|
-
};
|
|
461
|
-
|
|
462
|
-
const commits = parser.extractCommits(payload);
|
|
463
|
-
expect(commits[0].author.username).toBe('devuser');
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
it('should handle commit without author or committer', () => {
|
|
467
|
-
const payload = {
|
|
468
|
-
commits: [
|
|
469
|
-
{
|
|
470
|
-
id: 'no-author',
|
|
471
|
-
message: 'No author',
|
|
472
|
-
timestamp: '2025-01-28T00:00:00Z',
|
|
473
|
-
url: 'https://github.com/owner/repo/commit/no-author',
|
|
474
|
-
added: [],
|
|
475
|
-
removed: [],
|
|
476
|
-
modified: []
|
|
477
|
-
}
|
|
478
|
-
]
|
|
479
|
-
};
|
|
480
|
-
|
|
481
|
-
const commits = parser.extractCommits(payload);
|
|
482
|
-
expect(commits[0].author.name).toBe('');
|
|
483
|
-
expect(commits[0].author.email).toBe('');
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
it('should use sha field when id is missing', () => {
|
|
487
|
-
const payload = {
|
|
488
|
-
commits: [
|
|
489
|
-
{
|
|
490
|
-
sha: 'sha123',
|
|
491
|
-
message: 'Has SHA',
|
|
492
|
-
author: { name: 'Author', email: 'author@example.com' },
|
|
493
|
-
timestamp: '2025-01-28T00:00:00Z',
|
|
494
|
-
url: 'https://github.com/owner/repo/commit/sha123',
|
|
495
|
-
added: [],
|
|
496
|
-
removed: [],
|
|
497
|
-
modified: []
|
|
498
|
-
}
|
|
499
|
-
]
|
|
500
|
-
};
|
|
501
|
-
|
|
502
|
-
const commits = parser.extractCommits(payload);
|
|
503
|
-
expect(commits[0].sha).toBe('sha123');
|
|
504
|
-
});
|
|
505
|
-
|
|
506
|
-
it('should handle missing commit message', () => {
|
|
507
|
-
const payload = {
|
|
508
|
-
commits: [
|
|
509
|
-
{
|
|
510
|
-
id: 'no-msg',
|
|
511
|
-
author: { name: 'Author', email: 'author@example.com' },
|
|
512
|
-
timestamp: '2025-01-28T00:00:00Z',
|
|
513
|
-
url: 'https://github.com/owner/repo/commit/no-msg',
|
|
514
|
-
added: [],
|
|
515
|
-
removed: [],
|
|
516
|
-
modified: []
|
|
517
|
-
}
|
|
518
|
-
]
|
|
519
|
-
};
|
|
520
|
-
|
|
521
|
-
const commits = parser.extractCommits(payload);
|
|
522
|
-
expect(commits[0].message).toBe('');
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
it('should handle missing commit url', () => {
|
|
526
|
-
const payload = {
|
|
527
|
-
commits: [
|
|
528
|
-
{
|
|
529
|
-
id: 'no-url',
|
|
530
|
-
message: 'No URL',
|
|
531
|
-
author: { name: 'Author', email: 'author@example.com' },
|
|
532
|
-
timestamp: '2025-01-28T00:00:00Z',
|
|
533
|
-
added: [],
|
|
534
|
-
removed: [],
|
|
535
|
-
modified: []
|
|
536
|
-
}
|
|
537
|
-
]
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
const commits = parser.extractCommits(payload);
|
|
541
|
-
expect(commits[0].url).toBe('');
|
|
542
|
-
});
|
|
543
|
-
|
|
544
|
-
it('should handle repository with fullName field', () => {
|
|
545
|
-
const payload = {
|
|
546
|
-
repository: {
|
|
547
|
-
id: 1,
|
|
548
|
-
name: 'repo',
|
|
549
|
-
fullName: 'user/repo',
|
|
550
|
-
owner: { login: 'user', type: 'User' },
|
|
551
|
-
default_branch: 'main',
|
|
552
|
-
html_url: 'https://github.com/user/repo',
|
|
553
|
-
private: false
|
|
554
|
-
}
|
|
555
|
-
};
|
|
556
|
-
|
|
557
|
-
const repo = parser.extractRepository(payload);
|
|
558
|
-
expect(repo.fullName).toBe('user/repo');
|
|
559
|
-
});
|
|
560
|
-
|
|
561
|
-
it('should handle repository with defaultBranch field', () => {
|
|
562
|
-
const payload = {
|
|
563
|
-
repository: {
|
|
564
|
-
id: 1,
|
|
565
|
-
name: 'repo',
|
|
566
|
-
full_name: 'user/repo',
|
|
567
|
-
owner: { login: 'user', type: 'User' },
|
|
568
|
-
defaultBranch: 'master',
|
|
569
|
-
html_url: 'https://github.com/user/repo',
|
|
570
|
-
private: false
|
|
571
|
-
}
|
|
572
|
-
};
|
|
573
|
-
|
|
574
|
-
const repo = parser.extractRepository(payload);
|
|
575
|
-
expect(repo.defaultBranch).toBe('master');
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
it('should handle repository with htmlUrl field', () => {
|
|
579
|
-
const payload = {
|
|
580
|
-
repository: {
|
|
581
|
-
id: 1,
|
|
582
|
-
name: 'repo',
|
|
583
|
-
full_name: 'user/repo',
|
|
584
|
-
owner: { login: 'user', type: 'User' },
|
|
585
|
-
default_branch: 'main',
|
|
586
|
-
htmlUrl: 'https://github.com/user/repo',
|
|
587
|
-
private: false
|
|
588
|
-
}
|
|
589
|
-
};
|
|
590
|
-
|
|
591
|
-
const repo = parser.extractRepository(payload);
|
|
592
|
-
expect(repo.url).toBe('https://github.com/user/repo');
|
|
593
|
-
});
|
|
594
|
-
|
|
595
|
-
it('should handle repository with only url field', () => {
|
|
596
|
-
const payload = {
|
|
597
|
-
repository: {
|
|
598
|
-
id: 1,
|
|
599
|
-
name: 'repo',
|
|
600
|
-
full_name: 'user/repo',
|
|
601
|
-
owner: { login: 'user', type: 'User' },
|
|
602
|
-
default_branch: 'main',
|
|
603
|
-
url: 'https://api.github.com/repos/user/repo',
|
|
604
|
-
private: false
|
|
605
|
-
}
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
const repo = parser.extractRepository(payload);
|
|
609
|
-
expect(repo.url).toBe('https://api.github.com/repos/user/repo');
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
it('should handle repository with missing owner type', () => {
|
|
613
|
-
const payload = {
|
|
614
|
-
repository: {
|
|
615
|
-
id: 1,
|
|
616
|
-
name: 'repo',
|
|
617
|
-
full_name: 'user/repo',
|
|
618
|
-
owner: { login: 'user' },
|
|
619
|
-
default_branch: 'main',
|
|
620
|
-
html_url: 'https://github.com/user/repo',
|
|
621
|
-
private: false
|
|
622
|
-
}
|
|
623
|
-
};
|
|
624
|
-
|
|
625
|
-
const repo = parser.extractRepository(payload);
|
|
626
|
-
expect(repo.owner.type).toBe('User');
|
|
627
|
-
});
|
|
628
|
-
|
|
629
|
-
it('should handle repository with missing default branch', () => {
|
|
630
|
-
const payload = {
|
|
631
|
-
repository: {
|
|
632
|
-
id: 1,
|
|
633
|
-
name: 'repo',
|
|
634
|
-
full_name: 'user/repo',
|
|
635
|
-
owner: { login: 'user', type: 'User' },
|
|
636
|
-
html_url: 'https://github.com/user/repo',
|
|
637
|
-
private: false
|
|
638
|
-
}
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
const repo = parser.extractRepository(payload);
|
|
642
|
-
expect(repo.defaultBranch).toBe('main');
|
|
643
|
-
});
|
|
644
|
-
|
|
645
|
-
it('should handle commit with missing modified field', () => {
|
|
646
|
-
const payload = {
|
|
647
|
-
commits: [
|
|
648
|
-
{
|
|
649
|
-
id: 'no-modified',
|
|
650
|
-
message: 'No modified',
|
|
651
|
-
author: { name: 'Author', email: 'author@example.com' },
|
|
652
|
-
timestamp: '2025-01-28T00:00:00Z',
|
|
653
|
-
url: 'https://github.com/owner/repo/commit/no-modified',
|
|
654
|
-
added: [],
|
|
655
|
-
removed: []
|
|
656
|
-
}
|
|
657
|
-
]
|
|
658
|
-
};
|
|
659
|
-
|
|
660
|
-
const commits = parser.extractCommits(payload);
|
|
661
|
-
expect(commits[0].files).toEqual([]);
|
|
662
|
-
});
|
|
663
|
-
|
|
664
|
-
it('should handle payload without sender', () => {
|
|
665
|
-
const payload = {
|
|
666
|
-
ref: 'refs/heads/main',
|
|
667
|
-
repository: {
|
|
668
|
-
id: 1,
|
|
669
|
-
name: 'repo',
|
|
670
|
-
full_name: 'user/repo',
|
|
671
|
-
owner: { login: 'user', type: 'User' },
|
|
672
|
-
default_branch: 'main',
|
|
673
|
-
html_url: 'https://github.com/user/repo',
|
|
674
|
-
private: false
|
|
675
|
-
},
|
|
676
|
-
commits: []
|
|
677
|
-
};
|
|
678
|
-
|
|
679
|
-
const result = parser.parse(payload);
|
|
680
|
-
expect(result.sender).toBeUndefined();
|
|
681
|
-
});
|
|
682
|
-
|
|
683
|
-
it('should handle commit with neither sha nor id', () => {
|
|
684
|
-
const payload = {
|
|
685
|
-
commits: [
|
|
686
|
-
{
|
|
687
|
-
message: 'No SHA or ID',
|
|
688
|
-
author: { name: 'Author', email: 'author@example.com' },
|
|
689
|
-
timestamp: '2025-01-28T00:00:00Z',
|
|
690
|
-
url: 'https://github.com/owner/repo/commit/unknown',
|
|
691
|
-
added: [],
|
|
692
|
-
removed: [],
|
|
693
|
-
modified: []
|
|
694
|
-
}
|
|
695
|
-
]
|
|
696
|
-
};
|
|
697
|
-
|
|
698
|
-
const commits = parser.extractCommits(payload);
|
|
699
|
-
expect(commits[0].sha).toBe('');
|
|
700
|
-
});
|
|
701
|
-
|
|
702
|
-
it('should handle repository with missing name', () => {
|
|
703
|
-
const payload = {
|
|
704
|
-
repository: {
|
|
705
|
-
id: 1,
|
|
706
|
-
full_name: 'user/repo',
|
|
707
|
-
owner: { login: 'user', type: 'User' },
|
|
708
|
-
default_branch: 'main',
|
|
709
|
-
html_url: 'https://github.com/user/repo',
|
|
710
|
-
private: false
|
|
711
|
-
}
|
|
712
|
-
};
|
|
713
|
-
|
|
714
|
-
const repo = parser.extractRepository(payload);
|
|
715
|
-
expect(repo.name).toBe('');
|
|
716
|
-
});
|
|
717
|
-
|
|
718
|
-
it('should handle repository with missing full_name and fullName', () => {
|
|
719
|
-
const payload = {
|
|
720
|
-
repository: {
|
|
721
|
-
id: 1,
|
|
722
|
-
name: 'repo',
|
|
723
|
-
owner: { login: 'user', type: 'User' },
|
|
724
|
-
default_branch: 'main',
|
|
725
|
-
html_url: 'https://github.com/user/repo',
|
|
726
|
-
private: false
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
|
|
730
|
-
const repo = parser.extractRepository(payload);
|
|
731
|
-
expect(repo.fullName).toBe('');
|
|
732
|
-
});
|
|
733
|
-
|
|
734
|
-
it('should handle repository owner with missing login', () => {
|
|
735
|
-
const payload = {
|
|
736
|
-
repository: {
|
|
737
|
-
id: 1,
|
|
738
|
-
name: 'repo',
|
|
739
|
-
full_name: 'user/repo',
|
|
740
|
-
owner: { type: 'Organization' },
|
|
741
|
-
default_branch: 'main',
|
|
742
|
-
html_url: 'https://github.com/user/repo',
|
|
743
|
-
private: false
|
|
744
|
-
}
|
|
745
|
-
};
|
|
746
|
-
|
|
747
|
-
const repo = parser.extractRepository(payload);
|
|
748
|
-
expect(repo.owner.login).toBe('');
|
|
749
|
-
});
|
|
750
|
-
|
|
751
|
-
it('should handle repository with all url fields missing', () => {
|
|
752
|
-
const payload = {
|
|
753
|
-
repository: {
|
|
754
|
-
id: 1,
|
|
755
|
-
name: 'repo',
|
|
756
|
-
full_name: 'user/repo',
|
|
757
|
-
owner: { login: 'user', type: 'User' },
|
|
758
|
-
default_branch: 'main',
|
|
759
|
-
private: false
|
|
760
|
-
}
|
|
761
|
-
};
|
|
762
|
-
|
|
763
|
-
const repo = parser.extractRepository(payload);
|
|
764
|
-
expect(repo.url).toBe('');
|
|
765
|
-
});
|
|
766
|
-
|
|
767
|
-
it('should detect pull_request event from X-GitHub-Event header', () => {
|
|
768
|
-
const payload = {
|
|
769
|
-
'X-GitHub-Event': 'pull_request',
|
|
770
|
-
repository: {
|
|
771
|
-
id: 1,
|
|
772
|
-
name: 'repo',
|
|
773
|
-
full_name: 'user/repo',
|
|
774
|
-
owner: { login: 'user', type: 'User' },
|
|
775
|
-
default_branch: 'main',
|
|
776
|
-
html_url: 'https://github.com/user/repo',
|
|
777
|
-
private: false
|
|
778
|
-
}
|
|
779
|
-
};
|
|
780
|
-
|
|
781
|
-
const eventType = parser.normalizeEventType(payload);
|
|
782
|
-
expect(eventType).toBe('pull_request');
|
|
783
|
-
});
|
|
784
|
-
|
|
785
|
-
it('should detect issues event from X-GitHub-Event header', () => {
|
|
786
|
-
const payload = {
|
|
787
|
-
'X-GitHub-Event': 'issues',
|
|
788
|
-
repository: {
|
|
789
|
-
id: 1,
|
|
790
|
-
name: 'repo',
|
|
791
|
-
full_name: 'user/repo',
|
|
792
|
-
owner: { login: 'user', type: 'User' },
|
|
793
|
-
default_branch: 'main',
|
|
794
|
-
html_url: 'https://github.com/user/repo',
|
|
795
|
-
private: false
|
|
796
|
-
}
|
|
797
|
-
};
|
|
798
|
-
|
|
799
|
-
const eventType = parser.normalizeEventType(payload);
|
|
800
|
-
expect(eventType).toBe('issues');
|
|
801
|
-
});
|
|
802
|
-
|
|
803
|
-
it('should detect release event from X-GitHub-Event header', () => {
|
|
804
|
-
const payload = {
|
|
805
|
-
'X-GitHub-Event': 'release',
|
|
806
|
-
repository: {
|
|
807
|
-
id: 1,
|
|
808
|
-
name: 'repo',
|
|
809
|
-
full_name: 'user/repo',
|
|
810
|
-
owner: { login: 'user', type: 'User' },
|
|
811
|
-
default_branch: 'main',
|
|
812
|
-
html_url: 'https://github.com/user/repo',
|
|
813
|
-
private: false
|
|
814
|
-
}
|
|
815
|
-
};
|
|
816
|
-
|
|
817
|
-
const eventType = parser.normalizeEventType(payload);
|
|
818
|
-
expect(eventType).toBe('release');
|
|
819
|
-
});
|
|
820
|
-
|
|
821
|
-
it('should handle sender with missing login', () => {
|
|
822
|
-
const payload = {
|
|
823
|
-
ref: 'refs/heads/main',
|
|
824
|
-
sender: {
|
|
825
|
-
type: 'Bot'
|
|
826
|
-
},
|
|
827
|
-
repository: {
|
|
828
|
-
id: 1,
|
|
829
|
-
name: 'repo',
|
|
830
|
-
full_name: 'user/repo',
|
|
831
|
-
owner: { login: 'user', type: 'User' },
|
|
832
|
-
default_branch: 'main',
|
|
833
|
-
html_url: 'https://github.com/user/repo',
|
|
834
|
-
private: false
|
|
835
|
-
},
|
|
836
|
-
commits: []
|
|
837
|
-
};
|
|
838
|
-
|
|
839
|
-
const result = parser.parse(payload);
|
|
840
|
-
expect(result.sender?.login).toBe('');
|
|
841
|
-
});
|
|
842
|
-
|
|
843
|
-
it('should handle sender with missing type', () => {
|
|
844
|
-
const payload = {
|
|
845
|
-
ref: 'refs/heads/main',
|
|
846
|
-
sender: {
|
|
847
|
-
login: 'bot-user'
|
|
848
|
-
},
|
|
849
|
-
repository: {
|
|
850
|
-
id: 1,
|
|
851
|
-
name: 'repo',
|
|
852
|
-
full_name: 'user/repo',
|
|
853
|
-
owner: { login: 'user', type: 'User' },
|
|
854
|
-
default_branch: 'main',
|
|
855
|
-
html_url: 'https://github.com/user/repo',
|
|
856
|
-
private: false
|
|
857
|
-
},
|
|
858
|
-
commits: []
|
|
859
|
-
};
|
|
860
|
-
|
|
861
|
-
const result = parser.parse(payload);
|
|
862
|
-
expect(result.sender?.type).toBe('User');
|
|
863
|
-
});
|
|
864
|
-
});
|
|
865
|
-
|