@bernierllc/github-parser 1.5.0 → 1.5.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bernierllc/github-parser",
3
- "version": "1.5.0",
3
+ "version": "1.5.2",
4
4
  "description": "GitHub webhook payload parser and transformer",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -18,7 +18,7 @@
18
18
  "author": "Bernier LLC",
19
19
  "license": "SEE LICENSE IN LICENSE",
20
20
  "dependencies": {
21
- "@bernierllc/logger": "1.7.0"
21
+ "@bernierllc/logger": "2.0.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/jest": "^29.5.0",
package/dist/errors.d.ts DELETED
@@ -1,11 +0,0 @@
1
- export type GithubParserErrorCode = 'GITHUB_PARSER_ERROR' | 'INVALID_INPUT' | 'OPERATION_FAILED';
2
- export interface GithubParserErrorOptions {
3
- cause?: Error;
4
- code?: GithubParserErrorCode;
5
- context?: Record<string, unknown>;
6
- }
7
- export declare class GithubParserError extends Error {
8
- readonly code: GithubParserErrorCode;
9
- readonly context?: Record<string, unknown>;
10
- constructor(message: string, options?: GithubParserErrorOptions);
11
- }
package/dist/errors.js DELETED
@@ -1,24 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code only within the scope of the project it was delivered for.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.GithubParserError = void 0;
11
- class GithubParserError extends Error {
12
- code;
13
- context;
14
- constructor(message, options) {
15
- super(message, options?.cause ? { cause: options.cause } : undefined);
16
- this.name = 'GithubParserError';
17
- this.code = options?.code ?? 'GITHUB_PARSER_ERROR';
18
- if (options?.context !== undefined) {
19
- this.context = options.context;
20
- }
21
- Error.captureStackTrace?.(this, this.constructor);
22
- }
23
- }
24
- exports.GithubParserError = GithubParserError;
@@ -1,46 +0,0 @@
1
- import type { GitHubWebhookPayload, ParsedWebhookEvent, ParsedCommit, ParsedRepository } from './types';
2
- /**
3
- * GitHub webhook payload parser
4
- */
5
- export declare class GitHubParser {
6
- /**
7
- * Parse GitHub webhook payload
8
- */
9
- parse(payload: GitHubWebhookPayload): ParsedWebhookEvent;
10
- /**
11
- * Extract commits from push webhook
12
- */
13
- extractCommits(payload: GitHubWebhookPayload): ParsedCommit[];
14
- /**
15
- * Extract single commit
16
- */
17
- extractCommit(payload: GitHubWebhookPayload): ParsedCommit | null;
18
- /**
19
- * Parse commit object
20
- */
21
- private parseCommit;
22
- /**
23
- * Extract repository information
24
- */
25
- extractRepository(payload: GitHubWebhookPayload): ParsedRepository;
26
- /**
27
- * Normalize event type
28
- */
29
- normalizeEventType(payload: GitHubWebhookPayload): string;
30
- /**
31
- * Extract action (for pull_request, issues, etc.)
32
- */
33
- private extractAction;
34
- /**
35
- * Extract branch name
36
- */
37
- private extractBranch;
38
- /**
39
- * Extract git ref
40
- */
41
- private extractRef;
42
- /**
43
- * Extract sender information
44
- */
45
- private extractSender;
46
- }
@@ -1,192 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code *only within the scope of the project it was delivered for*.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.GitHubParser = void 0;
11
- const logger_1 = require("@bernierllc/logger");
12
- const logger = (0, logger_1.createLogger)();
13
- /**
14
- * GitHub webhook payload parser
15
- */
16
- class GitHubParser {
17
- /**
18
- * Parse GitHub webhook payload
19
- */
20
- parse(payload) {
21
- const eventType = this.normalizeEventType(payload);
22
- const repository = this.extractRepository(payload);
23
- const parsed = {
24
- type: eventType,
25
- repository,
26
- action: this.extractAction(payload),
27
- branch: this.extractBranch(payload),
28
- ref: this.extractRef(payload),
29
- sender: this.extractSender(payload)
30
- };
31
- // Extract commits based on event type
32
- if (eventType === 'push') {
33
- parsed.commits = this.extractCommits(payload);
34
- }
35
- else {
36
- const commit = this.extractCommit(payload);
37
- if (commit) {
38
- parsed.commit = commit;
39
- }
40
- }
41
- logger.debug('Parsed GitHub webhook', { eventType, repository: repository.fullName });
42
- return parsed;
43
- }
44
- /**
45
- * Extract commits from push webhook
46
- */
47
- extractCommits(payload) {
48
- const commits = payload.commits || [];
49
- return commits.map((commit) => this.parseCommit(commit));
50
- }
51
- /**
52
- * Extract single commit
53
- */
54
- extractCommit(payload) {
55
- const commit = payload.commit;
56
- if (!commit) {
57
- return null;
58
- }
59
- return this.parseCommit(commit);
60
- }
61
- /**
62
- * Parse commit object
63
- */
64
- parseCommit(commit) {
65
- const author = commit.author;
66
- const committer = commit.committer;
67
- // Parse additions and deletions - can be arrays or numbers
68
- let additions = 0;
69
- let deletions = 0;
70
- if (Array.isArray(commit.added)) {
71
- additions = commit.added.length;
72
- }
73
- else if (typeof commit.additions === 'number') {
74
- additions = commit.additions;
75
- }
76
- if (Array.isArray(commit.removed)) {
77
- deletions = commit.removed.length;
78
- }
79
- else if (typeof commit.deletions === 'number') {
80
- deletions = commit.deletions;
81
- }
82
- return {
83
- sha: String(commit.sha || commit.id || ''),
84
- message: String(commit.message || ''),
85
- author: {
86
- name: String(author?.name || committer?.name || ''),
87
- email: String(author?.email || committer?.email || ''),
88
- username: author?.username ? String(author.username) : undefined
89
- },
90
- timestamp: commit.timestamp
91
- ? new Date(String(commit.timestamp))
92
- : new Date(),
93
- url: String(commit.url || ''),
94
- additions,
95
- deletions,
96
- files: commit.modified || []
97
- };
98
- }
99
- /**
100
- * Extract repository information
101
- */
102
- extractRepository(payload) {
103
- const repo = payload.repository;
104
- if (!repo) {
105
- throw new Error('Repository information not found in payload');
106
- }
107
- const owner = repo.owner;
108
- return {
109
- id: Number(repo.id || 0),
110
- name: String(repo.name || ''),
111
- fullName: String(repo.full_name || repo.fullName || ''),
112
- owner: {
113
- login: String(owner?.login || ''),
114
- type: String(owner?.type || 'User')
115
- },
116
- defaultBranch: String(repo.default_branch || repo.defaultBranch || 'main'),
117
- url: String(repo.html_url || repo.htmlUrl || repo.url || ''),
118
- private: Boolean(repo.private)
119
- };
120
- }
121
- /**
122
- * Normalize event type
123
- */
124
- normalizeEventType(payload) {
125
- // Check X-GitHub-Event header or payload field
126
- const eventType = payload['X-GitHub-Event'] ||
127
- payload.action ||
128
- payload.type;
129
- // If we have an explicit event type, normalize it
130
- if (eventType) {
131
- if (eventType.includes('push'))
132
- return 'push';
133
- if (eventType.includes('pull_request'))
134
- return 'pull_request';
135
- if (eventType.includes('issue'))
136
- return 'issues';
137
- if (eventType.includes('release'))
138
- return 'release';
139
- return eventType.toLowerCase();
140
- }
141
- // Infer event type from payload structure
142
- if (payload.ref && typeof payload.ref === 'string' && payload.ref.startsWith('refs/heads/')) {
143
- return 'push';
144
- }
145
- if (payload.pull_request) {
146
- return 'pull_request';
147
- }
148
- if (payload.issue) {
149
- return 'issues';
150
- }
151
- if (payload.release) {
152
- return 'release';
153
- }
154
- return 'unknown';
155
- }
156
- /**
157
- * Extract action (for pull_request, issues, etc.)
158
- */
159
- extractAction(payload) {
160
- return payload.action;
161
- }
162
- /**
163
- * Extract branch name
164
- */
165
- extractBranch(payload) {
166
- const ref = this.extractRef(payload);
167
- if (!ref)
168
- return undefined;
169
- // Extract branch from ref (e.g., "refs/heads/main" -> "main")
170
- const match = ref.match(/^refs\/heads\/(.+)$/);
171
- return match ? match[1] : ref;
172
- }
173
- /**
174
- * Extract git ref
175
- */
176
- extractRef(payload) {
177
- return payload.ref || undefined;
178
- }
179
- /**
180
- * Extract sender information
181
- */
182
- extractSender(payload) {
183
- const sender = payload.sender;
184
- if (!sender)
185
- return undefined;
186
- return {
187
- login: String(sender.login || ''),
188
- type: String(sender.type || 'User')
189
- };
190
- }
191
- }
192
- exports.GitHubParser = GitHubParser;
package/dist/index.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export { GitHubParser } from './github-parser';
2
- export type { GitHubWebhookPayload, ParsedWebhookEvent, ParsedCommit, ParsedRepository } from './types';
3
- export { GithubParserError, type GithubParserErrorCode, type GithubParserErrorOptions } from './errors';
package/dist/index.js DELETED
@@ -1,14 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code *only within the scope of the project it was delivered for*.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.GithubParserError = exports.GitHubParser = void 0;
11
- var github_parser_1 = require("./github-parser");
12
- Object.defineProperty(exports, "GitHubParser", { enumerable: true, get: function () { return github_parser_1.GitHubParser; } });
13
- var errors_1 = require("./errors");
14
- Object.defineProperty(exports, "GithubParserError", { enumerable: true, get: function () { return errors_1.GithubParserError; } });
package/dist/types.d.ts DELETED
@@ -1,77 +0,0 @@
1
- /**
2
- * Raw GitHub webhook payload
3
- */
4
- export interface GitHubWebhookPayload {
5
- [key: string]: unknown;
6
- }
7
- /**
8
- * Parsed commit information
9
- */
10
- export interface ParsedCommit {
11
- /** Commit SHA */
12
- sha: string;
13
- /** Commit message */
14
- message: string;
15
- /** Commit author */
16
- author: {
17
- name: string;
18
- email: string;
19
- username?: string;
20
- };
21
- /** Commit timestamp */
22
- timestamp: Date;
23
- /** Commit URL */
24
- url: string;
25
- /** Lines added */
26
- additions: number;
27
- /** Lines deleted */
28
- deletions: number;
29
- /** Files changed */
30
- files: string[];
31
- }
32
- /**
33
- * Parsed repository information
34
- */
35
- export interface ParsedRepository {
36
- /** Repository ID */
37
- id: number;
38
- /** Repository name */
39
- name: string;
40
- /** Full repository name (owner/repo) */
41
- fullName: string;
42
- /** Repository owner */
43
- owner: {
44
- login: string;
45
- type: string;
46
- };
47
- /** Default branch */
48
- defaultBranch: string;
49
- /** Repository URL */
50
- url: string;
51
- /** Whether repository is private */
52
- private: boolean;
53
- }
54
- /**
55
- * Parsed webhook event
56
- */
57
- export interface ParsedWebhookEvent {
58
- /** Event type */
59
- type: 'push' | 'pull_request' | 'issues' | 'release' | string;
60
- /** Event action (for pull_request, issues, etc.) */
61
- action?: string;
62
- /** Repository information */
63
- repository: ParsedRepository;
64
- /** Commits (for push events) */
65
- commits?: ParsedCommit[];
66
- /** Single commit (for some events) */
67
- commit?: ParsedCommit;
68
- /** Branch name */
69
- branch?: string;
70
- /** Git ref */
71
- ref?: string;
72
- /** Event sender */
73
- sender?: {
74
- login: string;
75
- type: string;
76
- };
77
- }
package/dist/types.js DELETED
@@ -1,9 +0,0 @@
1
- "use strict";
2
- /*
3
- Copyright (c) 2025 Bernier LLC
4
-
5
- This file is licensed to the client under a limited-use license.
6
- The client may use and modify this code *only within the scope of the project it was delivered for*.
7
- Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
8
- */
9
- Object.defineProperty(exports, "__esModule", { value: true });