@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.
Files changed (95) hide show
  1. package/README.md +2 -0
  2. package/dist/adapter/adapter.d.ts +9 -0
  3. package/dist/adapter/adapter.js +3 -0
  4. package/dist/adapter/adapter.js.map +1 -0
  5. package/dist/config/create-config.d.ts +34 -0
  6. package/dist/config/create-config.js +33 -0
  7. package/dist/config/create-config.js.map +1 -0
  8. package/dist/config/index.d.ts +4 -0
  9. package/dist/config/index.js +9 -0
  10. package/dist/config/index.js.map +1 -0
  11. package/dist/devrev/client.d.ts +104 -0
  12. package/dist/devrev/client.js +113 -0
  13. package/dist/devrev/client.js.map +1 -0
  14. package/dist/devrev/http.d.ts +42 -0
  15. package/dist/devrev/http.js +105 -0
  16. package/dist/devrev/http.js.map +1 -0
  17. package/dist/devrev/index.d.ts +7 -0
  18. package/dist/devrev/index.js +43 -0
  19. package/dist/devrev/index.js.map +1 -0
  20. package/dist/devrev/managers/code_change_manager.d.ts +48 -0
  21. package/dist/devrev/managers/code_change_manager.js +227 -0
  22. package/dist/devrev/managers/code_change_manager.js.map +1 -0
  23. package/dist/devrev/managers/code_change_schema.d.ts +12 -0
  24. package/dist/devrev/managers/code_change_schema.js +317 -0
  25. package/dist/devrev/managers/code_change_schema.js.map +1 -0
  26. package/dist/devrev/managers/custom_link_type_manager.d.ts +33 -0
  27. package/dist/devrev/managers/custom_link_type_manager.js +94 -0
  28. package/dist/devrev/managers/custom_link_type_manager.js.map +1 -0
  29. package/dist/devrev/managers/dev_user_manager.d.ts +53 -0
  30. package/dist/devrev/managers/dev_user_manager.js +155 -0
  31. package/dist/devrev/managers/dev_user_manager.js.map +1 -0
  32. package/dist/devrev/managers/index.d.ts +9 -0
  33. package/dist/devrev/managers/index.js +20 -0
  34. package/dist/devrev/managers/index.js.map +1 -0
  35. package/dist/devrev/managers/link_manager.d.ts +41 -0
  36. package/dist/devrev/managers/link_manager.js +111 -0
  37. package/dist/devrev/managers/link_manager.js.map +1 -0
  38. package/dist/devrev/managers/tenant_fragment_manager.d.ts +26 -0
  39. package/dist/devrev/managers/tenant_fragment_manager.js +68 -0
  40. package/dist/devrev/managers/tenant_fragment_manager.js.map +1 -0
  41. package/dist/devrev/managers/timeline_manager.d.ts +86 -0
  42. package/dist/devrev/managers/timeline_manager.js +184 -0
  43. package/dist/devrev/managers/timeline_manager.js.map +1 -0
  44. package/dist/devrev/types.d.ts +139 -0
  45. package/dist/devrev/types.js +127 -0
  46. package/dist/devrev/types.js.map +1 -0
  47. package/dist/handlers/commit_push_handler.d.ts +31 -0
  48. package/dist/handlers/commit_push_handler.js +145 -0
  49. package/dist/handlers/commit_push_handler.js.map +1 -0
  50. package/dist/handlers/helpers.d.ts +87 -0
  51. package/dist/handlers/helpers.js +201 -0
  52. package/dist/handlers/helpers.js.map +1 -0
  53. package/dist/handlers/index.d.ts +12 -0
  54. package/dist/handlers/index.js +26 -0
  55. package/dist/handlers/index.js.map +1 -0
  56. package/dist/handlers/pr_create_handler.d.ts +36 -0
  57. package/dist/handlers/pr_create_handler.js +121 -0
  58. package/dist/handlers/pr_create_handler.js.map +1 -0
  59. package/dist/handlers/pr_merge_handler.d.ts +29 -0
  60. package/dist/handlers/pr_merge_handler.js +86 -0
  61. package/dist/handlers/pr_merge_handler.js.map +1 -0
  62. package/dist/handlers/pr_review_handler.d.ts +30 -0
  63. package/dist/handlers/pr_review_handler.js +109 -0
  64. package/dist/handlers/pr_review_handler.js.map +1 -0
  65. package/dist/handlers/registry.d.ts +9 -0
  66. package/dist/handlers/registry.js +22 -0
  67. package/dist/handlers/registry.js.map +1 -0
  68. package/dist/handlers/types.d.ts +46 -0
  69. package/dist/handlers/types.js +6 -0
  70. package/dist/handlers/types.js.map +1 -0
  71. package/dist/index.d.ts +12 -0
  72. package/dist/index.js +65 -0
  73. package/dist/index.js.map +1 -0
  74. package/dist/orchestrator/event_orchestrator.d.ts +99 -0
  75. package/dist/orchestrator/event_orchestrator.js +137 -0
  76. package/dist/orchestrator/event_orchestrator.js.map +1 -0
  77. package/dist/orchestrator/index.d.ts +7 -0
  78. package/dist/orchestrator/index.js +12 -0
  79. package/dist/orchestrator/index.js.map +1 -0
  80. package/dist/types/config.d.ts +22 -0
  81. package/dist/types/config.js +6 -0
  82. package/dist/types/config.js.map +1 -0
  83. package/dist/types/events.d.ts +50 -0
  84. package/dist/types/events.js +14 -0
  85. package/dist/types/events.js.map +1 -0
  86. package/dist/types/index.d.ts +7 -0
  87. package/dist/types/index.js +24 -0
  88. package/dist/types/index.js.map +1 -0
  89. package/dist/types/provider.d.ts +20 -0
  90. package/dist/types/provider.js +14 -0
  91. package/dist/types/provider.js.map +1 -0
  92. package/dist/types/types.d.ts +48 -0
  93. package/dist/types/types.js +9 -0
  94. package/dist/types/types.js.map +1 -0
  95. package/package.json +61 -0
@@ -0,0 +1,86 @@
1
+ /**
2
+ * Manager for timeline entry operations.
3
+ */
4
+ import { ChangeEventBody, GitProvider } from '../types';
5
+ import type { publicSDK } from '@devrev/typescript-sdk';
6
+ /**
7
+ * Result of timeline entry operation.
8
+ */
9
+ export interface TimelineResult {
10
+ success: boolean;
11
+ message?: string;
12
+ data?: any;
13
+ }
14
+ /**
15
+ * Event metadata key constants.
16
+ */
17
+ export declare const EventMetadataKeys: {
18
+ readonly BRANCH_NAME: "branch_name";
19
+ readonly REPO_NAME: "repo_name";
20
+ readonly SOURCE_TIME_STAMP: "source_time_stamp";
21
+ };
22
+ /**
23
+ * Manager for timeline entry operations.
24
+ */
25
+ export declare class TimelineManager {
26
+ private publicApi;
27
+ private endpoint;
28
+ private token;
29
+ private provider;
30
+ /**
31
+ * Creates a new TimelineManager.
32
+ *
33
+ * @param publicApi - The DevRev public API instance
34
+ * @param endpoint - The DevRev API endpoint
35
+ * @param token - The DevRev API token
36
+ * @param provider - The Git provider used as app identifier (defaults to 'unknown')
37
+ */
38
+ constructor(publicApi: publicSDK.Api<unknown>, endpoint: string, token: string, provider?: GitProvider);
39
+ /**
40
+ * Creates a timeline entry in the events collection.
41
+ *
42
+ * @param objectId - The object ID to create the timeline entry for
43
+ * @param changeEvent - The change event body
44
+ * @returns Operation result
45
+ */
46
+ createEventEntry(objectId: string, changeEvent: ChangeEventBody): Promise<TimelineResult>;
47
+ /**
48
+ * Lists timeline entries in the events collection for a given object.
49
+ *
50
+ * @param objectId - The object ID to list timeline entries for
51
+ * @returns Array of timeline entries
52
+ */
53
+ listEventEntries(objectId: string): Promise<Record<string, any>[]>;
54
+ /**
55
+ * Creates a change event body for timeline entries.
56
+ *
57
+ * @param actor - Actor information (id, username/login, url)
58
+ * @param branchName - The branch name
59
+ * @param repoName - The repository name
60
+ * @param sourceTimestamp - The source timestamp (ISO format)
61
+ * @param eventUrl - The URL of the event (e.g., PR URL, commit URL)
62
+ * @param eventType - The type of event
63
+ * @param message - The event message/summary
64
+ * @returns The change event body
65
+ */
66
+ createChangeEventBody(actor: {
67
+ id: string;
68
+ username: string;
69
+ url: string;
70
+ }, branchName: string, repoName: string, sourceTimestamp: string, eventUrl: string, eventType: string, message: string): ChangeEventBody;
71
+ /**
72
+ * Creates a timeline entry in the discussions collection.
73
+ *
74
+ * @param objectId - The object ID to create the timeline entry for
75
+ * @param message - The message to post
76
+ * @returns Operation result
77
+ */
78
+ createDiscussionEntry(objectId: string, message: string): Promise<TimelineResult>;
79
+ /**
80
+ * Deletes a timeline entry.
81
+ *
82
+ * @param commentId - The timeline entry ID to delete
83
+ * @returns Operation result
84
+ */
85
+ deleteEntry(commentId: string): Promise<TimelineResult>;
86
+ }
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ /**
3
+ * Manager for timeline entry operations.
4
+ */
5
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
6
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
7
+ return new (P || (P = Promise))(function (resolve, reject) {
8
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
9
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
10
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
11
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
12
+ });
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.TimelineManager = exports.EventMetadataKeys = void 0;
16
+ const http_1 = require("../http");
17
+ const types_1 = require("../types");
18
+ /**
19
+ * Event metadata key constants.
20
+ */
21
+ exports.EventMetadataKeys = {
22
+ BRANCH_NAME: 'branch_name',
23
+ REPO_NAME: 'repo_name',
24
+ SOURCE_TIME_STAMP: 'source_time_stamp',
25
+ };
26
+ /**
27
+ * Manager for timeline entry operations.
28
+ */
29
+ class TimelineManager {
30
+ /**
31
+ * Creates a new TimelineManager.
32
+ *
33
+ * @param publicApi - The DevRev public API instance
34
+ * @param endpoint - The DevRev API endpoint
35
+ * @param token - The DevRev API token
36
+ * @param provider - The Git provider used as app identifier (defaults to 'unknown')
37
+ */
38
+ constructor(publicApi, endpoint, token, provider = types_1.GitProviderValues.UNKNOWN) {
39
+ this.publicApi = publicApi;
40
+ this.endpoint = endpoint;
41
+ this.token = token;
42
+ this.provider = provider;
43
+ }
44
+ /**
45
+ * Creates a timeline entry in the events collection.
46
+ *
47
+ * @param objectId - The object ID to create the timeline entry for
48
+ * @param changeEvent - The change event body
49
+ * @returns Operation result
50
+ */
51
+ createEventEntry(objectId, changeEvent) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const endpoint = this.endpoint + '/internal/timeline-entries.create';
54
+ const data = {
55
+ change_event: changeEvent,
56
+ object: objectId,
57
+ type: 'timeline_change_event',
58
+ };
59
+ const response = yield (0, http_1.postCall)(endpoint, this.token, data);
60
+ if (!response.success) {
61
+ console.error(`Error creating timeline entry in events: ${response.message}`);
62
+ return {
63
+ success: false,
64
+ message: `Error creating timeline entry in events: ${response.message}`,
65
+ };
66
+ }
67
+ return { success: true, data: response.data };
68
+ });
69
+ }
70
+ /**
71
+ * Lists timeline entries in the events collection for a given object.
72
+ *
73
+ * @param objectId - The object ID to list timeline entries for
74
+ * @returns Array of timeline entries
75
+ */
76
+ listEventEntries(objectId) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ const endpoint = this.endpoint + '/internal/timeline-entries.list';
79
+ const data = {
80
+ collections: ['events'],
81
+ object: objectId,
82
+ };
83
+ const response = yield (0, http_1.postCall)(endpoint, this.token, data);
84
+ if (!response.success) {
85
+ throw new Error(`Error listing timeline entries: ${response.message}`);
86
+ }
87
+ return response.data.timeline_entries;
88
+ });
89
+ }
90
+ /**
91
+ * Creates a change event body for timeline entries.
92
+ *
93
+ * @param actor - Actor information (id, username/login, url)
94
+ * @param branchName - The branch name
95
+ * @param repoName - The repository name
96
+ * @param sourceTimestamp - The source timestamp (ISO format)
97
+ * @param eventUrl - The URL of the event (e.g., PR URL, commit URL)
98
+ * @param eventType - The type of event
99
+ * @param message - The event message/summary
100
+ * @returns The change event body
101
+ */
102
+ createChangeEventBody(actor, branchName, repoName, sourceTimestamp, eventUrl, eventType, message) {
103
+ return {
104
+ app: this.provider,
105
+ app_user_display_id: actor.username,
106
+ app_user_id: actor.id,
107
+ app_user_identifier: actor.url,
108
+ event_metadata: [
109
+ {
110
+ key: exports.EventMetadataKeys.BRANCH_NAME,
111
+ value: branchName,
112
+ },
113
+ {
114
+ key: exports.EventMetadataKeys.REPO_NAME,
115
+ value: repoName,
116
+ },
117
+ {
118
+ key: exports.EventMetadataKeys.SOURCE_TIME_STAMP,
119
+ value: sourceTimestamp,
120
+ },
121
+ ],
122
+ event_summary: message,
123
+ event_type: eventType,
124
+ event_url: eventUrl,
125
+ message: message,
126
+ source_timestamp: sourceTimestamp,
127
+ type: 'microflow_action',
128
+ };
129
+ }
130
+ /**
131
+ * Creates a timeline entry in the discussions collection.
132
+ *
133
+ * @param objectId - The object ID to create the timeline entry for
134
+ * @param message - The message to post
135
+ * @returns Operation result
136
+ */
137
+ createDiscussionEntry(objectId, message) {
138
+ return __awaiter(this, void 0, void 0, function* () {
139
+ try {
140
+ const response = yield this.publicApi.timelineEntriesCreate({
141
+ body: message,
142
+ body_type: 'text',
143
+ object: objectId,
144
+ type: 'timeline_comment',
145
+ });
146
+ return { success: true, data: response.data };
147
+ }
148
+ catch (error) {
149
+ const errorMsg = (0, types_1.getErrorMessage)(error);
150
+ console.error(`Error creating timeline entry in discussions: ${errorMsg}`);
151
+ return {
152
+ success: false,
153
+ message: `Error creating timeline entry in discussions: ${errorMsg}`,
154
+ };
155
+ }
156
+ });
157
+ }
158
+ /**
159
+ * Deletes a timeline entry.
160
+ *
161
+ * @param commentId - The timeline entry ID to delete
162
+ * @returns Operation result
163
+ */
164
+ deleteEntry(commentId) {
165
+ return __awaiter(this, void 0, void 0, function* () {
166
+ try {
167
+ const response = yield this.publicApi.timelineEntriesDelete({
168
+ id: commentId,
169
+ });
170
+ return { success: true, data: response.data };
171
+ }
172
+ catch (error) {
173
+ const errorMsg = (0, types_1.getErrorMessage)(error);
174
+ console.error(`Error deleting timeline entry: ${errorMsg}`);
175
+ return {
176
+ success: false,
177
+ message: `Error deleting timeline entry: ${errorMsg}`,
178
+ };
179
+ }
180
+ });
181
+ }
182
+ }
183
+ exports.TimelineManager = TimelineManager;
184
+ //# sourceMappingURL=timeline_manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timeline_manager.js","sourceRoot":"","sources":["../../../src/devrev/managers/timeline_manager.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;AAEH,kCAAmC;AACnC,oCAKkB;AAalB;;GAEG;AACU,QAAA,iBAAiB,GAAG;IAC/B,WAAW,EAAE,aAAa;IAC1B,SAAS,EAAE,WAAW;IACtB,iBAAiB,EAAE,mBAAmB;CAC9B,CAAC;AAEX;;GAEG;AACH,MAAa,eAAe;IAS1B;;;;;;;OAOG;IACH,YACE,SAAiC,EACjC,QAAgB,EAChB,KAAa,EACb,WAAwB,yBAAiB,CAAC,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OAAO,KAAc,EAAE;gBACvB,MAAM,QAAQ,GAAG,IAAA,uBAAe,EAAC,KAAK,CAAC,CAAC;gBACxC,OAAO,CAAC,KAAK,CAAC,iDAAiD,QAAQ,EAAE,CAAC,CAAC;gBAC3E,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,OAAO,EAAE,iDAAiD,QAAQ,EAAE;iBACrE,CAAC;aACH;QACH,CAAC;KAAA;IAED;;;;;OAKG;IACG,WAAW,CAAC,SAAiB;;YACjC,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAAC;oBAC1D,EAAE,EAAE,SAAS;iBACd,CAAC,CAAC;gBAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC;aAC/C;YAAC,OAAO,KAAc,EAAE;gBACvB,MAAM,QAAQ,GAAG,IAAA,uBAAe,EAAC,KAAK,CAAC,CAAC;gBACxC,OAAO,CAAC,KAAK,CAAC,kCAAkC,QAAQ,EAAE,CAAC,CAAC;gBAC5D,OAAO;oBACL,OAAO,EAAE,KAAK;oBACd,OAAO,EAAE,kCAAkC,QAAQ,EAAE;iBACtD,CAAC;aACH;QACH,CAAC;KAAA;CACF;AAzLD,0CAyLC"}
@@ -0,0 +1,139 @@
1
+ /**
2
+ * DevRev-specific types for the Git SDK.
3
+ */
4
+ import { GitProvider } from '../types/provider';
5
+ /**
6
+ * Safely extracts error message from unknown error type.
7
+ */
8
+ export declare function getErrorMessage(error: unknown): string;
9
+ export declare const CODE_CHANGE_LEAF_TYPE = "code_change";
10
+ /** Tenant fragment custom field prefix */
11
+ export declare const TF_PREFIX = "tnt__";
12
+ /** Helper to get full custom field name with tenant prefix */
13
+ export declare const tf: (field: string) => string;
14
+ /**
15
+ * Source provider numeric values for code_change schema enum.
16
+ * These values correspond to the allowed_values in the tenant fragment.
17
+ */
18
+ export declare const CodeChangeSource: {
19
+ readonly UNKNOWN: 0;
20
+ readonly GITHUB: 1;
21
+ readonly BITBUCKET: 2;
22
+ readonly GITLAB: 3;
23
+ readonly AZURE_DEVOPS: 4;
24
+ };
25
+ export type CodeChangeSourceType = (typeof CodeChangeSource)[keyof typeof CodeChangeSource];
26
+ /**
27
+ * Maps GitProvider string values to CodeChangeSource numeric values.
28
+ *
29
+ * @param provider - The GitProvider string value
30
+ * @returns The corresponding CodeChangeSource numeric value
31
+ */
32
+ export declare function getCodeChangeSourceFromProvider(provider: GitProvider): CodeChangeSourceType;
33
+ /**
34
+ * Status values for code changes (ordered by ordinal).
35
+ */
36
+ export declare const CodeChangeStatus: {
37
+ readonly DRAFT: 0;
38
+ readonly WAITING_FOR_REVIEW: 1;
39
+ readonly CHANGES_REQUESTED: 2;
40
+ readonly APPROVED: 3;
41
+ readonly MERGED: 4;
42
+ readonly CLOSED: 5;
43
+ };
44
+ export type CodeChangeStatusType = (typeof CodeChangeStatus)[keyof typeof CodeChangeStatus];
45
+ /**
46
+ * Custom field names for code_change objects (grouped logically).
47
+ */
48
+ export declare const CodeChangeFields: {
49
+ readonly SOURCE: "source";
50
+ readonly AUTHOR: "author";
51
+ readonly REPO_NAME: "repo_name";
52
+ readonly SOURCE_BRANCH: "source_branch";
53
+ readonly TARGET_BRANCH: "target_branch";
54
+ readonly EXTERNAL_URL: "external_url";
55
+ readonly STATUS: "status";
56
+ readonly REVIEWED_BY: "reviewed_by";
57
+ readonly REQUESTED_REVIEWERS: "requested_reviewers";
58
+ readonly APPROVED_BY: "approved_by";
59
+ readonly TARGET_COMMITS: "target_commits";
60
+ readonly SOURCE_COMMITS: "source_commits";
61
+ readonly FIRST_COMMIT_AT: "first_commit_at";
62
+ readonly LAST_COMMIT_AT: "last_commit_at";
63
+ readonly PR_CREATED_AT: "pr_created_at";
64
+ readonly FIRST_REVIEW_AT: "first_review_at";
65
+ readonly LAST_REVIEW_AT: "last_review_at";
66
+ readonly FIRST_APPROVED_AT: "first_approved_at";
67
+ readonly LAST_APPROVED_AT: "last_approved_at";
68
+ readonly CLOSED_AT: "closed_at";
69
+ readonly LINES_ADDED: "lines_added";
70
+ readonly LINES_DELETED: "lines_deleted";
71
+ readonly FILES_CHANGED: "files_changed";
72
+ };
73
+ export declare const ISSUE_CODE_CHANGE_LINK_TYPE_NAME = "issue_code_change";
74
+ export declare const ISSUE_CODE_CHANGE_LINK_TOOLTIP = "Links an issue to code change custom object";
75
+ export declare const ISSUE_CODE_CHANGE_FORWARD_NAME = "addressed by";
76
+ export declare const ISSUE_CODE_CHANGE_BACKWARD_NAME = "addresses";
77
+ /**
78
+ * Request type for creating a code_change custom object.
79
+ */
80
+ export interface CodeChangeCustomCreateRequest {
81
+ title: string;
82
+ source: CodeChangeSourceType;
83
+ repo_name: string;
84
+ source_branch: string;
85
+ target_branch: string;
86
+ external_url: string;
87
+ status: CodeChangeStatusType;
88
+ author?: string;
89
+ pr_created_at?: string;
90
+ first_commit_at?: string;
91
+ last_commit_at?: string;
92
+ }
93
+ /**
94
+ * Request type for updating a code_change custom object.
95
+ */
96
+ export interface CodeChangeCustomUpdateRequest {
97
+ id: string;
98
+ status?: CodeChangeStatusType;
99
+ source_commits?: string[];
100
+ target_commits?: string[];
101
+ first_commit_at?: string;
102
+ last_commit_at?: string;
103
+ first_review_at?: string;
104
+ last_review_at?: string;
105
+ first_approved_at?: string;
106
+ last_approved_at?: string;
107
+ closed_at?: string;
108
+ lines_added?: number;
109
+ lines_deleted?: number;
110
+ files_changed?: number;
111
+ add_reviewed_by?: string[];
112
+ add_approved_by?: string[];
113
+ add_requested_reviewer?: string[];
114
+ remove_requested_reviewer?: string[];
115
+ }
116
+ /**
117
+ * Metadata for timeline change events.
118
+ */
119
+ export interface TimelineEventMetadata {
120
+ key: string;
121
+ value: string;
122
+ }
123
+ /**
124
+ * Change event body for timeline entries.
125
+ */
126
+ export interface ChangeEventBody {
127
+ app: string;
128
+ app_user_display_id: string;
129
+ app_user_id: string;
130
+ app_user_identifier: string;
131
+ event_metadata: TimelineEventMetadata[];
132
+ event_summary: string;
133
+ event_type: string;
134
+ event_url: string;
135
+ message: string;
136
+ source_timestamp: string;
137
+ type: string;
138
+ }
139
+ export { GitProvider, GitProviderValues } from '../types/provider';
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+ /**
3
+ * DevRev-specific types for the Git SDK.
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GitProviderValues = 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.CodeChangeFields = exports.CodeChangeStatus = exports.getCodeChangeSourceFromProvider = exports.CodeChangeSource = exports.tf = exports.TF_PREFIX = exports.CODE_CHANGE_LEAF_TYPE = exports.getErrorMessage = void 0;
7
+ const provider_1 = require("../types/provider");
8
+ // =============================================================================
9
+ // Utility Functions
10
+ // =============================================================================
11
+ /**
12
+ * Safely extracts error message from unknown error type.
13
+ */
14
+ function getErrorMessage(error) {
15
+ return error instanceof Error ? error.message : String(error);
16
+ }
17
+ exports.getErrorMessage = getErrorMessage;
18
+ // =============================================================================
19
+ // Code Change Constants
20
+ // =============================================================================
21
+ exports.CODE_CHANGE_LEAF_TYPE = 'code_change';
22
+ /** Tenant fragment custom field prefix */
23
+ exports.TF_PREFIX = 'tnt__';
24
+ /** Helper to get full custom field name with tenant prefix */
25
+ const tf = (field) => `${exports.TF_PREFIX}${field}`;
26
+ exports.tf = tf;
27
+ // =============================================================================
28
+ // Source Enum
29
+ // =============================================================================
30
+ /**
31
+ * Source provider numeric values for code_change schema enum.
32
+ * These values correspond to the allowed_values in the tenant fragment.
33
+ */
34
+ exports.CodeChangeSource = {
35
+ UNKNOWN: 0,
36
+ GITHUB: 1,
37
+ BITBUCKET: 2,
38
+ GITLAB: 3,
39
+ AZURE_DEVOPS: 4,
40
+ };
41
+ /**
42
+ * Maps GitProvider string values to CodeChangeSource numeric values.
43
+ *
44
+ * @param provider - The GitProvider string value
45
+ * @returns The corresponding CodeChangeSource numeric value
46
+ */
47
+ function getCodeChangeSourceFromProvider(provider) {
48
+ switch (provider) {
49
+ case provider_1.GitProviderValues.GITHUB:
50
+ return exports.CodeChangeSource.GITHUB;
51
+ case provider_1.GitProviderValues.GITLAB:
52
+ return exports.CodeChangeSource.GITLAB;
53
+ case provider_1.GitProviderValues.BITBUCKET:
54
+ return exports.CodeChangeSource.BITBUCKET;
55
+ case provider_1.GitProviderValues.AZURE:
56
+ return exports.CodeChangeSource.AZURE_DEVOPS;
57
+ case provider_1.GitProviderValues.UNKNOWN:
58
+ default:
59
+ return exports.CodeChangeSource.UNKNOWN;
60
+ }
61
+ }
62
+ exports.getCodeChangeSourceFromProvider = getCodeChangeSourceFromProvider;
63
+ // =============================================================================
64
+ // Status Enum
65
+ // =============================================================================
66
+ /**
67
+ * Status values for code changes (ordered by ordinal).
68
+ */
69
+ exports.CodeChangeStatus = {
70
+ DRAFT: 0,
71
+ WAITING_FOR_REVIEW: 1,
72
+ CHANGES_REQUESTED: 2,
73
+ APPROVED: 3,
74
+ MERGED: 4,
75
+ CLOSED: 5,
76
+ };
77
+ // =============================================================================
78
+ // Field Names
79
+ // =============================================================================
80
+ /**
81
+ * Custom field names for code_change objects (grouped logically).
82
+ */
83
+ exports.CodeChangeFields = {
84
+ // Identity
85
+ SOURCE: 'source',
86
+ AUTHOR: 'author',
87
+ // Repository
88
+ REPO_NAME: 'repo_name',
89
+ SOURCE_BRANCH: 'source_branch',
90
+ TARGET_BRANCH: 'target_branch',
91
+ EXTERNAL_URL: 'external_url',
92
+ // Status
93
+ STATUS: 'status',
94
+ // Reviewers
95
+ REVIEWED_BY: 'reviewed_by',
96
+ REQUESTED_REVIEWERS: 'requested_reviewers',
97
+ APPROVED_BY: 'approved_by',
98
+ // Commits
99
+ TARGET_COMMITS: 'target_commits',
100
+ SOURCE_COMMITS: 'source_commits',
101
+ // Timestamps
102
+ FIRST_COMMIT_AT: 'first_commit_at',
103
+ LAST_COMMIT_AT: 'last_commit_at',
104
+ PR_CREATED_AT: 'pr_created_at',
105
+ FIRST_REVIEW_AT: 'first_review_at',
106
+ LAST_REVIEW_AT: 'last_review_at',
107
+ FIRST_APPROVED_AT: 'first_approved_at',
108
+ LAST_APPROVED_AT: 'last_approved_at',
109
+ CLOSED_AT: 'closed_at',
110
+ // Metrics
111
+ LINES_ADDED: 'lines_added',
112
+ LINES_DELETED: 'lines_deleted',
113
+ FILES_CHANGED: 'files_changed',
114
+ };
115
+ // =============================================================================
116
+ // Custom Link Type Constants
117
+ // =============================================================================
118
+ exports.ISSUE_CODE_CHANGE_LINK_TYPE_NAME = 'issue_code_change';
119
+ exports.ISSUE_CODE_CHANGE_LINK_TOOLTIP = 'Links an issue to code change custom object';
120
+ exports.ISSUE_CODE_CHANGE_FORWARD_NAME = 'addressed by';
121
+ exports.ISSUE_CODE_CHANGE_BACKWARD_NAME = 'addresses';
122
+ // =============================================================================
123
+ // Re-export GitProvider for convenience
124
+ // =============================================================================
125
+ var provider_2 = require("../types/provider");
126
+ Object.defineProperty(exports, "GitProviderValues", { enumerable: true, get: function () { return provider_2.GitProviderValues; } });
127
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/devrev/types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,gDAAmE;AAEnE,gFAAgF;AAChF,oBAAoB;AACpB,gFAAgF;AAEhF;;GAEG;AACH,SAAgB,eAAe,CAAC,KAAc;IAC5C,OAAO,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAChE,CAAC;AAFD,0CAEC;AAED,gFAAgF;AAChF,wBAAwB;AACxB,gFAAgF;AAEnE,QAAA,qBAAqB,GAAG,aAAa,CAAC;AAEnD,0CAA0C;AAC7B,QAAA,S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B,aAAa;IACb,SAAS,EAAE,WAAW;IACtB,aAAa,EAAE,eAAe;IAC9B,aAAa,EAAE,eAAe;IAC9B,YAAY,EAAE,cAAc;IAC5B,SAAS;IACT,MAAM,EAAE,QAAQ;IAChB,YAAY;IACZ,WAAW,EAAE,aAAa;IAC1B,mBAAmB,EAAE,qBAAqB;IAC1C,WAAW,EAAE,aAAa;IAC1B,UAAU;IACV,cAAc,EAAE,gBAAgB;IAChC,cAAc,EAAE,gBAAgB;IAChC,aAAa;IACb,eAAe,EAAE,iBAAiB;IAClC,cAAc,EAAE,gBAAgB;IAChC,aAAa,EAAE,eAAe;IAC9B,eAAe,EAAE,iBAAiB;IAClC,cAAc,EAAE,gBAAgB;IAChC,iBAAiB,EAAE,mBAAmB;IACtC,gBAAgB,EAAE,kBAAkB;IACpC,SAAS,EAAE,WAAW;IACtB,UAAU;IACV,WAAW,EAAE,aAAa;IAC1B,aAAa,EAAE,eAAe;IAC9B,aAAa,EAAE,eAAe;CACtB,CAAC;AAEX,gFAAgF;AAChF,6BAA6B;AAC7B,gFAAgF;AAEnE,QAAA,gCAAgC,GAAG,mBAAmB,CAAC;AACvD,QAAA,8BAA8B,GACzC,6CAA6C,CAAC;AACnC,QAAA,8BAA8B,GAAG,cAAc,CAAC;AAChD,QAAA,+BAA+B,GAAG,WAAW,CAAC;AAoF3D,gFAAgF;AAChF,wCAAwC;AACxC,gFAAgF;AAEhF,8CAAmE;AAA7C,6GAAA,iBAAiB,OAAA"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Handler for push events.
3
+ *
4
+ * This handler processes push events and updates the associated code_change
5
+ * custom objects with commit information. It also creates timeline entries
6
+ * for each commit in the push.
7
+ */
8
+ import { NormalizedPushEvent } from '../types/events';
9
+ import { HandlerContext, HandlerResult } from './types';
10
+ /**
11
+ * Process a push event.
12
+ *
13
+ * This function handles the core business logic for creating/updating custom code_change
14
+ * objects and timeline entries when commits are pushed to a PR branch.
15
+ *
16
+ * Behavior:
17
+ * - Push events with no commits are skipped (returns success with skip message)
18
+ * - Push events with no associated PRs are skipped (returns success with skip message)
19
+ * - For new code_change objects, historical commits are fetched from the adapter
20
+ * and populated (first_commit_at, last_commit_at, timeline entries)
21
+ *
22
+ * For each associated PR:
23
+ * 1. Gets or creates the code_change custom object
24
+ * 2. Updates source_commits, first_commit_at (if not set), and last_commit_at
25
+ * 3. Creates timeline entries for each commit (when updating existing code_change)
26
+ *
27
+ * @param input - The normalized push event
28
+ * @param context - The handler context with DevRev client and adapter
29
+ * @returns Handler result indicating success or failure
30
+ */
31
+ export declare function handlePushEvent(input: NormalizedPushEvent, context: HandlerContext): Promise<HandlerResult>;