@devrev/git-sdk 0.11.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/README.md +2 -0
- package/dist/adapter/adapter.d.ts +9 -0
- package/dist/adapter/adapter.js +3 -0
- package/dist/adapter/adapter.js.map +1 -0
- package/dist/config/create-config.d.ts +34 -0
- package/dist/config/create-config.js +33 -0
- package/dist/config/create-config.js.map +1 -0
- package/dist/config/index.d.ts +4 -0
- package/dist/config/index.js +9 -0
- package/dist/config/index.js.map +1 -0
- package/dist/devrev/client.d.ts +104 -0
- package/dist/devrev/client.js +113 -0
- package/dist/devrev/client.js.map +1 -0
- package/dist/devrev/http.d.ts +42 -0
- package/dist/devrev/http.js +105 -0
- package/dist/devrev/http.js.map +1 -0
- package/dist/devrev/index.d.ts +7 -0
- package/dist/devrev/index.js +43 -0
- package/dist/devrev/index.js.map +1 -0
- package/dist/devrev/managers/code_change_manager.d.ts +48 -0
- package/dist/devrev/managers/code_change_manager.js +227 -0
- package/dist/devrev/managers/code_change_manager.js.map +1 -0
- package/dist/devrev/managers/code_change_schema.d.ts +12 -0
- package/dist/devrev/managers/code_change_schema.js +317 -0
- package/dist/devrev/managers/code_change_schema.js.map +1 -0
- package/dist/devrev/managers/custom_link_type_manager.d.ts +33 -0
- package/dist/devrev/managers/custom_link_type_manager.js +94 -0
- package/dist/devrev/managers/custom_link_type_manager.js.map +1 -0
- package/dist/devrev/managers/dev_user_manager.d.ts +53 -0
- package/dist/devrev/managers/dev_user_manager.js +155 -0
- package/dist/devrev/managers/dev_user_manager.js.map +1 -0
- package/dist/devrev/managers/index.d.ts +9 -0
- package/dist/devrev/managers/index.js +20 -0
- package/dist/devrev/managers/index.js.map +1 -0
- package/dist/devrev/managers/link_manager.d.ts +41 -0
- package/dist/devrev/managers/link_manager.js +111 -0
- package/dist/devrev/managers/link_manager.js.map +1 -0
- package/dist/devrev/managers/tenant_fragment_manager.d.ts +26 -0
- package/dist/devrev/managers/tenant_fragment_manager.js +68 -0
- package/dist/devrev/managers/tenant_fragment_manager.js.map +1 -0
- package/dist/devrev/managers/timeline_manager.d.ts +86 -0
- package/dist/devrev/managers/timeline_manager.js +184 -0
- package/dist/devrev/managers/timeline_manager.js.map +1 -0
- package/dist/devrev/types.d.ts +139 -0
- package/dist/devrev/types.js +127 -0
- package/dist/devrev/types.js.map +1 -0
- package/dist/handlers/commit_push_handler.d.ts +31 -0
- package/dist/handlers/commit_push_handler.js +145 -0
- package/dist/handlers/commit_push_handler.js.map +1 -0
- package/dist/handlers/helpers.d.ts +87 -0
- package/dist/handlers/helpers.js +201 -0
- package/dist/handlers/helpers.js.map +1 -0
- package/dist/handlers/index.d.ts +12 -0
- package/dist/handlers/index.js +26 -0
- package/dist/handlers/index.js.map +1 -0
- package/dist/handlers/pr_create_handler.d.ts +36 -0
- package/dist/handlers/pr_create_handler.js +121 -0
- package/dist/handlers/pr_create_handler.js.map +1 -0
- package/dist/handlers/pr_merge_handler.d.ts +29 -0
- package/dist/handlers/pr_merge_handler.js +86 -0
- package/dist/handlers/pr_merge_handler.js.map +1 -0
- package/dist/handlers/pr_review_handler.d.ts +30 -0
- package/dist/handlers/pr_review_handler.js +109 -0
- package/dist/handlers/pr_review_handler.js.map +1 -0
- package/dist/handlers/registry.d.ts +9 -0
- package/dist/handlers/registry.js +22 -0
- package/dist/handlers/registry.js.map +1 -0
- package/dist/handlers/types.d.ts +46 -0
- package/dist/handlers/types.js +6 -0
- package/dist/handlers/types.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +65 -0
- package/dist/index.js.map +1 -0
- package/dist/orchestrator/event_orchestrator.d.ts +99 -0
- package/dist/orchestrator/event_orchestrator.js +137 -0
- package/dist/orchestrator/event_orchestrator.js.map +1 -0
- package/dist/orchestrator/index.d.ts +7 -0
- package/dist/orchestrator/index.js +12 -0
- package/dist/orchestrator/index.js.map +1 -0
- package/dist/types/config.d.ts +22 -0
- package/dist/types/config.js +6 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/events.d.ts +50 -0
- package/dist/types/events.js +14 -0
- package/dist/types/events.js.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.js +24 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/provider.d.ts +20 -0
- package/dist/types/provider.js +14 -0
- package/dist/types/provider.js.map +1 -0
- package/dist/types/types.d.ts +48 -0
- package/dist/types/types.js +9 -0
- package/dist/types/types.js.map +1 -0
- package/package.json +61 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handler for pull request merge events.
|
|
3
|
+
*
|
|
4
|
+
* This module handles PR merge events, updating the code_change custom object
|
|
5
|
+
* with merged status, closed timestamp, target commit information, and
|
|
6
|
+
* lines of code metrics (lines added, lines deleted, files changed).
|
|
7
|
+
*/
|
|
8
|
+
import { NormalizedPullRequestMergeEvent } from '../types/events';
|
|
9
|
+
import { HandlerContext, HandlerResult } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Process a pull request merge event.
|
|
12
|
+
*
|
|
13
|
+
* This function handles the core business logic for updating code_change
|
|
14
|
+
* custom objects when a pull request is merged.
|
|
15
|
+
*
|
|
16
|
+
* The handler will:
|
|
17
|
+
* 1. Get or create the code_change for this PR (by URL)
|
|
18
|
+
* 2. Fetch diff stats (lines added, lines deleted, files changed) from the provider
|
|
19
|
+
* 3. Update the code_change with:
|
|
20
|
+
* - Status → MERGED
|
|
21
|
+
* - closed_at → merge timestamp
|
|
22
|
+
* - target_commits → merge commit SHA (when available)
|
|
23
|
+
* - lines_added, lines_deleted, files_changed → from diff stats
|
|
24
|
+
*
|
|
25
|
+
* @param input - The normalized PR merge event
|
|
26
|
+
* @param context - The handler context with DevRev client and adapter
|
|
27
|
+
* @returns Handler result indicating success or failure
|
|
28
|
+
*/
|
|
29
|
+
export declare function handlePRMerge(input: NormalizedPullRequestMergeEvent, context: HandlerContext): Promise<HandlerResult>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Handler for pull request merge events.
|
|
4
|
+
*
|
|
5
|
+
* This module handles PR merge events, updating the code_change custom object
|
|
6
|
+
* with merged status, closed timestamp, target commit information, and
|
|
7
|
+
* lines of code metrics (lines added, lines deleted, files changed).
|
|
8
|
+
*/
|
|
9
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
10
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
13
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
14
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
15
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.handlePRMerge = void 0;
|
|
20
|
+
const types_1 = require("../devrev/types");
|
|
21
|
+
const helpers_1 = require("./helpers");
|
|
22
|
+
// =============================================================================
|
|
23
|
+
// PR Merge Handler
|
|
24
|
+
// =============================================================================
|
|
25
|
+
/**
|
|
26
|
+
* Process a pull request merge event.
|
|
27
|
+
*
|
|
28
|
+
* This function handles the core business logic for updating code_change
|
|
29
|
+
* custom objects when a pull request is merged.
|
|
30
|
+
*
|
|
31
|
+
* The handler will:
|
|
32
|
+
* 1. Get or create the code_change for this PR (by URL)
|
|
33
|
+
* 2. Fetch diff stats (lines added, lines deleted, files changed) from the provider
|
|
34
|
+
* 3. Update the code_change with:
|
|
35
|
+
* - Status → MERGED
|
|
36
|
+
* - closed_at → merge timestamp
|
|
37
|
+
* - target_commits → merge commit SHA (when available)
|
|
38
|
+
* - lines_added, lines_deleted, files_changed → from diff stats
|
|
39
|
+
*
|
|
40
|
+
* @param input - The normalized PR merge event
|
|
41
|
+
* @param context - The handler context with DevRev client and adapter
|
|
42
|
+
* @returns Handler result indicating success or failure
|
|
43
|
+
*/
|
|
44
|
+
function handlePRMerge(input, context) {
|
|
45
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
const { pullRequest, repository, mergedAt, mergeCommitSha } = input;
|
|
47
|
+
const repoName = repository.name;
|
|
48
|
+
const { client, adapter } = context;
|
|
49
|
+
try {
|
|
50
|
+
// Get or create code_change for this PR
|
|
51
|
+
const { codeChange } = yield (0, helpers_1.getOrCreateCodeChangeForPR)(pullRequest, repoName, context);
|
|
52
|
+
// Fetch diff stats from the provider (lines added, deleted, files changed)
|
|
53
|
+
let diffStats;
|
|
54
|
+
try {
|
|
55
|
+
diffStats = yield adapter.getPullRequestDiffStats(pullRequest);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
console.log(`Warning: Could not fetch diff stats for PR #${pullRequest.number}: ${error}`);
|
|
59
|
+
}
|
|
60
|
+
// Build update request for merge
|
|
61
|
+
const updateRequest = Object.assign(Object.assign({ id: codeChange.id, status: types_1.CodeChangeStatus.MERGED, closed_at: mergedAt }, (mergeCommitSha && { target_commits: [mergeCommitSha] })), (diffStats && {
|
|
62
|
+
lines_added: diffStats.lines_added,
|
|
63
|
+
lines_deleted: diffStats.lines_deleted,
|
|
64
|
+
files_changed: diffStats.files_changed,
|
|
65
|
+
}));
|
|
66
|
+
yield client.codeChange.update(updateRequest, codeChange);
|
|
67
|
+
// Note: No separate timeline entry is created for merge events.
|
|
68
|
+
// The status change to MERGED generates a timeline entry automatically
|
|
69
|
+
// via the code_change status field change delta.
|
|
70
|
+
return {
|
|
71
|
+
data: Object.assign({ codeChangeId: codeChange.id, mergedAt, mergeCommitSha: mergeCommitSha || null }, (diffStats && {
|
|
72
|
+
linesAdded: diffStats.lines_added,
|
|
73
|
+
linesDeleted: diffStats.lines_deleted,
|
|
74
|
+
filesChanged: diffStats.files_changed,
|
|
75
|
+
})),
|
|
76
|
+
message: `Processed merge for PR #${pullRequest.number}`,
|
|
77
|
+
success: true,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
return (0, helpers_1.createPRHandlerErrorResult)('PR merge', pullRequest, error);
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
exports.handlePRMerge = handlePRMerge;
|
|
86
|
+
//# sourceMappingURL=pr_merge_handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pr_merge_handler.js","sourceRoot":"","sources":["../../src/handlers/pr_merge_handler.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;AAEH,2CAGyB;AAIzB,uCAAmF;AAGnF,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;GAkBG;AACH,SAAsB,aAAa,CACjC,KAAsC,EACtC,OAAuB;;QAEvB,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC;QACpE,MAAM,QAAQ,GAAG,UAAU,CAAC,IAAI,CAAC;QACjC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAEpC,IAAI;YACF,wCAAwC;YACxC,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,IAAA,oCAA0B,EACrD,WAAW,EACX,QAAQ,EACR,OAAO,CACR,CAAC;YAEF,2EAA2E;YAC3E,IAAI,SAA0C,CAAC;YAC/C,IAAI;gBACF,SAAS,GAAG,MAAM,OAAO,CAAC,uBAAuB,CAAC,WAAW,CAAC,CAAC;aAChE;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,CAAC,GAAG,CAAC,+CAA+C,WAAW,CAAC,MAAM,KAAK,KAAK,EAAE,CAAC,CAAC;aAC5F;YAED,iCAAiC;YACjC,MAAM,aAAa,iCACjB,EAAE,EAAE,UAAU,CAAC,EAAE,EACjB,MAAM,EAAE,wBAAgB,CAAC,MAAM,EAC/B,SAAS,EAAE,QAAQ,IAChB,CAAC,cAAc,IAAI,EAAE,cAAc,EAAE,CAAC,cAAc,CAAC,EAAE,CAAC,GACxD,CAAC,SAAS,IAAI;gBACf,WAAW,EAAE,SAAS,CAAC,WAAW;gBAClC,aAAa,EAAE,SAAS,CAAC,aAAa;gBACtC,aAAa,EAAE,SAAS,CAAC,aAAa;aACvC,CAAC,CACH,CAAC;YAEF,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;YAE1D,gEAAgE;YAChE,uEAAuE;YACvE,iDAAiD;YAEjD,OAAO;gBACL,IAAI,kBACF,YAAY,EAAE,UAAU,CAAC,EAAE,EAC3B,QAAQ,EACR,cAAc,EAAE,cAAc,IAAI,IAAI,IACnC,CAAC,SAAS,IAAI;oBACf,UAAU,EAAE,SAAS,CAAC,WAAW;oBACjC,YAAY,EAAE,SAAS,CAAC,aAAa;oBACrC,YAAY,EAAE,SAAS,CAAC,aAAa;iBACtC,CAAC,CACH;gBACD,OAAO,EAAE,2BAA2B,WAAW,CAAC,MAAM,EAAE;gBACxD,OAAO,EAAE,IAAI;aACd,CAAC;SACH;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,IAAA,oCAA0B,EAAC,UAAU,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;SACnE;IACH,CAAC;CAAA;AA5DD,sCA4DC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handler for pull request review events.
|
|
3
|
+
*
|
|
4
|
+
* This module handles PR review submissions (approval or changes requested),
|
|
5
|
+
* updating the code_change custom object with reviewer information, status
|
|
6
|
+
* changes, and review timestamps.
|
|
7
|
+
*/
|
|
8
|
+
import { NormalizedPRReviewEvent } from '../types/events';
|
|
9
|
+
import { HandlerContext, HandlerResult } from './types';
|
|
10
|
+
/**
|
|
11
|
+
* Process a pull request review event.
|
|
12
|
+
*
|
|
13
|
+
* This function handles the core business logic for updating code_change
|
|
14
|
+
* custom objects when a review is submitted on a pull request.
|
|
15
|
+
*
|
|
16
|
+
* The handler will:
|
|
17
|
+
* 1. Get or create the code_change for this PR (by URL)
|
|
18
|
+
* 2. Resolve the reviewer to a DevRev user ID
|
|
19
|
+
* 3. Update the code_change status based on review state:
|
|
20
|
+
* - APPROVED → status = APPROVED, update approved_by + reviewed_by
|
|
21
|
+
* - CHANGES_REQUESTED → status = CHANGES_REQUESTED, update reviewed_by
|
|
22
|
+
* 4. Update review timestamps (first_review_at, last_review_at, first_approved_at, last_approved_at)
|
|
23
|
+
* 5. Remove reviewer from requested_reviewers (they've submitted their review)
|
|
24
|
+
* 6. Create a timeline entry for the review event
|
|
25
|
+
*
|
|
26
|
+
* @param input - The normalized PR review event
|
|
27
|
+
* @param context - The handler context with DevRev client and adapter
|
|
28
|
+
* @returns Handler result indicating success or failure
|
|
29
|
+
*/
|
|
30
|
+
export declare function handlePRReview(input: NormalizedPRReviewEvent, context: HandlerContext): Promise<HandlerResult>;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Handler for pull request review events.
|
|
4
|
+
*
|
|
5
|
+
* This module handles PR review submissions (approval or changes requested),
|
|
6
|
+
* updating the code_change custom object with reviewer information, status
|
|
7
|
+
* changes, and review timestamps.
|
|
8
|
+
*/
|
|
9
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
10
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
11
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
12
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
13
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
14
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
15
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.handlePRReview = void 0;
|
|
20
|
+
const types_1 = require("../devrev/types");
|
|
21
|
+
const events_1 = require("../types/events");
|
|
22
|
+
const helpers_1 = require("./helpers");
|
|
23
|
+
// =============================================================================
|
|
24
|
+
// PR Review Handler
|
|
25
|
+
// =============================================================================
|
|
26
|
+
/**
|
|
27
|
+
* Process a pull request review event.
|
|
28
|
+
*
|
|
29
|
+
* This function handles the core business logic for updating code_change
|
|
30
|
+
* custom objects when a review is submitted on a pull request.
|
|
31
|
+
*
|
|
32
|
+
* The handler will:
|
|
33
|
+
* 1. Get or create the code_change for this PR (by URL)
|
|
34
|
+
* 2. Resolve the reviewer to a DevRev user ID
|
|
35
|
+
* 3. Update the code_change status based on review state:
|
|
36
|
+
* - APPROVED → status = APPROVED, update approved_by + reviewed_by
|
|
37
|
+
* - CHANGES_REQUESTED → status = CHANGES_REQUESTED, update reviewed_by
|
|
38
|
+
* 4. Update review timestamps (first_review_at, last_review_at, first_approved_at, last_approved_at)
|
|
39
|
+
* 5. Remove reviewer from requested_reviewers (they've submitted their review)
|
|
40
|
+
* 6. Create a timeline entry for the review event
|
|
41
|
+
*
|
|
42
|
+
* @param input - The normalized PR review event
|
|
43
|
+
* @param context - The handler context with DevRev client and adapter
|
|
44
|
+
* @returns Handler result indicating success or failure
|
|
45
|
+
*/
|
|
46
|
+
function handlePRReview(input, context) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
const { pullRequest, repository, state, reviewer, reviewedAt } = input;
|
|
49
|
+
const repoName = repository.name;
|
|
50
|
+
const { client } = context;
|
|
51
|
+
try {
|
|
52
|
+
// Get or create code_change for this PR
|
|
53
|
+
const { codeChange } = yield (0, helpers_1.getOrCreateCodeChangeForPR)(pullRequest, repoName, context);
|
|
54
|
+
// Resolve reviewer to DevRev user ID
|
|
55
|
+
const reviewerDevUserId = yield client.devUser.resolveByExternalId(reviewer.external_id, reviewer.email);
|
|
56
|
+
// Read existing custom fields from the code_change
|
|
57
|
+
const existingFirstReviewAt = (0, helpers_1.getCodeChangeCustomField)(codeChange, types_1.CodeChangeFields.FIRST_REVIEW_AT);
|
|
58
|
+
const existingFirstApprovedAt = (0, helpers_1.getCodeChangeCustomField)(codeChange, types_1.CodeChangeFields.FIRST_APPROVED_AT);
|
|
59
|
+
// Check if reviewer is already in reviewed_by / approved_by lists
|
|
60
|
+
const existingReviewedBy = (0, helpers_1.getCodeChangeCustomField)(codeChange, types_1.CodeChangeFields.REVIEWED_BY) || [];
|
|
61
|
+
const existingApprovedBy = (0, helpers_1.getCodeChangeCustomField)(codeChange, types_1.CodeChangeFields.APPROVED_BY) || [];
|
|
62
|
+
const isAlreadyReviewer = reviewerDevUserId != null && existingReviewedBy.includes(reviewerDevUserId);
|
|
63
|
+
const isAlreadyApprover = reviewerDevUserId != null && existingApprovedBy.includes(reviewerDevUserId);
|
|
64
|
+
// Build update request based on review state
|
|
65
|
+
const updateRequest = Object.assign(Object.assign(Object.assign({ id: codeChange.id,
|
|
66
|
+
// Always update last_review_at
|
|
67
|
+
last_review_at: reviewedAt }, (!existingFirstReviewAt && { first_review_at: reviewedAt })), (reviewerDevUserId && !isAlreadyReviewer && { add_reviewed_by: [reviewerDevUserId] })), (reviewerDevUserId && {
|
|
68
|
+
remove_requested_reviewer: [reviewerDevUserId],
|
|
69
|
+
}));
|
|
70
|
+
if (state === events_1.ReviewStateValues.APPROVED) {
|
|
71
|
+
updateRequest.status = types_1.CodeChangeStatus.APPROVED;
|
|
72
|
+
updateRequest.last_approved_at = reviewedAt;
|
|
73
|
+
// Set first_approved_at only if not already set
|
|
74
|
+
if (!existingFirstApprovedAt) {
|
|
75
|
+
updateRequest.first_approved_at = reviewedAt;
|
|
76
|
+
}
|
|
77
|
+
// Add to approved_by list only if not already present
|
|
78
|
+
if (reviewerDevUserId && !isAlreadyApprover) {
|
|
79
|
+
updateRequest.add_approved_by = [reviewerDevUserId];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else if (state === events_1.ReviewStateValues.CHANGES_REQUESTED) {
|
|
83
|
+
updateRequest.status = types_1.CodeChangeStatus.CHANGES_REQUESTED;
|
|
84
|
+
}
|
|
85
|
+
yield client.codeChange.update(updateRequest, codeChange);
|
|
86
|
+
// Create timeline entry for the review
|
|
87
|
+
// Prefer the resolved DevRev user identity; fall back to provider username
|
|
88
|
+
const reviewerName = reviewerDevUserId || reviewer.username || 'A reviewer';
|
|
89
|
+
const message = state === events_1.ReviewStateValues.APPROVED
|
|
90
|
+
? `${reviewerName} approved PR #${pullRequest.number}`
|
|
91
|
+
: `${reviewerName} requested changes on PR #${pullRequest.number}`;
|
|
92
|
+
yield (0, helpers_1.createPRTimelineEntry)(codeChange.id, pullRequest, repoName, reviewedAt, message, context);
|
|
93
|
+
return {
|
|
94
|
+
data: {
|
|
95
|
+
codeChangeId: codeChange.id,
|
|
96
|
+
reviewState: state,
|
|
97
|
+
reviewerDevUserId,
|
|
98
|
+
},
|
|
99
|
+
message: `Processed ${state.toLowerCase()} review for PR #${pullRequest.number}`,
|
|
100
|
+
success: true,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
return (0, helpers_1.createPRHandlerErrorResult)('PR review', pullRequest, error);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
exports.handlePRReview = handlePRReview;
|
|
109
|
+
//# sourceMappingURL=pr_review_handler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pr_review_handler.js","sourceRoot":"","sources":["../../src/handlers/pr_review_handler.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;;;;;;;;;;AAEH,2CAIyB;AACzB,4CAA6E;AAE7E,uCAKmB;AAGnB,gFAAgF;AAChF,oBAAoB;AACpB,gFAAg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BAAqB,EACzB,UAAU,CAAC,EAAE,EACb,WAAW,EACX,QAAQ,EACR,UAAU,EACV,OAAO,EACP,OAAO,CACR,CAAC;YAEF,OAAO;gBACL,IAAI,EAAE;oBACJ,YAAY,EAAE,UAAU,CAAC,EAAE;oBAC3B,WAAW,EAAE,KAAK;oBAClB,iBAAiB;iBAClB;gBACD,OAAO,EAAE,aAAa,KAAK,CAAC,WAAW,EAAE,mBAAmB,WAAW,CAAC,MAAM,EAAE;gBAChF,OAAO,EAAE,IAAI;aACd,CAAC;SACH;QAAC,OAAO,KAAK,EAAE;YACd,OAAO,IAAA,oCAA0B,EAAC,WAAW,EAAE,WAAW,EAAE,KAAK,CAAC,CAAC;SACpE;IACH,CAAC;CAAA;AAzGD,wCAyGC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default handler registry for the Git SDK.
|
|
3
|
+
*
|
|
4
|
+
* Maps each normalized event type to its corresponding handler function.
|
|
5
|
+
* `pull_request_edit` is intentionally not mapped — there is no dedicated
|
|
6
|
+
* handler for edit events yet.
|
|
7
|
+
*/
|
|
8
|
+
import { HandlerRegistry } from './types';
|
|
9
|
+
export declare const DEFAULT_HANDLER_REGISTRY: HandlerRegistry;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Default handler registry for the Git SDK.
|
|
4
|
+
*
|
|
5
|
+
* Maps each normalized event type to its corresponding handler function.
|
|
6
|
+
* `pull_request_edit` is intentionally not mapped — there is no dedicated
|
|
7
|
+
* handler for edit events yet.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.DEFAULT_HANDLER_REGISTRY = void 0;
|
|
11
|
+
const commit_push_handler_1 = require("./commit_push_handler");
|
|
12
|
+
const pr_create_handler_1 = require("./pr_create_handler");
|
|
13
|
+
const pr_review_handler_1 = require("./pr_review_handler");
|
|
14
|
+
const pr_merge_handler_1 = require("./pr_merge_handler");
|
|
15
|
+
exports.DEFAULT_HANDLER_REGISTRY = {
|
|
16
|
+
'push': commit_push_handler_1.handlePushEvent,
|
|
17
|
+
'pull_request_create': pr_create_handler_1.handlePRCreate,
|
|
18
|
+
'pull_request_close': pr_create_handler_1.handlePRClose,
|
|
19
|
+
'pull_request_review': pr_review_handler_1.handlePRReview,
|
|
20
|
+
'pull_request_merge': pr_merge_handler_1.handlePRMerge,
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/handlers/registry.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAEH,+DAAwD;AACxD,2DAAoE;AACpE,2DAAqD;AACrD,yDAAmD;AAGtC,QAAA,wBAAwB,GAAoB;IACvD,MAAM,EAAE,qCAA+B;IACvC,qBAAqB,EAAE,kCAA8B;IACrD,oBAAoB,EAAE,iCAA6B;IACnD,qBAAqB,EAAE,kCAA8B;IACrD,oBAAoB,EAAE,gCAA6B;CACpD,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for event handlers.
|
|
3
|
+
*/
|
|
4
|
+
import { IProviderAdapter } from '../adapter/adapter';
|
|
5
|
+
import { DevRevClient } from '../devrev/client';
|
|
6
|
+
import { CodeChangeSourceType } from '../devrev/types';
|
|
7
|
+
import { NormalizedEvent } from '../types/events';
|
|
8
|
+
/**
|
|
9
|
+
* Result of a handler operation.
|
|
10
|
+
*/
|
|
11
|
+
export interface HandlerResult {
|
|
12
|
+
success: boolean;
|
|
13
|
+
message: string;
|
|
14
|
+
data?: Record<string, unknown>;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Context required for event handlers.
|
|
18
|
+
*/
|
|
19
|
+
export interface HandlerContext {
|
|
20
|
+
/**
|
|
21
|
+
* The DevRev client instance for API operations.
|
|
22
|
+
*/
|
|
23
|
+
client: DevRevClient;
|
|
24
|
+
/**
|
|
25
|
+
* The code change source type (GitHub=1, GitLab=2, etc.).
|
|
26
|
+
*/
|
|
27
|
+
source: CodeChangeSourceType;
|
|
28
|
+
/**
|
|
29
|
+
* Event type identifier for timeline entries.
|
|
30
|
+
* Should be the type field from the events defined in src/types/events.ts
|
|
31
|
+
* (e.g., 'push', 'pull_request_create', 'pull_request_edit', 'pull_request_review').
|
|
32
|
+
*/
|
|
33
|
+
eventType: string;
|
|
34
|
+
/**
|
|
35
|
+
* The provider adapter for extracting work IDs and fetching commits.
|
|
36
|
+
*/
|
|
37
|
+
adapter: IProviderAdapter;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A handler function that processes a normalized event.
|
|
41
|
+
*/
|
|
42
|
+
export type EventHandler = (event: NormalizedEvent, context: HandlerContext) => Promise<HandlerResult>;
|
|
43
|
+
/**
|
|
44
|
+
* Map of event type string to its handler function.
|
|
45
|
+
*/
|
|
46
|
+
export type HandlerRegistry = Record<string, EventHandler>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/handlers/types.ts"],"names":[],"mappings":";AAAA;;GAEG"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Git SDK - Adapter interfaces for git connectors
|
|
3
|
+
*
|
|
4
|
+
* This SDK provides interfaces that git connectors can implement
|
|
5
|
+
* to publish events from git tools (GitHub, GitLab, etc.) into DevRev.
|
|
6
|
+
*/
|
|
7
|
+
export { type ProviderContext, type DevRevConfig, type SDKConfiguration, type NormalizedActor, type NormalizedCommit, type NormalizedBranch, type NormalizedDiffStats, type NormalizedPullRequest, type NormalizedRepository, type NormalizedEvent, type NormalizedPushEvent, type NormalizedPullRequestCreateEvent, type NormalizedPullRequestEditEvent, type NormalizedPRReviewEvent, type NormalizedPullRequestCloseEvent, type NormalizedPullRequestMergeEvent, ReviewStateValues, type ReviewState, } from './types';
|
|
8
|
+
export { createConfig, type CreateConfigOptions } from './config';
|
|
9
|
+
export { DevRevClient, type DevRevClientConfig, getErrorMessage, getCodeChangeSourceFromProvider, CODE_CHANGE_LEAF_TYPE, TF_PREFIX, tf, ISSUE_CODE_CHANGE_LINK_TYPE_NAME, ISSUE_CODE_CHANGE_LINK_TOOLTIP, ISSUE_CODE_CHANGE_FORWARD_NAME, ISSUE_CODE_CHANGE_BACKWARD_NAME, CodeChangeSource, CodeChangeStatus, CodeChangeFields, GitProviderValues, type GitProvider, type CodeChangeSourceType, type CodeChangeStatusType, type CodeChangeCustomCreateRequest, type CodeChangeCustomUpdateRequest, type TimelineEventMetadata, type ChangeEventBody, type HTTPResponse, type TenantFragmentResult, type CustomLinkTypeInstallResult, type TimelineResult, CodeChangeManager, TenantFragmentManager, CustomLinkTypeManager, LinkManager, TimelineManager, DevUserManager, EventMetadataKeys, postCall, getCall, constructURL, } from './devrev';
|
|
10
|
+
export { handlePushEvent, handlePRCreate, handlePRClose, handlePRReview, handlePRMerge, DEFAULT_HANDLER_REGISTRY, type EventHandler, type HandlerContext, type HandlerRegistry, type HandlerResult, } from './handlers';
|
|
11
|
+
export { EventOrchestrator, type EventOrchestratorConfig, } from './orchestrator';
|
|
12
|
+
export { type IProviderAdapter } from './adapter/adapter';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Git SDK - Adapter interfaces for git connectors
|
|
4
|
+
*
|
|
5
|
+
* This SDK provides interfaces that git connectors can implement
|
|
6
|
+
* to publish events from git tools (GitHub, GitLab, etc.) into DevRev.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.EventOrchestrator = exports.DEFAULT_HANDLER_REGISTRY = exports.handlePRMerge = exports.handlePRReview = exports.handlePRClose = exports.handlePRCreate = exports.handlePushEvent = exports.constructURL = exports.getCall = exports.postCall = exports.EventMetadataKeys = exports.DevUserManager = exports.TimelineManager = exports.LinkManager = exports.CustomLinkTypeManager = exports.TenantFragmentManager = exports.CodeChangeManager = exports.GitProviderValues = exports.CodeChangeFields = exports.CodeChangeStatus = exports.CodeChangeSource = exports.ISSUE_CODE_CHANGE_BACKWARD_NAME = exports.ISSUE_CODE_CHANGE_FORWARD_NAME = exports.ISSUE_CODE_CHANGE_LINK_TOOLTIP = exports.ISSUE_CODE_CHANGE_LINK_TYPE_NAME = exports.tf = exports.TF_PREFIX = exports.CODE_CHANGE_LEAF_TYPE = exports.getCodeChangeSourceFromProvider = exports.getErrorMessage = exports.DevRevClient = exports.createConfig = exports.ReviewStateValues = void 0;
|
|
10
|
+
// Types - re-export from types module
|
|
11
|
+
var types_1 = require("./types");
|
|
12
|
+
Object.defineProperty(exports, "ReviewStateValues", { enumerable: true, get: function () { return types_1.ReviewStateValues; } });
|
|
13
|
+
// Config
|
|
14
|
+
var config_1 = require("./config");
|
|
15
|
+
Object.defineProperty(exports, "createConfig", { enumerable: true, get: function () { return config_1.createConfig; } });
|
|
16
|
+
// DevRev Client
|
|
17
|
+
var devrev_1 = require("./devrev");
|
|
18
|
+
// Main client
|
|
19
|
+
Object.defineProperty(exports, "DevRevClient", { enumerable: true, get: function () { return devrev_1.DevRevClient; } });
|
|
20
|
+
// Utilities
|
|
21
|
+
Object.defineProperty(exports, "getErrorMessage", { enumerable: true, get: function () { return devrev_1.getErrorMessage; } });
|
|
22
|
+
Object.defineProperty(exports, "getCodeChangeSourceFromProvider", { enumerable: true, get: function () { return devrev_1.getCodeChangeSourceFromProvider; } });
|
|
23
|
+
// Constants
|
|
24
|
+
Object.defineProperty(exports, "CODE_CHANGE_LEAF_TYPE", { enumerable: true, get: function () { return devrev_1.CODE_CHANGE_LEAF_TYPE; } });
|
|
25
|
+
Object.defineProperty(exports, "TF_PREFIX", { enumerable: true, get: function () { return devrev_1.TF_PREFIX; } });
|
|
26
|
+
Object.defineProperty(exports, "tf", { enumerable: true, get: function () { return devrev_1.tf; } });
|
|
27
|
+
Object.defineProperty(exports, "ISSUE_CODE_CHANGE_LINK_TYPE_NAME", { enumerable: true, get: function () { return devrev_1.ISSUE_CODE_CHANGE_LINK_TYPE_NAME; } });
|
|
28
|
+
Object.defineProperty(exports, "ISSUE_CODE_CHANGE_LINK_TOOLTIP", { enumerable: true, get: function () { return devrev_1.ISSUE_CODE_CHANGE_LINK_TOOLTIP; } });
|
|
29
|
+
Object.defineProperty(exports, "ISSUE_CODE_CHANGE_FORWARD_NAME", { enumerable: true, get: function () { return devrev_1.ISSUE_CODE_CHANGE_FORWARD_NAME; } });
|
|
30
|
+
Object.defineProperty(exports, "ISSUE_CODE_CHANGE_BACKWARD_NAME", { enumerable: true, get: function () { return devrev_1.ISSUE_CODE_CHANGE_BACKWARD_NAME; } });
|
|
31
|
+
// Enums
|
|
32
|
+
Object.defineProperty(exports, "CodeChangeSource", { enumerable: true, get: function () { return devrev_1.CodeChangeSource; } });
|
|
33
|
+
Object.defineProperty(exports, "CodeChangeStatus", { enumerable: true, get: function () { return devrev_1.CodeChangeStatus; } });
|
|
34
|
+
Object.defineProperty(exports, "CodeChangeFields", { enumerable: true, get: function () { return devrev_1.CodeChangeFields; } });
|
|
35
|
+
// Git Provider
|
|
36
|
+
Object.defineProperty(exports, "GitProviderValues", { enumerable: true, get: function () { return devrev_1.GitProviderValues; } });
|
|
37
|
+
// Managers (for advanced usage)
|
|
38
|
+
Object.defineProperty(exports, "CodeChangeManager", { enumerable: true, get: function () { return devrev_1.CodeChangeManager; } });
|
|
39
|
+
Object.defineProperty(exports, "TenantFragmentManager", { enumerable: true, get: function () { return devrev_1.TenantFragmentManager; } });
|
|
40
|
+
Object.defineProperty(exports, "CustomLinkTypeManager", { enumerable: true, get: function () { return devrev_1.CustomLinkTypeManager; } });
|
|
41
|
+
Object.defineProperty(exports, "LinkManager", { enumerable: true, get: function () { return devrev_1.LinkManager; } });
|
|
42
|
+
Object.defineProperty(exports, "TimelineManager", { enumerable: true, get: function () { return devrev_1.TimelineManager; } });
|
|
43
|
+
Object.defineProperty(exports, "DevUserManager", { enumerable: true, get: function () { return devrev_1.DevUserManager; } });
|
|
44
|
+
Object.defineProperty(exports, "EventMetadataKeys", { enumerable: true, get: function () { return devrev_1.EventMetadataKeys; } });
|
|
45
|
+
// HTTP utilities
|
|
46
|
+
Object.defineProperty(exports, "postCall", { enumerable: true, get: function () { return devrev_1.postCall; } });
|
|
47
|
+
Object.defineProperty(exports, "getCall", { enumerable: true, get: function () { return devrev_1.getCall; } });
|
|
48
|
+
Object.defineProperty(exports, "constructURL", { enumerable: true, get: function () { return devrev_1.constructURL; } });
|
|
49
|
+
// Event Handlers
|
|
50
|
+
var handlers_1 = require("./handlers");
|
|
51
|
+
// Push event handler
|
|
52
|
+
Object.defineProperty(exports, "handlePushEvent", { enumerable: true, get: function () { return handlers_1.handlePushEvent; } });
|
|
53
|
+
// PR handlers
|
|
54
|
+
Object.defineProperty(exports, "handlePRCreate", { enumerable: true, get: function () { return handlers_1.handlePRCreate; } });
|
|
55
|
+
Object.defineProperty(exports, "handlePRClose", { enumerable: true, get: function () { return handlers_1.handlePRClose; } });
|
|
56
|
+
// PR review handler
|
|
57
|
+
Object.defineProperty(exports, "handlePRReview", { enumerable: true, get: function () { return handlers_1.handlePRReview; } });
|
|
58
|
+
// PR merge handler
|
|
59
|
+
Object.defineProperty(exports, "handlePRMerge", { enumerable: true, get: function () { return handlers_1.handlePRMerge; } });
|
|
60
|
+
// Handler registry
|
|
61
|
+
Object.defineProperty(exports, "DEFAULT_HANDLER_REGISTRY", { enumerable: true, get: function () { return handlers_1.DEFAULT_HANDLER_REGISTRY; } });
|
|
62
|
+
// Event Orchestrator
|
|
63
|
+
var orchestrator_1 = require("./orchestrator");
|
|
64
|
+
Object.defineProperty(exports, "EventOrchestrator", { enumerable: true, get: function () { return orchestrator_1.EventOrchestrator; } });
|
|
65
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 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rB,+CAGwB;AAFtB,iHAAA,iBAAiB,OAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event Orchestrator for the Git SDK.
|
|
3
|
+
*
|
|
4
|
+
* The orchestrator is the central routing layer that receives raw events from
|
|
5
|
+
* any Git provider, normalizes them via the provider adapter, and dispatches
|
|
6
|
+
* them to the appropriate handler. This simplifies the consumer experience —
|
|
7
|
+
* instead of manually normalizing events and routing to individual handlers,
|
|
8
|
+
* consumers call a single `processEvent()` method.
|
|
9
|
+
*
|
|
10
|
+
* Flow:
|
|
11
|
+
* 1. Raw provider event → adapter.normalizeEvent() → NormalizedEvent
|
|
12
|
+
* 2. NormalizedEvent.type → route to correct handler
|
|
13
|
+
* 3. Handler processes event → HandlerResult
|
|
14
|
+
*/
|
|
15
|
+
import { IProviderAdapter } from '../adapter/adapter';
|
|
16
|
+
import { HandlerResult } from '../handlers/types';
|
|
17
|
+
import { SDKConfiguration } from '../types/config';
|
|
18
|
+
import { NormalizedEvent } from '../types/events';
|
|
19
|
+
import { GitProvider } from '../types/provider';
|
|
20
|
+
/**
|
|
21
|
+
* Configuration for the EventOrchestrator.
|
|
22
|
+
*/
|
|
23
|
+
export interface EventOrchestratorConfig {
|
|
24
|
+
/** SDK configuration with DevRev and provider settings */
|
|
25
|
+
sdkConfig: SDKConfiguration;
|
|
26
|
+
/** The provider adapter for normalization and data fetching */
|
|
27
|
+
adapter: IProviderAdapter;
|
|
28
|
+
/**
|
|
29
|
+
* The Git provider identifier (e.g., 'github', 'gitlab', 'bitbucket', 'azure').
|
|
30
|
+
* Used to derive the CodeChangeSource for code_change objects.
|
|
31
|
+
*/
|
|
32
|
+
provider: GitProvider;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Central event processing engine for the Git SDK.
|
|
36
|
+
*
|
|
37
|
+
* The EventOrchestrator ties together the provider adapter (normalization)
|
|
38
|
+
* and the event handlers (processing) into a single, easy-to-use interface.
|
|
39
|
+
*
|
|
40
|
+
* Usage:
|
|
41
|
+
* 1. Create an orchestrator with SDK configuration, a provider adapter, and a provider name.
|
|
42
|
+
* 2. Call `processEvent(rawEvent)` for each incoming webhook payload.
|
|
43
|
+
* 3. The orchestrator normalizes the event and routes it to the correct handler.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```typescript
|
|
47
|
+
* const orchestrator = new EventOrchestrator({
|
|
48
|
+
* sdkConfig: {
|
|
49
|
+
* devrev: { endpoint: 'https://api.devrev.ai', token: devrevToken },
|
|
50
|
+
* provider: { token: providerToken },
|
|
51
|
+
* },
|
|
52
|
+
* adapter: myProviderAdapter,
|
|
53
|
+
* provider: 'github', // or 'gitlab', 'bitbucket', 'azure'
|
|
54
|
+
* });
|
|
55
|
+
*
|
|
56
|
+
* // Process a raw webhook payload
|
|
57
|
+
* const result = await orchestrator.processEvent(webhookPayload);
|
|
58
|
+
* console.log(result.success, result.message);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export declare class EventOrchestrator {
|
|
62
|
+
private readonly client;
|
|
63
|
+
private readonly adapter;
|
|
64
|
+
private readonly source;
|
|
65
|
+
/**
|
|
66
|
+
* Creates a new EventOrchestrator.
|
|
67
|
+
*
|
|
68
|
+
* Internally builds a DevRevClient from the provided SDKConfiguration.
|
|
69
|
+
*
|
|
70
|
+
* @param config - The orchestrator configuration
|
|
71
|
+
*/
|
|
72
|
+
constructor(config: EventOrchestratorConfig);
|
|
73
|
+
/**
|
|
74
|
+
* Processes a raw event from a Git provider.
|
|
75
|
+
*
|
|
76
|
+
* This is the primary entry point for event processing. It:
|
|
77
|
+
* 1. Normalizes the raw event via the provider adapter
|
|
78
|
+
* 2. Routes the normalized event to the appropriate handler
|
|
79
|
+
* 3. Returns the handler result
|
|
80
|
+
*
|
|
81
|
+
* @param rawEvent - The raw event payload from the Git provider
|
|
82
|
+
* @returns The handler result indicating success or failure
|
|
83
|
+
*/
|
|
84
|
+
processEvent(rawEvent: unknown): Promise<HandlerResult>;
|
|
85
|
+
/**
|
|
86
|
+
* Processes a pre-normalized event.
|
|
87
|
+
*
|
|
88
|
+
* Use this when the event has already been normalized (e.g., in testing
|
|
89
|
+
* or when the normalization step is handled externally).
|
|
90
|
+
*
|
|
91
|
+
* @param event - The normalized event
|
|
92
|
+
* @returns The handler result indicating success or failure
|
|
93
|
+
*/
|
|
94
|
+
processNormalizedEvent(event: NormalizedEvent): Promise<HandlerResult>;
|
|
95
|
+
/**
|
|
96
|
+
* Builds the HandlerContext for a given event type.
|
|
97
|
+
*/
|
|
98
|
+
private buildHandlerContext;
|
|
99
|
+
}
|