@oneuptime/common 9.2.12 → 9.2.14

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 (190) hide show
  1. package/Models/DatabaseModels/AlertInternalNote.ts +29 -0
  2. package/Models/DatabaseModels/IncidentInternalNote.ts +29 -0
  3. package/Models/DatabaseModels/IncidentPublicNote.ts +29 -0
  4. package/Models/DatabaseModels/Index.ts +3 -11
  5. package/Models/DatabaseModels/{CopilotPullRequest.ts → LlmProvider.ts} +243 -248
  6. package/Models/DatabaseModels/ScheduledMaintenanceInternalNote.ts +29 -0
  7. package/Models/DatabaseModels/ScheduledMaintenancePublicNote.ts +29 -0
  8. package/Server/API/LlmProviderAPI.ts +57 -0
  9. package/Server/API/MicrosoftTeamsAPI.ts +2 -146
  10. package/Server/API/SlackAPI.ts +105 -0
  11. package/Server/API/StatusPageAPI.ts +6 -0
  12. package/Server/Infrastructure/Postgres/SchemaMigrations/1765477339178-MigrationName.ts +71 -0
  13. package/Server/Infrastructure/Postgres/SchemaMigrations/1765540325149-MigrationName.ts +45 -0
  14. package/Server/Infrastructure/Postgres/SchemaMigrations/1765540549739-MigrationName.ts +61 -0
  15. package/Server/Infrastructure/Postgres/SchemaMigrations/1765544010078-MigrationName.ts +35 -0
  16. package/Server/Infrastructure/Postgres/SchemaMigrations/Index.ts +8 -0
  17. package/Server/Middleware/SlackAuthorization.ts +4 -1
  18. package/Server/Services/AlertInternalNoteService.ts +26 -0
  19. package/Server/Services/IncidentInternalNoteService.ts +26 -0
  20. package/Server/Services/IncidentPublicNoteService.ts +26 -0
  21. package/Server/Services/Index.ts +2 -11
  22. package/Server/Services/LlmProviderService.ts +100 -0
  23. package/Server/Services/ScheduledMaintenanceInternalNoteService.ts +26 -0
  24. package/Server/Services/ScheduledMaintenancePublicNoteService.ts +26 -0
  25. package/Server/Services/StatusPageService.ts +3 -0
  26. package/Server/Utils/Express.ts +1 -0
  27. package/Server/Utils/StartServer.ts +5 -0
  28. package/Server/Utils/StatusPageResource.ts +89 -0
  29. package/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.ts +96 -55
  30. package/Server/Utils/Workspace/Slack/Actions/ActionTypes.ts +16 -0
  31. package/Server/Utils/Workspace/Slack/Actions/Alert.ts +184 -1
  32. package/Server/Utils/Workspace/Slack/Actions/Incident.ts +224 -1
  33. package/Server/Utils/Workspace/Slack/Actions/ScheduledMaintenance.ts +232 -1
  34. package/Server/Utils/Workspace/Slack/Slack.ts +113 -0
  35. package/Server/Utils/Workspace/Slack/app-manifest.json +13 -2
  36. package/Tests/Server/Utils/StatusPageResource.test.ts +161 -0
  37. package/Types/Icon/IconProp.ts +1 -0
  38. package/Types/LLM/Index.ts +4 -0
  39. package/Types/LLM/LlmType.ts +7 -0
  40. package/Types/Permission.ts +38 -113
  41. package/UI/Components/Icon/Icon.tsx +8 -0
  42. package/UI/Components/Link/Link.tsx +5 -1
  43. package/build/dist/Models/DatabaseModels/AlertInternalNote.js +30 -0
  44. package/build/dist/Models/DatabaseModels/AlertInternalNote.js.map +1 -1
  45. package/build/dist/Models/DatabaseModels/IncidentInternalNote.js +30 -0
  46. package/build/dist/Models/DatabaseModels/IncidentInternalNote.js.map +1 -1
  47. package/build/dist/Models/DatabaseModels/IncidentPublicNote.js +30 -0
  48. package/build/dist/Models/DatabaseModels/IncidentPublicNote.js.map +1 -1
  49. package/build/dist/Models/DatabaseModels/Index.js +2 -10
  50. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  51. package/build/dist/Models/DatabaseModels/{CopilotPullRequest.js → LlmProvider.js} +263 -255
  52. package/build/dist/Models/DatabaseModels/LlmProvider.js.map +1 -0
  53. package/build/dist/Models/DatabaseModels/ScheduledMaintenanceInternalNote.js +30 -0
  54. package/build/dist/Models/DatabaseModels/ScheduledMaintenanceInternalNote.js.map +1 -1
  55. package/build/dist/Models/DatabaseModels/ScheduledMaintenancePublicNote.js +30 -0
  56. package/build/dist/Models/DatabaseModels/ScheduledMaintenancePublicNote.js.map +1 -1
  57. package/build/dist/Server/API/LlmProviderAPI.js +36 -0
  58. package/build/dist/Server/API/LlmProviderAPI.js.map +1 -0
  59. package/build/dist/Server/API/MicrosoftTeamsAPI.js +2 -91
  60. package/build/dist/Server/API/MicrosoftTeamsAPI.js.map +1 -1
  61. package/build/dist/Server/API/SlackAPI.js +74 -0
  62. package/build/dist/Server/API/SlackAPI.js.map +1 -1
  63. package/build/dist/Server/API/StatusPageAPI.js +6 -0
  64. package/build/dist/Server/API/StatusPageAPI.js.map +1 -1
  65. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765477339178-MigrationName.js +30 -0
  66. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765477339178-MigrationName.js.map +1 -0
  67. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765540325149-MigrationName.js +22 -0
  68. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765540325149-MigrationName.js.map +1 -0
  69. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765540549739-MigrationName.js +39 -0
  70. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765540549739-MigrationName.js.map +1 -0
  71. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765544010078-MigrationName.js +18 -0
  72. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765544010078-MigrationName.js.map +1 -0
  73. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +8 -0
  74. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  75. package/build/dist/Server/Middleware/SlackAuthorization.js +4 -1
  76. package/build/dist/Server/Middleware/SlackAuthorization.js.map +1 -1
  77. package/build/dist/Server/Services/AlertInternalNoteService.js +24 -0
  78. package/build/dist/Server/Services/AlertInternalNoteService.js.map +1 -1
  79. package/build/dist/Server/Services/IncidentInternalNoteService.js +24 -0
  80. package/build/dist/Server/Services/IncidentInternalNoteService.js.map +1 -1
  81. package/build/dist/Server/Services/IncidentPublicNoteService.js +24 -0
  82. package/build/dist/Server/Services/IncidentPublicNoteService.js.map +1 -1
  83. package/build/dist/Server/Services/Index.js +2 -10
  84. package/build/dist/Server/Services/Index.js.map +1 -1
  85. package/build/dist/Server/Services/LlmProviderService.js +85 -0
  86. package/build/dist/Server/Services/LlmProviderService.js.map +1 -0
  87. package/build/dist/Server/Services/ScheduledMaintenanceInternalNoteService.js +24 -0
  88. package/build/dist/Server/Services/ScheduledMaintenanceInternalNoteService.js.map +1 -1
  89. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js +24 -0
  90. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js.map +1 -1
  91. package/build/dist/Server/Services/StatusPageService.js +3 -0
  92. package/build/dist/Server/Services/StatusPageService.js.map +1 -1
  93. package/build/dist/Server/Utils/Express.js.map +1 -1
  94. package/build/dist/Server/Utils/StartServer.js +5 -0
  95. package/build/dist/Server/Utils/StartServer.js.map +1 -1
  96. package/build/dist/Server/Utils/StatusPageResource.js +68 -0
  97. package/build/dist/Server/Utils/StatusPageResource.js.map +1 -0
  98. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js +73 -42
  99. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js.map +1 -1
  100. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js +13 -0
  101. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js.map +1 -1
  102. package/build/dist/Server/Utils/Workspace/Slack/Actions/Alert.js +143 -1
  103. package/build/dist/Server/Utils/Workspace/Slack/Actions/Alert.js.map +1 -1
  104. package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js +173 -1
  105. package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js.map +1 -1
  106. package/build/dist/Server/Utils/Workspace/Slack/Actions/ScheduledMaintenance.js +173 -1
  107. package/build/dist/Server/Utils/Workspace/Slack/Actions/ScheduledMaintenance.js.map +1 -1
  108. package/build/dist/Server/Utils/Workspace/Slack/Slack.js +92 -0
  109. package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
  110. package/build/dist/Server/Utils/Workspace/Slack/app-manifest.json +12 -2
  111. package/build/dist/Tests/Server/Utils/StatusPageResource.test.js +122 -0
  112. package/build/dist/Tests/Server/Utils/StatusPageResource.test.js.map +1 -0
  113. package/build/dist/Types/Icon/IconProp.js +1 -0
  114. package/build/dist/Types/Icon/IconProp.js.map +1 -1
  115. package/build/dist/Types/LLM/Index.js +4 -0
  116. package/build/dist/Types/LLM/Index.js.map +1 -0
  117. package/build/dist/Types/LLM/LlmType.js +8 -0
  118. package/build/dist/Types/LLM/LlmType.js.map +1 -0
  119. package/build/dist/Types/Permission.js +32 -97
  120. package/build/dist/Types/Permission.js.map +1 -1
  121. package/build/dist/UI/Components/Icon/Icon.js +3 -0
  122. package/build/dist/UI/Components/Icon/Icon.js.map +1 -1
  123. package/build/dist/UI/Components/Link/Link.js +4 -1
  124. package/build/dist/UI/Components/Link/Link.js.map +1 -1
  125. package/package.json +5 -1
  126. package/Models/DatabaseModels/CopilotAction.ts +0 -772
  127. package/Models/DatabaseModels/CopilotActionTypePriority.ts +0 -340
  128. package/Models/DatabaseModels/CopilotCodeRepository.ts +0 -637
  129. package/Models/DatabaseModels/ServiceCopilotCodeRepository.ts +0 -544
  130. package/Server/API/CopilotActionAPI.ts +0 -418
  131. package/Server/API/CopilotCodeRepositoryAPI.ts +0 -127
  132. package/Server/API/CopilotPullRequestAPI.ts +0 -243
  133. package/Server/Docs/CodeRepository.md +0 -43
  134. package/Server/Middleware/CodeRepositoryAuthorization.ts +0 -50
  135. package/Server/Services/CopilotActionService.ts +0 -10
  136. package/Server/Services/CopilotActionTypePriorityService.ts +0 -67
  137. package/Server/Services/CopilotCodeRepositoryService.ts +0 -62
  138. package/Server/Services/CopilotPullRequestService.ts +0 -10
  139. package/Server/Services/ServiceCopilotCodeRepositoryService.ts +0 -10
  140. package/Types/Copilot/CopilotActionProps/DirectoryActionProp.ts +0 -3
  141. package/Types/Copilot/CopilotActionProps/ExceptionActionProp.ts +0 -4
  142. package/Types/Copilot/CopilotActionProps/FileActionProp.ts +0 -7
  143. package/Types/Copilot/CopilotActionProps/FunctionActionProp.ts +0 -5
  144. package/Types/Copilot/CopilotActionProps/Index.ts +0 -96
  145. package/Types/Copilot/CopilotActionProps/SpanActionProp.ts +0 -4
  146. package/Types/Copilot/CopilotActionStatus.ts +0 -114
  147. package/Types/Copilot/CopilotActionType.ts +0 -212
  148. package/build/dist/Models/DatabaseModels/CopilotAction.js +0 -793
  149. package/build/dist/Models/DatabaseModels/CopilotAction.js.map +0 -1
  150. package/build/dist/Models/DatabaseModels/CopilotActionTypePriority.js +0 -358
  151. package/build/dist/Models/DatabaseModels/CopilotActionTypePriority.js.map +0 -1
  152. package/build/dist/Models/DatabaseModels/CopilotCodeRepository.js +0 -656
  153. package/build/dist/Models/DatabaseModels/CopilotCodeRepository.js.map +0 -1
  154. package/build/dist/Models/DatabaseModels/CopilotPullRequest.js.map +0 -1
  155. package/build/dist/Models/DatabaseModels/ServiceCopilotCodeRepository.js +0 -561
  156. package/build/dist/Models/DatabaseModels/ServiceCopilotCodeRepository.js.map +0 -1
  157. package/build/dist/Server/API/CopilotActionAPI.js +0 -295
  158. package/build/dist/Server/API/CopilotActionAPI.js.map +0 -1
  159. package/build/dist/Server/API/CopilotCodeRepositoryAPI.js +0 -91
  160. package/build/dist/Server/API/CopilotCodeRepositoryAPI.js.map +0 -1
  161. package/build/dist/Server/API/CopilotPullRequestAPI.js +0 -166
  162. package/build/dist/Server/API/CopilotPullRequestAPI.js.map +0 -1
  163. package/build/dist/Server/Middleware/CodeRepositoryAuthorization.js +0 -48
  164. package/build/dist/Server/Middleware/CodeRepositoryAuthorization.js.map +0 -1
  165. package/build/dist/Server/Services/CopilotActionService.js +0 -9
  166. package/build/dist/Server/Services/CopilotActionService.js.map +0 -1
  167. package/build/dist/Server/Services/CopilotActionTypePriorityService.js +0 -61
  168. package/build/dist/Server/Services/CopilotActionTypePriorityService.js.map +0 -1
  169. package/build/dist/Server/Services/CopilotCodeRepositoryService.js +0 -61
  170. package/build/dist/Server/Services/CopilotCodeRepositoryService.js.map +0 -1
  171. package/build/dist/Server/Services/CopilotPullRequestService.js +0 -9
  172. package/build/dist/Server/Services/CopilotPullRequestService.js.map +0 -1
  173. package/build/dist/Server/Services/ServiceCopilotCodeRepositoryService.js +0 -9
  174. package/build/dist/Server/Services/ServiceCopilotCodeRepositoryService.js.map +0 -1
  175. package/build/dist/Types/Copilot/CopilotActionProps/DirectoryActionProp.js +0 -2
  176. package/build/dist/Types/Copilot/CopilotActionProps/DirectoryActionProp.js.map +0 -1
  177. package/build/dist/Types/Copilot/CopilotActionProps/ExceptionActionProp.js +0 -2
  178. package/build/dist/Types/Copilot/CopilotActionProps/ExceptionActionProp.js.map +0 -1
  179. package/build/dist/Types/Copilot/CopilotActionProps/FileActionProp.js +0 -2
  180. package/build/dist/Types/Copilot/CopilotActionProps/FileActionProp.js.map +0 -1
  181. package/build/dist/Types/Copilot/CopilotActionProps/FunctionActionProp.js +0 -2
  182. package/build/dist/Types/Copilot/CopilotActionProps/FunctionActionProp.js.map +0 -1
  183. package/build/dist/Types/Copilot/CopilotActionProps/Index.js +0 -64
  184. package/build/dist/Types/Copilot/CopilotActionProps/Index.js.map +0 -1
  185. package/build/dist/Types/Copilot/CopilotActionProps/SpanActionProp.js +0 -2
  186. package/build/dist/Types/Copilot/CopilotActionProps/SpanActionProp.js.map +0 -1
  187. package/build/dist/Types/Copilot/CopilotActionStatus.js +0 -96
  188. package/build/dist/Types/Copilot/CopilotActionStatus.js.map +0 -1
  189. package/build/dist/Types/Copilot/CopilotActionType.js +0 -175
  190. package/build/dist/Types/Copilot/CopilotActionType.js.map +0 -1
@@ -1,243 +0,0 @@
1
- import CopilotCodeRepository from "../../Models/DatabaseModels/CopilotCodeRepository";
2
- import CopilotPullRequestService, {
3
- Service as CopilotPullRequestServiceType,
4
- } from "../Services/CopilotPullRequestService";
5
- import {
6
- ExpressRequest,
7
- ExpressResponse,
8
- NextFunction,
9
- } from "../Utils/Express";
10
- import Response from "../Utils/Response";
11
- import BaseAPI from "./BaseAPI";
12
- import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
13
- import BadDataException from "../../Types/Exception/BadDataException";
14
- import ObjectID from "../../Types/ObjectID";
15
- import CopilotCodeRepositoryService from "../Services/CopilotCodeRepositoryService";
16
- import CodeRepositoryAuthorization from "../Middleware/CodeRepositoryAuthorization";
17
- import CopilotPullRequest from "../../Models/DatabaseModels/CopilotPullRequest";
18
- import PullRequestState from "../../Types/CodeRepository/PullRequestState";
19
-
20
- export default class CopilotPullRequestAPI extends BaseAPI<
21
- CopilotPullRequest,
22
- CopilotPullRequestServiceType
23
- > {
24
- public constructor() {
25
- super(CopilotPullRequest, CopilotPullRequestService);
26
-
27
- this.router.get(
28
- `${new this.entityType()
29
- .getCrudApiPath()
30
- ?.toString()}/get-pending-pull-requests/:secretkey`,
31
- CodeRepositoryAuthorization.isAuthorizedRepository,
32
- async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
33
- try {
34
- const secretkey: string = req.params["secretkey"]!;
35
-
36
- if (!secretkey) {
37
- throw new BadDataException("Secret key is required");
38
- }
39
-
40
- const codeRepository: CopilotCodeRepository | null =
41
- await CopilotCodeRepositoryService.findOneBy({
42
- query: {
43
- secretToken: new ObjectID(secretkey),
44
- },
45
- select: {
46
- _id: true,
47
- },
48
- props: {
49
- isRoot: true,
50
- },
51
- });
52
-
53
- if (!codeRepository) {
54
- throw new BadDataException(
55
- "Code repository not found. Secret key is invalid.",
56
- );
57
- }
58
-
59
- const copilotPullRequests: Array<CopilotPullRequest> =
60
- await CopilotPullRequestService.findBy({
61
- query: {
62
- codeRepositoryId: codeRepository.id!,
63
- copilotPullRequestStatus: PullRequestState.Open, // only get pending pull requests
64
- },
65
- select: {
66
- _id: true,
67
- codeRepositoryId: true,
68
- projectId: true,
69
- copilotPullRequestStatus: true,
70
- pullRequestId: true,
71
- isSetupPullRequest: true,
72
- serviceCatalogId: true,
73
- serviceRepositoryId: true,
74
- },
75
- skip: 0,
76
- limit: LIMIT_PER_PROJECT,
77
- props: {
78
- isRoot: true,
79
- },
80
- });
81
-
82
- return Response.sendJsonObjectResponse(req, res, {
83
- copilotPullRequests: CopilotPullRequest.toJSONArray(
84
- copilotPullRequests,
85
- CopilotPullRequest,
86
- ),
87
- });
88
- } catch (err) {
89
- next(err);
90
- }
91
- },
92
- );
93
-
94
- this.router.post(
95
- `${new this.entityType()
96
- .getCrudApiPath()
97
- ?.toString()}/add-pull-request/:secretkey`,
98
- CodeRepositoryAuthorization.isAuthorizedRepository,
99
- async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
100
- try {
101
- const secretkey: string = req.params["secretkey"]!;
102
-
103
- if (!secretkey) {
104
- throw new BadDataException("Secret key is required");
105
- }
106
-
107
- const codeRepository: CopilotCodeRepository | null =
108
- await CopilotCodeRepositoryService.findOneBy({
109
- query: {
110
- secretToken: new ObjectID(secretkey),
111
- },
112
- select: {
113
- _id: true,
114
- projectId: true,
115
- },
116
- props: {
117
- isRoot: true,
118
- },
119
- });
120
-
121
- if (!codeRepository) {
122
- throw new BadDataException(
123
- "Code repository not found. Secret key is invalid.",
124
- );
125
- }
126
-
127
- if (!req.body["copilotPullRequest"]) {
128
- throw new BadDataException("Copilot pull request is required");
129
- }
130
-
131
- const copilotPullRequest: CopilotPullRequest =
132
- CopilotPullRequest.fromJSON(
133
- req.body["copilotPullRequest"],
134
- CopilotPullRequest,
135
- ) as CopilotPullRequest;
136
-
137
- copilotPullRequest.codeRepositoryId = codeRepository.id!;
138
- copilotPullRequest.projectId = codeRepository.projectId!;
139
- copilotPullRequest.copilotPullRequestStatus = PullRequestState.Open;
140
-
141
- const createdPullRequest: CopilotPullRequest =
142
- await CopilotPullRequestService.create({
143
- data: copilotPullRequest,
144
- props: {
145
- isRoot: true,
146
- },
147
- });
148
-
149
- return Response.sendEntityResponse(
150
- req,
151
- res,
152
- createdPullRequest,
153
- CopilotPullRequest,
154
- );
155
- } catch (err) {
156
- next(err);
157
- }
158
- },
159
- );
160
-
161
- this.router.post(
162
- `${new this.entityType()
163
- .getCrudApiPath()
164
- ?.toString()}/update-pull-request-status/:secretkey`,
165
- CodeRepositoryAuthorization.isAuthorizedRepository,
166
- async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
167
- try {
168
- const secretkey: string = req.params["secretkey"]!;
169
-
170
- if (!secretkey) {
171
- throw new BadDataException("Secret key is required");
172
- }
173
-
174
- const codeRepository: CopilotCodeRepository | null =
175
- await CopilotCodeRepositoryService.findOneBy({
176
- query: {
177
- secretToken: new ObjectID(secretkey),
178
- },
179
- select: {
180
- _id: true,
181
- projectId: true,
182
- },
183
- props: {
184
- isRoot: true,
185
- },
186
- });
187
-
188
- if (!codeRepository) {
189
- throw new BadDataException(
190
- "Code repository not found. Secret key is invalid.",
191
- );
192
- }
193
-
194
- if (!req.body["copilotPullRequestId"]) {
195
- throw new BadDataException("Copilot pull request is required");
196
- }
197
-
198
- // check copilotPullRequestStatus
199
-
200
- if (!req.body["copilotPullRequestStatus"]) {
201
- throw new BadDataException(
202
- "Copilot pull request status is required",
203
- );
204
- }
205
-
206
- const copilotPullRequestId: ObjectID = new ObjectID(
207
- req.body["copilotPullRequestId"],
208
- );
209
-
210
- const copilotPullRequest: CopilotPullRequest | null =
211
- await CopilotPullRequestService.findOneById({
212
- id: copilotPullRequestId,
213
- select: {
214
- copilotPullRequestStatus: true,
215
- pullRequestId: true,
216
- },
217
- props: {
218
- isRoot: true,
219
- },
220
- });
221
-
222
- if (!copilotPullRequest) {
223
- throw new BadDataException("Copilot pull request not found");
224
- }
225
-
226
- await CopilotPullRequestService.updateOneById({
227
- id: copilotPullRequestId,
228
- data: {
229
- copilotPullRequestStatus: req.body["copilotPullRequestStatus"],
230
- },
231
- props: {
232
- isRoot: true,
233
- },
234
- });
235
-
236
- return Response.sendEmptySuccessResponse(req, res);
237
- } catch (err) {
238
- next(err);
239
- }
240
- },
241
- );
242
- }
243
- }
@@ -1,43 +0,0 @@
1
- # Code Repository
2
-
3
- ```javascript
4
- const branchName: string = 'test-branch-11';
5
-
6
- await CodeRepositoryUtil.createOrCheckoutBranch({
7
- serviceRepository: serviceRepository,
8
- branchName: branchName,
9
- });
10
-
11
- // test code from here.
12
- const file: CodeRepositoryFile | undefined =
13
- filesInService[Object.keys(filesInService)[0]!];
14
-
15
- await CodeRepositoryUtil.writeToFile({
16
- filePath: file!.filePath!,
17
- content: 'Hello World',
18
- });
19
-
20
- // commit the changes
21
-
22
- await CodeRepositoryUtil.addFilesToGit({
23
- filePaths: [file!.filePath!],
24
- });
25
-
26
- await CodeRepositoryUtil.commitChanges({
27
- message: 'Test commit',
28
- });
29
-
30
- await CodeRepositoryUtil.pushChanges({
31
- branchName: branchName,
32
- serviceRepository: serviceRepository,
33
- });
34
-
35
- // create a pull request
36
-
37
- await CodeRepositoryUtil.createPullRequest({
38
- title: 'Test PR',
39
- body: 'Test PR body',
40
- branchName: branchName,
41
- serviceRepository: serviceRepository,
42
- });
43
- ```
@@ -1,50 +0,0 @@
1
- import BadDataException from "../../Types/Exception/BadDataException";
2
- import {
3
- ExpressRequest,
4
- ExpressResponse,
5
- NextFunction,
6
- } from "../Utils/Express";
7
- import CopilotCodeRepository from "../../Models/DatabaseModels/CopilotCodeRepository";
8
- import CopilotCodeRepositoryService from "../Services/CopilotCodeRepositoryService";
9
- import ObjectID from "../../Types/ObjectID";
10
- import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
11
-
12
- export default class CopilotCodeRepositoryAuthorization {
13
- @CaptureSpan()
14
- public static async isAuthorizedRepository(
15
- req: ExpressRequest,
16
- _res: ExpressResponse,
17
- next: NextFunction,
18
- ): Promise<void> {
19
- try {
20
- const secretkey: string = req.params["secretkey"]!;
21
-
22
- if (!secretkey) {
23
- throw new BadDataException("Secret key is required");
24
- }
25
-
26
- const CopilotCodeRepository: CopilotCodeRepository | null =
27
- await CopilotCodeRepositoryService.findOneBy({
28
- query: {
29
- secretToken: new ObjectID(secretkey),
30
- },
31
- select: {
32
- _id: true,
33
- },
34
- props: {
35
- isRoot: true,
36
- },
37
- });
38
-
39
- if (!CopilotCodeRepository) {
40
- throw new BadDataException(
41
- "Code repository not found. Secret key is invalid.",
42
- );
43
- }
44
-
45
- next();
46
- } catch (err) {
47
- next(err);
48
- }
49
- }
50
- }
@@ -1,10 +0,0 @@
1
- import DatabaseService from "./DatabaseService";
2
- import Model from "../../Models/DatabaseModels/CopilotAction";
3
-
4
- export class Service extends DatabaseService<Model> {
5
- public constructor() {
6
- super(Model);
7
- }
8
- }
9
-
10
- export default new Service();
@@ -1,67 +0,0 @@
1
- import CopilotActionType from "../../Types/Copilot/CopilotActionType";
2
- import BadDataException from "../../Types/Exception/BadDataException";
3
- import ObjectID from "../../Types/ObjectID";
4
- import CreateBy from "../Types/Database/CreateBy";
5
- import { OnCreate } from "../Types/Database/Hooks";
6
- import DatabaseService from "./DatabaseService";
7
- import Model from "../../Models/DatabaseModels/CopilotActionTypePriority";
8
- import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
9
- export class Service extends DatabaseService<Model> {
10
- public constructor() {
11
- super(Model);
12
- }
13
-
14
- @CaptureSpan()
15
- protected override async onBeforeCreate(
16
- createBy: CreateBy<Model>,
17
- ): Promise<OnCreate<Model>> {
18
- // check if the action exits witht he same name exists in the same repo.
19
-
20
- const actionType: CopilotActionType | undefined = createBy.data.actionType;
21
- const codeRepositoryId: ObjectID | undefined =
22
- createBy.data.codeRepositoryId;
23
-
24
- if (!actionType) {
25
- throw new BadDataException("ActionType is required");
26
- }
27
-
28
- if (!codeRepositoryId) {
29
- throw new BadDataException("CodeRepositoryId is required");
30
- }
31
-
32
- const existingItem: Model | null = await this.findOneBy({
33
- query: {
34
- actionType,
35
- codeRepositoryId,
36
- },
37
- props: {
38
- isRoot: true,
39
- },
40
- });
41
-
42
- if (existingItem) {
43
- throw new BadDataException(
44
- "Action Type already exists for this repository.",
45
- );
46
- }
47
-
48
- // check if the priority is in between 1 and 5.
49
-
50
- const priority: number | undefined = createBy.data.priority;
51
-
52
- if (!priority) {
53
- throw new BadDataException("Priority is required");
54
- }
55
-
56
- if (priority < 1 || priority > 5) {
57
- throw new BadDataException("Priority must be between 1 and 5");
58
- }
59
-
60
- return {
61
- createBy: createBy,
62
- carryForward: null,
63
- };
64
- }
65
- }
66
-
67
- export default new Service();
@@ -1,62 +0,0 @@
1
- import CreateBy from "../Types/Database/CreateBy";
2
- import { OnCreate } from "../Types/Database/Hooks";
3
- import DatabaseService from "./DatabaseService";
4
- import ObjectID from "../../Types/ObjectID";
5
- import Model from "../../Models/DatabaseModels/CopilotCodeRepository";
6
- import {
7
- CopilotActionTypeData,
8
- CopilotActionTypeUtil,
9
- } from "../../Types/Copilot/CopilotActionType";
10
- import CopilotActionTypePriority from "../../Models/DatabaseModels/CopilotActionTypePriority";
11
- import CopilotActionTypePriorityService from "./CopilotActionTypePriorityService";
12
- import CaptureSpan from "../Utils/Telemetry/CaptureSpan";
13
- export class Service extends DatabaseService<Model> {
14
- public constructor() {
15
- super(Model);
16
- }
17
-
18
- @CaptureSpan()
19
- protected override async onBeforeCreate(
20
- createBy: CreateBy<Model>,
21
- ): Promise<OnCreate<Model>> {
22
- createBy.data.secretToken = ObjectID.generate();
23
-
24
- return {
25
- carryForward: null,
26
- createBy: createBy,
27
- };
28
- }
29
-
30
- @CaptureSpan()
31
- protected override async onCreateSuccess(
32
- _onCreate: OnCreate<Model>,
33
- createdItem: Model,
34
- ): Promise<Model> {
35
- // add all the actions.
36
-
37
- const repo: Model = createdItem;
38
-
39
- const defaultCopilotActionTypes: Array<CopilotActionTypeData> =
40
- CopilotActionTypeUtil.getAllCopilotActionTypes();
41
-
42
- for (const defaultAction of defaultCopilotActionTypes) {
43
- const copilotActionTypePriority: CopilotActionTypePriority =
44
- new CopilotActionTypePriority();
45
- copilotActionTypePriority.projectId = repo.projectId!;
46
- copilotActionTypePriority.actionType = defaultAction.type;
47
- copilotActionTypePriority.priority = defaultAction.defaultPriority;
48
- copilotActionTypePriority.codeRepositoryId = repo.id!;
49
-
50
- await CopilotActionTypePriorityService.create({
51
- data: copilotActionTypePriority,
52
- props: {
53
- isRoot: true,
54
- },
55
- });
56
- }
57
-
58
- return createdItem;
59
- }
60
- }
61
-
62
- export default new Service();
@@ -1,10 +0,0 @@
1
- import DatabaseService from "./DatabaseService";
2
- import Model from "../../Models/DatabaseModels/CopilotPullRequest";
3
-
4
- export class Service extends DatabaseService<Model> {
5
- public constructor() {
6
- super(Model);
7
- }
8
- }
9
-
10
- export default new Service();
@@ -1,10 +0,0 @@
1
- import DatabaseService from "./DatabaseService";
2
- import Model from "../../Models/DatabaseModels/ServiceCopilotCodeRepository";
3
-
4
- export class Service extends DatabaseService<Model> {
5
- public constructor() {
6
- super(Model);
7
- }
8
- }
9
-
10
- export default new Service();
@@ -1,3 +0,0 @@
1
- export default interface DirectoryActionProp {
2
- directoryPath: string;
3
- }
@@ -1,4 +0,0 @@
1
- export default interface ExceptionActionProp {
2
- fingerprint: string;
3
- message: string;
4
- }
@@ -1,7 +0,0 @@
1
- export default interface FileActionProp {
2
- filePath: string;
3
-
4
- // if startLineNumber and endLineNumber are not provided, the whole file will be considered
5
- startLineNumber?: number | undefined;
6
- endLineNumber?: number | undefined;
7
- }
@@ -1,5 +0,0 @@
1
- export default interface FunctionActionProp {
2
- filePath: string;
3
- className?: string | undefined; // some languages are not class based.
4
- functionName: string;
5
- }
@@ -1,96 +0,0 @@
1
- import DirectoryActionProp from "./DirectoryActionProp";
2
- import FileActionProp from "./FileActionProp";
3
- import ExceptionActionProp from "./ExceptionActionProp";
4
- import SpanActionProp from "./SpanActionProp";
5
- import FunctionActionProp from "./FunctionActionProp";
6
- import CopilotActionType from "../CopilotActionType";
7
-
8
- type CopilotActionProp =
9
- | DirectoryActionProp
10
- | FileActionProp
11
- | ExceptionActionProp
12
- | SpanActionProp
13
- | FunctionActionProp;
14
-
15
- export enum CopilotActionPropType {
16
- Directory = "Directory",
17
- File = "File",
18
- Exception = "Exception",
19
- Span = "Span",
20
- Metric = "Metric",
21
- Function = "Function",
22
- }
23
-
24
- export class CopilotActionPropUtil {
25
- public static getCopilotActionPropByActionType(
26
- actionType: CopilotActionType,
27
- ): CopilotActionPropType {
28
- if (actionType === CopilotActionType.FIX_EXCEPTIONS) {
29
- return CopilotActionPropType.Exception;
30
- }
31
-
32
- if (actionType === CopilotActionType.FIX_PERFORMANCE_ISSUES) {
33
- return CopilotActionPropType.Span;
34
- }
35
-
36
- if (actionType === CopilotActionType.FIX_BUGS) {
37
- return CopilotActionPropType.Function;
38
- }
39
-
40
- if (actionType === CopilotActionType.IMPROVE_LOGS) {
41
- return CopilotActionPropType.File;
42
- }
43
-
44
- if (actionType === CopilotActionType.IMPROVE_SPANS) {
45
- return CopilotActionPropType.Function;
46
- }
47
-
48
- if (actionType === CopilotActionType.IMPROVE_METRICS) {
49
- return CopilotActionPropType.Function;
50
- }
51
-
52
- if (actionType === CopilotActionType.ADD_LOGS) {
53
- return CopilotActionPropType.File;
54
- }
55
-
56
- if (actionType === CopilotActionType.ADD_SPANS) {
57
- return CopilotActionPropType.File;
58
- }
59
-
60
- if (actionType === CopilotActionType.ADD_METRICS) {
61
- return CopilotActionPropType.Function;
62
- }
63
-
64
- if (actionType === CopilotActionType.REFACTOR_CODE) {
65
- return CopilotActionPropType.Function;
66
- }
67
-
68
- if (actionType === CopilotActionType.WRITE_UNIT_TESTS) {
69
- return CopilotActionPropType.Function;
70
- }
71
-
72
- if (actionType === CopilotActionType.IMPROVE_UNIT_TESTS) {
73
- return CopilotActionPropType.Function;
74
- }
75
-
76
- if (actionType === CopilotActionType.IMPROVE_COMMENTS) {
77
- return CopilotActionPropType.File;
78
- }
79
-
80
- if (actionType === CopilotActionType.ADD_COMMENTS) {
81
- return CopilotActionPropType.File;
82
- }
83
-
84
- if (actionType === CopilotActionType.ADD_README) {
85
- return CopilotActionPropType.Directory;
86
- }
87
-
88
- if (actionType === CopilotActionType.IMPROVE_README) {
89
- return CopilotActionPropType.File;
90
- }
91
-
92
- return CopilotActionPropType.File;
93
- }
94
- }
95
-
96
- export default CopilotActionProp;
@@ -1,4 +0,0 @@
1
- export default interface SpanActionProp {
2
- traceId: string;
3
- spanId?: string;
4
- }