@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/jest.config.cjs DELETED
@@ -1,30 +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
- module.exports = {
10
- preset: 'ts-jest',
11
- testEnvironment: '<rootDir>/../../../jest-environment-node-fixed.cjs',
12
- roots: ['<rootDir>/__tests__'],
13
- testMatch: ['**/*.test.ts'],
14
- collectCoverageFrom: [
15
- 'src/**/*.ts',
16
- '!src/**/*.d.ts',
17
- '!src/index.ts'
18
- ],
19
- coverageThreshold: {
20
- global: {
21
- branches: 90,
22
- functions: 90,
23
- lines: 90,
24
- statements: 90
25
- }
26
- },
27
- coverageDirectory: 'coverage',
28
- verbose: true
29
- };
30
-
@@ -1,213 +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 { createLogger } from '@bernierllc/logger';
10
- import type {
11
- GitHubWebhookPayload,
12
- ParsedWebhookEvent,
13
- ParsedCommit,
14
- ParsedRepository
15
- } from './types';
16
-
17
- const logger = createLogger();
18
-
19
- /**
20
- * GitHub webhook payload parser
21
- */
22
- export class GitHubParser {
23
- /**
24
- * Parse GitHub webhook payload
25
- */
26
- parse(payload: GitHubWebhookPayload): ParsedWebhookEvent {
27
- const eventType = this.normalizeEventType(payload);
28
- const repository = this.extractRepository(payload);
29
-
30
- const parsed: ParsedWebhookEvent = {
31
- type: eventType,
32
- repository,
33
- action: this.extractAction(payload),
34
- branch: this.extractBranch(payload),
35
- ref: this.extractRef(payload),
36
- sender: this.extractSender(payload)
37
- };
38
-
39
- // Extract commits based on event type
40
- if (eventType === 'push') {
41
- parsed.commits = this.extractCommits(payload);
42
- } else {
43
- const commit = this.extractCommit(payload);
44
- if (commit) {
45
- parsed.commit = commit;
46
- }
47
- }
48
-
49
- logger.debug('Parsed GitHub webhook', { eventType, repository: repository.fullName });
50
-
51
- return parsed;
52
- }
53
-
54
- /**
55
- * Extract commits from push webhook
56
- */
57
- extractCommits(payload: GitHubWebhookPayload): ParsedCommit[] {
58
- const commits = (payload.commits as unknown[]) || [];
59
- return commits.map((commit: unknown) => this.parseCommit(commit as Record<string, unknown>));
60
- }
61
-
62
- /**
63
- * Extract single commit
64
- */
65
- extractCommit(payload: GitHubWebhookPayload): ParsedCommit | null {
66
- const commit = payload.commit as Record<string, unknown> | undefined;
67
- if (!commit) {
68
- return null;
69
- }
70
- return this.parseCommit(commit);
71
- }
72
-
73
- /**
74
- * Parse commit object
75
- */
76
- private parseCommit(commit: Record<string, unknown>): ParsedCommit {
77
- const author = commit.author as Record<string, unknown> | undefined;
78
- const committer = commit.committer as Record<string, unknown> | undefined;
79
-
80
- // Parse additions and deletions - can be arrays or numbers
81
- let additions = 0;
82
- let deletions = 0;
83
-
84
- if (Array.isArray(commit.added)) {
85
- additions = commit.added.length;
86
- } else if (typeof commit.additions === 'number') {
87
- additions = commit.additions;
88
- }
89
-
90
- if (Array.isArray(commit.removed)) {
91
- deletions = commit.removed.length;
92
- } else if (typeof commit.deletions === 'number') {
93
- deletions = commit.deletions;
94
- }
95
-
96
- return {
97
- sha: String(commit.sha || commit.id || ''),
98
- message: String(commit.message || ''),
99
- author: {
100
- name: String(author?.name || committer?.name || ''),
101
- email: String(author?.email || committer?.email || ''),
102
- username: author?.username ? String(author.username) : undefined
103
- },
104
- timestamp: commit.timestamp
105
- ? new Date(String(commit.timestamp))
106
- : new Date(),
107
- url: String(commit.url || ''),
108
- additions,
109
- deletions,
110
- files: (commit.modified as string[]) || []
111
- };
112
- }
113
-
114
- /**
115
- * Extract repository information
116
- */
117
- extractRepository(payload: GitHubWebhookPayload): ParsedRepository {
118
- const repo = payload.repository as Record<string, unknown> | undefined;
119
- if (!repo) {
120
- throw new Error('Repository information not found in payload');
121
- }
122
-
123
- const owner = repo.owner as Record<string, unknown> | undefined;
124
-
125
- return {
126
- id: Number(repo.id || 0),
127
- name: String(repo.name || ''),
128
- fullName: String(repo.full_name || repo.fullName || ''),
129
- owner: {
130
- login: String(owner?.login || ''),
131
- type: String(owner?.type || 'User')
132
- },
133
- defaultBranch: String(repo.default_branch || repo.defaultBranch || 'main'),
134
- url: String(repo.html_url || repo.htmlUrl || repo.url || ''),
135
- private: Boolean(repo.private)
136
- };
137
- }
138
-
139
- /**
140
- * Normalize event type
141
- */
142
- normalizeEventType(payload: GitHubWebhookPayload): string {
143
- // Check X-GitHub-Event header or payload field
144
- const eventType = (payload['X-GitHub-Event'] as string) ||
145
- (payload.action as string) ||
146
- (payload.type as string);
147
-
148
- // If we have an explicit event type, normalize it
149
- if (eventType) {
150
- if (eventType.includes('push')) return 'push';
151
- if (eventType.includes('pull_request')) return 'pull_request';
152
- if (eventType.includes('issue')) return 'issues';
153
- if (eventType.includes('release')) return 'release';
154
- return eventType.toLowerCase();
155
- }
156
-
157
- // Infer event type from payload structure
158
- if (payload.ref && typeof payload.ref === 'string' && payload.ref.startsWith('refs/heads/')) {
159
- return 'push';
160
- }
161
- if (payload.pull_request) {
162
- return 'pull_request';
163
- }
164
- if (payload.issue) {
165
- return 'issues';
166
- }
167
- if (payload.release) {
168
- return 'release';
169
- }
170
-
171
- return 'unknown';
172
- }
173
-
174
- /**
175
- * Extract action (for pull_request, issues, etc.)
176
- */
177
- private extractAction(payload: GitHubWebhookPayload): string | undefined {
178
- return payload.action as string | undefined;
179
- }
180
-
181
- /**
182
- * Extract branch name
183
- */
184
- private extractBranch(payload: GitHubWebhookPayload): string | undefined {
185
- const ref = this.extractRef(payload);
186
- if (!ref) return undefined;
187
-
188
- // Extract branch from ref (e.g., "refs/heads/main" -> "main")
189
- const match = ref.match(/^refs\/heads\/(.+)$/);
190
- return match ? match[1] : ref;
191
- }
192
-
193
- /**
194
- * Extract git ref
195
- */
196
- private extractRef(payload: GitHubWebhookPayload): string | undefined {
197
- return (payload.ref as string) || undefined;
198
- }
199
-
200
- /**
201
- * Extract sender information
202
- */
203
- private extractSender(payload: GitHubWebhookPayload): { login: string; type: string } | undefined {
204
- const sender = payload.sender as Record<string, unknown> | undefined;
205
- if (!sender) return undefined;
206
-
207
- return {
208
- login: String(sender.login || ''),
209
- type: String(sender.type || 'User')
210
- };
211
- }
212
- }
213
-
package/src/index.ts DELETED
@@ -1,16 +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
- export { GitHubParser } from './github-parser';
10
- export type {
11
- GitHubWebhookPayload,
12
- ParsedWebhookEvent,
13
- ParsedCommit,
14
- ParsedRepository
15
- } from './types';
16
-
package/src/types.ts DELETED
@@ -1,89 +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
- /**
10
- * Raw GitHub webhook payload
11
- */
12
- export interface GitHubWebhookPayload {
13
- [key: string]: unknown;
14
- }
15
-
16
- /**
17
- * Parsed commit information
18
- */
19
- export interface ParsedCommit {
20
- /** Commit SHA */
21
- sha: string;
22
- /** Commit message */
23
- message: string;
24
- /** Commit author */
25
- author: {
26
- name: string;
27
- email: string;
28
- username?: string;
29
- };
30
- /** Commit timestamp */
31
- timestamp: Date;
32
- /** Commit URL */
33
- url: string;
34
- /** Lines added */
35
- additions: number;
36
- /** Lines deleted */
37
- deletions: number;
38
- /** Files changed */
39
- files: string[];
40
- }
41
-
42
- /**
43
- * Parsed repository information
44
- */
45
- export interface ParsedRepository {
46
- /** Repository ID */
47
- id: number;
48
- /** Repository name */
49
- name: string;
50
- /** Full repository name (owner/repo) */
51
- fullName: string;
52
- /** Repository owner */
53
- owner: {
54
- login: string;
55
- type: string;
56
- };
57
- /** Default branch */
58
- defaultBranch: string;
59
- /** Repository URL */
60
- url: string;
61
- /** Whether repository is private */
62
- private: boolean;
63
- }
64
-
65
- /**
66
- * Parsed webhook event
67
- */
68
- export interface ParsedWebhookEvent {
69
- /** Event type */
70
- type: 'push' | 'pull_request' | 'issues' | 'release' | string;
71
- /** Event action (for pull_request, issues, etc.) */
72
- action?: string;
73
- /** Repository information */
74
- repository: ParsedRepository;
75
- /** Commits (for push events) */
76
- commits?: ParsedCommit[];
77
- /** Single commit (for some events) */
78
- commit?: ParsedCommit;
79
- /** Branch name */
80
- branch?: string;
81
- /** Git ref */
82
- ref?: string;
83
- /** Event sender */
84
- sender?: {
85
- login: string;
86
- type: string;
87
- };
88
- }
89
-
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "ES2020",
4
- "module": "commonjs",
5
- "lib": ["ES2020"],
6
- "declaration": true,
7
- "outDir": "./dist",
8
- "rootDir": "./src",
9
- "strict": true,
10
- "esModuleInterop": true,
11
- "skipLibCheck": true,
12
- "forceConsistentCasingInFileNames": true,
13
- "moduleResolution": "node",
14
- "resolveJsonModule": true,
15
- "noUnusedLocals": true,
16
- "noUnusedParameters": true,
17
- "noImplicitReturns": true,
18
- "noFallthroughCasesInSwitch": true
19
- },
20
- "include": ["src/**/*"],
21
- "exclude": ["node_modules", "dist", "__tests__"]
22
- }
23
-