@bernierllc/github-parser 1.0.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/.eslintrc.cjs ADDED
@@ -0,0 +1,33 @@
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
+ parser: '@typescript-eslint/parser',
11
+ extends: [
12
+ 'eslint:recommended',
13
+ 'plugin:@typescript-eslint/recommended'
14
+ ],
15
+ plugins: ['@typescript-eslint'],
16
+ parserOptions: {
17
+ ecmaVersion: 2020,
18
+ sourceType: 'module',
19
+ project: './tsconfig.json'
20
+ },
21
+ env: {
22
+ node: true,
23
+ es6: true
24
+ },
25
+ rules: {
26
+ '@typescript-eslint/explicit-function-return-type': 'off',
27
+ '@typescript-eslint/no-explicit-any': 'error',
28
+ '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }],
29
+ '@typescript-eslint/no-non-null-assertion': 'warn'
30
+ },
31
+ ignorePatterns: ['dist/', 'node_modules/', '*.cjs']
32
+ };
33
+
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Bernier LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,148 @@
1
+ # @bernierllc/github-parser
2
+
3
+ GitHub webhook payload parser and transformer
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @bernierllc/github-parser
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - **Webhook parsing** - Parse all GitHub webhook event types
14
+ - **Commit extraction** - Extract commit information from push events
15
+ - **Repository metadata** - Extract repository details
16
+ - **Event normalization** - Normalize different payload structures
17
+ - **Type-safe** - Full TypeScript support with interfaces
18
+ - **Framework agnostic** - Pure parsing logic
19
+
20
+ ## Usage
21
+
22
+ ### Basic Usage
23
+
24
+ ```typescript
25
+ import { GitHubParser } from '@bernierllc/github-parser';
26
+
27
+ const parser = new GitHubParser();
28
+
29
+ // Parse webhook payload
30
+ const event = parser.parse(webhookPayload);
31
+
32
+ console.log('Event type:', event.type);
33
+ console.log('Repository:', event.repository.fullName);
34
+ console.log('Commits:', event.commits);
35
+ ```
36
+
37
+ ### Parse Push Webhook
38
+
39
+ ```typescript
40
+ const payload = {
41
+ ref: 'refs/heads/main',
42
+ repository: { /* ... */ },
43
+ commits: [
44
+ {
45
+ id: 'abc123',
46
+ message: 'Add feature',
47
+ author: { name: 'Developer', email: 'dev@example.com' },
48
+ // ...
49
+ }
50
+ ]
51
+ };
52
+
53
+ const event = parser.parse(payload);
54
+ console.log('Branch:', event.branch); // 'main'
55
+ console.log('Commits:', event.commits?.length);
56
+ ```
57
+
58
+ ### Extract Commits
59
+
60
+ ```typescript
61
+ const commits = parser.extractCommits(payload);
62
+ commits.forEach(commit => {
63
+ console.log('SHA:', commit.sha);
64
+ console.log('Message:', commit.message);
65
+ console.log('Files:', commit.files);
66
+ console.log('Additions:', commit.additions);
67
+ console.log('Deletions:', commit.deletions);
68
+ });
69
+ ```
70
+
71
+ ### Extract Repository
72
+
73
+ ```typescript
74
+ const repo = parser.extractRepository(payload);
75
+ console.log('Name:', repo.name);
76
+ console.log('Full name:', repo.fullName);
77
+ console.log('Owner:', repo.owner.login);
78
+ console.log('Private:', repo.private);
79
+ ```
80
+
81
+ ### Extract Single Commit
82
+
83
+ ```typescript
84
+ const commit = parser.extractCommit(payload);
85
+ if (commit) {
86
+ console.log('Commit SHA:', commit.sha);
87
+ console.log('Author:', commit.author.name);
88
+ }
89
+ ```
90
+
91
+ ## API
92
+
93
+ ### `new GitHubParser()`
94
+
95
+ Creates a new GitHub parser instance.
96
+
97
+ ### `parser.parse(payload: GitHubWebhookPayload): ParsedWebhookEvent`
98
+
99
+ Parses a GitHub webhook payload into a normalized event structure.
100
+
101
+ ### `parser.extractCommits(payload: GitHubWebhookPayload): ParsedCommit[]`
102
+
103
+ Extracts all commits from a push webhook payload.
104
+
105
+ ### `parser.extractCommit(payload: GitHubWebhookPayload): ParsedCommit | null`
106
+
107
+ Extracts a single commit from a webhook payload.
108
+
109
+ ### `parser.extractRepository(payload: GitHubWebhookPayload): ParsedRepository`
110
+
111
+ Extracts repository information from a webhook payload.
112
+
113
+ ### `parser.normalizeEventType(payload: GitHubWebhookPayload): string`
114
+
115
+ Normalizes the event type from a webhook payload.
116
+
117
+ ## Integration Status
118
+
119
+ ### Logger Integration
120
+ **Status**: ✅ Integrated
121
+
122
+ Uses `@bernierllc/logger` for parsing events, errors, and webhook processing.
123
+
124
+ ### NeverHub Integration
125
+ **Status**: ⚠️ Optional
126
+
127
+ Can emit parsing events to NeverHub for distributed monitoring and observability. GitHub parser can publish events like `github.webhook.parsed`, `github.commit.extracted`, and `github.repository.extracted` to NeverHub when available.
128
+
129
+ **Pattern**: Optional service discovery integration - package can emit parsing events to NeverHub for distributed monitoring.
130
+
131
+ **Example Integration**:
132
+ ```typescript
133
+ // If NeverHub is available, emit events
134
+ if (typeof detectNeverHub === 'function') {
135
+ const event = parser.parse(payload);
136
+ neverhub.emit('github-parser.webhook.parsed', event);
137
+ }
138
+ ```
139
+
140
+ ### Docs-Suite Integration
141
+ **Status**: ✅ Ready
142
+
143
+ TypeDoc-compatible JSDoc comments are included throughout the source code. All public APIs are documented with examples and type information.
144
+
145
+ ## License
146
+
147
+ Copyright (c) 2025 Bernier LLC. All rights reserved.
148
+