@oneuptime/common 9.2.11 → 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 (193) 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/Monitor/MonitorStep.ts +14 -0
  41. package/Types/Permission.ts +38 -113
  42. package/UI/Components/Icon/Icon.tsx +8 -0
  43. package/UI/Components/Link/Link.tsx +5 -1
  44. package/build/dist/Models/DatabaseModels/AlertInternalNote.js +30 -0
  45. package/build/dist/Models/DatabaseModels/AlertInternalNote.js.map +1 -1
  46. package/build/dist/Models/DatabaseModels/IncidentInternalNote.js +30 -0
  47. package/build/dist/Models/DatabaseModels/IncidentInternalNote.js.map +1 -1
  48. package/build/dist/Models/DatabaseModels/IncidentPublicNote.js +30 -0
  49. package/build/dist/Models/DatabaseModels/IncidentPublicNote.js.map +1 -1
  50. package/build/dist/Models/DatabaseModels/Index.js +2 -10
  51. package/build/dist/Models/DatabaseModels/Index.js.map +1 -1
  52. package/build/dist/Models/DatabaseModels/{CopilotPullRequest.js → LlmProvider.js} +263 -255
  53. package/build/dist/Models/DatabaseModels/LlmProvider.js.map +1 -0
  54. package/build/dist/Models/DatabaseModels/ScheduledMaintenanceInternalNote.js +30 -0
  55. package/build/dist/Models/DatabaseModels/ScheduledMaintenanceInternalNote.js.map +1 -1
  56. package/build/dist/Models/DatabaseModels/ScheduledMaintenancePublicNote.js +30 -0
  57. package/build/dist/Models/DatabaseModels/ScheduledMaintenancePublicNote.js.map +1 -1
  58. package/build/dist/Server/API/LlmProviderAPI.js +36 -0
  59. package/build/dist/Server/API/LlmProviderAPI.js.map +1 -0
  60. package/build/dist/Server/API/MicrosoftTeamsAPI.js +2 -91
  61. package/build/dist/Server/API/MicrosoftTeamsAPI.js.map +1 -1
  62. package/build/dist/Server/API/SlackAPI.js +74 -0
  63. package/build/dist/Server/API/SlackAPI.js.map +1 -1
  64. package/build/dist/Server/API/StatusPageAPI.js +6 -0
  65. package/build/dist/Server/API/StatusPageAPI.js.map +1 -1
  66. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765477339178-MigrationName.js +30 -0
  67. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765477339178-MigrationName.js.map +1 -0
  68. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765540325149-MigrationName.js +22 -0
  69. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765540325149-MigrationName.js.map +1 -0
  70. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765540549739-MigrationName.js +39 -0
  71. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765540549739-MigrationName.js.map +1 -0
  72. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765544010078-MigrationName.js +18 -0
  73. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/1765544010078-MigrationName.js.map +1 -0
  74. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js +8 -0
  75. package/build/dist/Server/Infrastructure/Postgres/SchemaMigrations/Index.js.map +1 -1
  76. package/build/dist/Server/Middleware/SlackAuthorization.js +4 -1
  77. package/build/dist/Server/Middleware/SlackAuthorization.js.map +1 -1
  78. package/build/dist/Server/Services/AlertInternalNoteService.js +24 -0
  79. package/build/dist/Server/Services/AlertInternalNoteService.js.map +1 -1
  80. package/build/dist/Server/Services/IncidentInternalNoteService.js +24 -0
  81. package/build/dist/Server/Services/IncidentInternalNoteService.js.map +1 -1
  82. package/build/dist/Server/Services/IncidentPublicNoteService.js +24 -0
  83. package/build/dist/Server/Services/IncidentPublicNoteService.js.map +1 -1
  84. package/build/dist/Server/Services/Index.js +2 -10
  85. package/build/dist/Server/Services/Index.js.map +1 -1
  86. package/build/dist/Server/Services/LlmProviderService.js +85 -0
  87. package/build/dist/Server/Services/LlmProviderService.js.map +1 -0
  88. package/build/dist/Server/Services/ScheduledMaintenanceInternalNoteService.js +24 -0
  89. package/build/dist/Server/Services/ScheduledMaintenanceInternalNoteService.js.map +1 -1
  90. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js +24 -0
  91. package/build/dist/Server/Services/ScheduledMaintenancePublicNoteService.js.map +1 -1
  92. package/build/dist/Server/Services/StatusPageService.js +3 -0
  93. package/build/dist/Server/Services/StatusPageService.js.map +1 -1
  94. package/build/dist/Server/Utils/Express.js.map +1 -1
  95. package/build/dist/Server/Utils/StartServer.js +5 -0
  96. package/build/dist/Server/Utils/StartServer.js.map +1 -1
  97. package/build/dist/Server/Utils/StatusPageResource.js +68 -0
  98. package/build/dist/Server/Utils/StatusPageResource.js.map +1 -0
  99. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js +73 -42
  100. package/build/dist/Server/Utils/Workspace/MicrosoftTeams/MicrosoftTeams.js.map +1 -1
  101. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js +13 -0
  102. package/build/dist/Server/Utils/Workspace/Slack/Actions/ActionTypes.js.map +1 -1
  103. package/build/dist/Server/Utils/Workspace/Slack/Actions/Alert.js +143 -1
  104. package/build/dist/Server/Utils/Workspace/Slack/Actions/Alert.js.map +1 -1
  105. package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js +173 -1
  106. package/build/dist/Server/Utils/Workspace/Slack/Actions/Incident.js.map +1 -1
  107. package/build/dist/Server/Utils/Workspace/Slack/Actions/ScheduledMaintenance.js +173 -1
  108. package/build/dist/Server/Utils/Workspace/Slack/Actions/ScheduledMaintenance.js.map +1 -1
  109. package/build/dist/Server/Utils/Workspace/Slack/Slack.js +92 -0
  110. package/build/dist/Server/Utils/Workspace/Slack/Slack.js.map +1 -1
  111. package/build/dist/Server/Utils/Workspace/Slack/app-manifest.json +12 -2
  112. package/build/dist/Tests/Server/Utils/StatusPageResource.test.js +122 -0
  113. package/build/dist/Tests/Server/Utils/StatusPageResource.test.js.map +1 -0
  114. package/build/dist/Types/Icon/IconProp.js +1 -0
  115. package/build/dist/Types/Icon/IconProp.js.map +1 -1
  116. package/build/dist/Types/LLM/Index.js +4 -0
  117. package/build/dist/Types/LLM/Index.js.map +1 -0
  118. package/build/dist/Types/LLM/LlmType.js +8 -0
  119. package/build/dist/Types/LLM/LlmType.js.map +1 -0
  120. package/build/dist/Types/Monitor/MonitorStep.js +10 -0
  121. package/build/dist/Types/Monitor/MonitorStep.js.map +1 -1
  122. package/build/dist/Types/Permission.js +32 -97
  123. package/build/dist/Types/Permission.js.map +1 -1
  124. package/build/dist/UI/Components/Icon/Icon.js +3 -0
  125. package/build/dist/UI/Components/Icon/Icon.js.map +1 -1
  126. package/build/dist/UI/Components/Link/Link.js +4 -1
  127. package/build/dist/UI/Components/Link/Link.js.map +1 -1
  128. package/package.json +5 -1
  129. package/Models/DatabaseModels/CopilotAction.ts +0 -772
  130. package/Models/DatabaseModels/CopilotActionTypePriority.ts +0 -340
  131. package/Models/DatabaseModels/CopilotCodeRepository.ts +0 -637
  132. package/Models/DatabaseModels/ServiceCopilotCodeRepository.ts +0 -544
  133. package/Server/API/CopilotActionAPI.ts +0 -418
  134. package/Server/API/CopilotCodeRepositoryAPI.ts +0 -127
  135. package/Server/API/CopilotPullRequestAPI.ts +0 -243
  136. package/Server/Docs/CodeRepository.md +0 -43
  137. package/Server/Middleware/CodeRepositoryAuthorization.ts +0 -50
  138. package/Server/Services/CopilotActionService.ts +0 -10
  139. package/Server/Services/CopilotActionTypePriorityService.ts +0 -67
  140. package/Server/Services/CopilotCodeRepositoryService.ts +0 -62
  141. package/Server/Services/CopilotPullRequestService.ts +0 -10
  142. package/Server/Services/ServiceCopilotCodeRepositoryService.ts +0 -10
  143. package/Types/Copilot/CopilotActionProps/DirectoryActionProp.ts +0 -3
  144. package/Types/Copilot/CopilotActionProps/ExceptionActionProp.ts +0 -4
  145. package/Types/Copilot/CopilotActionProps/FileActionProp.ts +0 -7
  146. package/Types/Copilot/CopilotActionProps/FunctionActionProp.ts +0 -5
  147. package/Types/Copilot/CopilotActionProps/Index.ts +0 -96
  148. package/Types/Copilot/CopilotActionProps/SpanActionProp.ts +0 -4
  149. package/Types/Copilot/CopilotActionStatus.ts +0 -114
  150. package/Types/Copilot/CopilotActionType.ts +0 -212
  151. package/build/dist/Models/DatabaseModels/CopilotAction.js +0 -793
  152. package/build/dist/Models/DatabaseModels/CopilotAction.js.map +0 -1
  153. package/build/dist/Models/DatabaseModels/CopilotActionTypePriority.js +0 -358
  154. package/build/dist/Models/DatabaseModels/CopilotActionTypePriority.js.map +0 -1
  155. package/build/dist/Models/DatabaseModels/CopilotCodeRepository.js +0 -656
  156. package/build/dist/Models/DatabaseModels/CopilotCodeRepository.js.map +0 -1
  157. package/build/dist/Models/DatabaseModels/CopilotPullRequest.js.map +0 -1
  158. package/build/dist/Models/DatabaseModels/ServiceCopilotCodeRepository.js +0 -561
  159. package/build/dist/Models/DatabaseModels/ServiceCopilotCodeRepository.js.map +0 -1
  160. package/build/dist/Server/API/CopilotActionAPI.js +0 -295
  161. package/build/dist/Server/API/CopilotActionAPI.js.map +0 -1
  162. package/build/dist/Server/API/CopilotCodeRepositoryAPI.js +0 -91
  163. package/build/dist/Server/API/CopilotCodeRepositoryAPI.js.map +0 -1
  164. package/build/dist/Server/API/CopilotPullRequestAPI.js +0 -166
  165. package/build/dist/Server/API/CopilotPullRequestAPI.js.map +0 -1
  166. package/build/dist/Server/Middleware/CodeRepositoryAuthorization.js +0 -48
  167. package/build/dist/Server/Middleware/CodeRepositoryAuthorization.js.map +0 -1
  168. package/build/dist/Server/Services/CopilotActionService.js +0 -9
  169. package/build/dist/Server/Services/CopilotActionService.js.map +0 -1
  170. package/build/dist/Server/Services/CopilotActionTypePriorityService.js +0 -61
  171. package/build/dist/Server/Services/CopilotActionTypePriorityService.js.map +0 -1
  172. package/build/dist/Server/Services/CopilotCodeRepositoryService.js +0 -61
  173. package/build/dist/Server/Services/CopilotCodeRepositoryService.js.map +0 -1
  174. package/build/dist/Server/Services/CopilotPullRequestService.js +0 -9
  175. package/build/dist/Server/Services/CopilotPullRequestService.js.map +0 -1
  176. package/build/dist/Server/Services/ServiceCopilotCodeRepositoryService.js +0 -9
  177. package/build/dist/Server/Services/ServiceCopilotCodeRepositoryService.js.map +0 -1
  178. package/build/dist/Types/Copilot/CopilotActionProps/DirectoryActionProp.js +0 -2
  179. package/build/dist/Types/Copilot/CopilotActionProps/DirectoryActionProp.js.map +0 -1
  180. package/build/dist/Types/Copilot/CopilotActionProps/ExceptionActionProp.js +0 -2
  181. package/build/dist/Types/Copilot/CopilotActionProps/ExceptionActionProp.js.map +0 -1
  182. package/build/dist/Types/Copilot/CopilotActionProps/FileActionProp.js +0 -2
  183. package/build/dist/Types/Copilot/CopilotActionProps/FileActionProp.js.map +0 -1
  184. package/build/dist/Types/Copilot/CopilotActionProps/FunctionActionProp.js +0 -2
  185. package/build/dist/Types/Copilot/CopilotActionProps/FunctionActionProp.js.map +0 -1
  186. package/build/dist/Types/Copilot/CopilotActionProps/Index.js +0 -64
  187. package/build/dist/Types/Copilot/CopilotActionProps/Index.js.map +0 -1
  188. package/build/dist/Types/Copilot/CopilotActionProps/SpanActionProp.js +0 -2
  189. package/build/dist/Types/Copilot/CopilotActionProps/SpanActionProp.js.map +0 -1
  190. package/build/dist/Types/Copilot/CopilotActionStatus.js +0 -96
  191. package/build/dist/Types/Copilot/CopilotActionStatus.js.map +0 -1
  192. package/build/dist/Types/Copilot/CopilotActionType.js +0 -175
  193. package/build/dist/Types/Copilot/CopilotActionType.js.map +0 -1
@@ -1,418 +0,0 @@
1
- import CopilotCodeRepository from "../../Models/DatabaseModels/CopilotCodeRepository";
2
- import CopilotActionService, {
3
- Service as CopilotActionServiceType,
4
- } from "../Services/CopilotActionService";
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 CopilotAction from "../../Models/DatabaseModels/CopilotAction";
16
- import CopilotCodeRepositoryService from "../Services/CopilotCodeRepositoryService";
17
- import CodeRepositoryAuthorization from "../Middleware/CodeRepositoryAuthorization";
18
- import CopilotActionStatus from "../../Types/Copilot/CopilotActionStatus";
19
- import CopilotActionTypePriority from "../../Models/DatabaseModels/CopilotActionTypePriority";
20
- import CopilotActionTypePriorityService from "../Services/CopilotActionTypePriorityService";
21
- import SortOrder from "../../Types/BaseDatabase/SortOrder";
22
- import JSONFunctions from "../../Types/JSONFunctions";
23
- import CopilotActionType from "../../Types/Copilot/CopilotActionType";
24
- import { JSONObject } from "../../Types/JSON";
25
- import OneUptimeDate from "../../Types/Date";
26
-
27
- export default class CopilotActionAPI extends BaseAPI<
28
- CopilotAction,
29
- CopilotActionServiceType
30
- > {
31
- public constructor() {
32
- super(CopilotAction, CopilotActionService);
33
-
34
- this.router.get(
35
- `${new this.entityType()
36
- .getCrudApiPath()
37
- ?.toString()}/copilot-action-types-by-priority/:secretkey`,
38
- CodeRepositoryAuthorization.isAuthorizedRepository,
39
- async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
40
- try {
41
- const secretkey: string = req.params["secretkey"]!;
42
-
43
- if (!secretkey) {
44
- throw new BadDataException("Secret key is required");
45
- }
46
-
47
- const codeRepository: CopilotCodeRepository | null =
48
- await CopilotCodeRepositoryService.findOneBy({
49
- query: {
50
- secretToken: new ObjectID(secretkey),
51
- },
52
- select: {
53
- _id: true,
54
- },
55
- props: {
56
- isRoot: true,
57
- },
58
- });
59
-
60
- if (!codeRepository) {
61
- throw new BadDataException(
62
- "Code repository not found. Secret key is invalid.",
63
- );
64
- }
65
-
66
- const copilotActionTypes: Array<CopilotActionTypePriority> =
67
- await CopilotActionTypePriorityService.findBy({
68
- query: {
69
- codeRepositoryId: codeRepository.id!,
70
- },
71
- select: {
72
- _id: true,
73
- actionType: true,
74
- priority: true,
75
- },
76
- skip: 0,
77
- sort: {
78
- priority: SortOrder.Ascending,
79
- },
80
- limit: LIMIT_PER_PROJECT,
81
- props: {
82
- isRoot: true,
83
- },
84
- });
85
-
86
- return Response.sendJsonObjectResponse(req, res, {
87
- actionTypes: CopilotActionTypePriority.toJSONArray(
88
- copilotActionTypes,
89
- CopilotActionTypePriority,
90
- ),
91
- });
92
- } catch (err) {
93
- next(err);
94
- }
95
- },
96
- );
97
-
98
- this.router.get(
99
- `${new this.entityType()
100
- .getCrudApiPath()
101
- ?.toString()}/copilot-actions-in-queue/:secretkey`,
102
- CodeRepositoryAuthorization.isAuthorizedRepository,
103
- async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
104
- try {
105
- const secretkey: string = req.params["secretkey"]!;
106
-
107
- if (!secretkey) {
108
- throw new BadDataException("Secret key is required");
109
- }
110
-
111
- const serviceCatalogId: string = req.body["serviceCatalogId"]!;
112
-
113
- if (!serviceCatalogId) {
114
- throw new BadDataException("Service catalog id is required");
115
- }
116
-
117
- const codeRepository: CopilotCodeRepository | null =
118
- await CopilotCodeRepositoryService.findOneBy({
119
- query: {
120
- secretToken: new ObjectID(secretkey),
121
- },
122
- select: {
123
- _id: true,
124
- },
125
- props: {
126
- isRoot: true,
127
- },
128
- });
129
-
130
- if (!codeRepository) {
131
- throw new BadDataException(
132
- "Code repository not found. Secret key is invalid.",
133
- );
134
- }
135
-
136
- const copilotActions: Array<CopilotAction> =
137
- await CopilotActionService.findBy({
138
- query: {
139
- codeRepositoryId: codeRepository.id!,
140
- serviceCatalogId: new ObjectID(serviceCatalogId),
141
- copilotActionStatus: CopilotActionStatus.IN_QUEUE,
142
- },
143
- select: {
144
- _id: true,
145
- codeRepositoryId: true,
146
- serviceCatalogId: true,
147
- copilotActionStatus: true,
148
- copilotActionType: true,
149
- copilotActionProp: true,
150
- createdAt: true,
151
- copilotPullRequest: {
152
- _id: true,
153
- pullRequestId: true,
154
- copilotPullRequestStatus: true,
155
- },
156
- },
157
- skip: 0,
158
- limit: LIMIT_PER_PROJECT,
159
- props: {
160
- isRoot: true,
161
- },
162
- });
163
-
164
- return Response.sendJsonObjectResponse(req, res, {
165
- copilotActions: CopilotAction.toJSONArray(
166
- copilotActions,
167
- CopilotAction,
168
- ),
169
- });
170
- } catch (err) {
171
- next(err);
172
- }
173
- },
174
- );
175
-
176
- this.router.get(
177
- `${new this.entityType()
178
- .getCrudApiPath()
179
- ?.toString()}/get-copilot-action/:secretkey`,
180
- CodeRepositoryAuthorization.isAuthorizedRepository,
181
- async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
182
- try {
183
- const secretkey: string = req.params["secretkey"]!;
184
-
185
- if (!secretkey) {
186
- throw new BadDataException("Secret key is required");
187
- }
188
-
189
- const serviceCatalogId: string = req.body["serviceCatalogId"]!;
190
-
191
- if (!serviceCatalogId) {
192
- throw new BadDataException("Service catalog id is required");
193
- }
194
-
195
- const codeRepository: CopilotCodeRepository | null =
196
- await CopilotCodeRepositoryService.findOneBy({
197
- query: {
198
- secretToken: new ObjectID(secretkey),
199
- },
200
- select: {
201
- _id: true,
202
- },
203
- props: {
204
- isRoot: true,
205
- },
206
- });
207
-
208
- if (!codeRepository) {
209
- throw new BadDataException(
210
- "Code repository not found. Secret key is invalid.",
211
- );
212
- }
213
-
214
- const actionType: CopilotActionType = req.body["actionType"]!;
215
-
216
- if (!actionType) {
217
- throw new BadDataException("Action type is required");
218
- }
219
-
220
- const actionProps: JSONObject = req.body["actionProps"]!;
221
-
222
- const copilotAction: CopilotAction | null =
223
- await CopilotActionService.findOneBy({
224
- query: {
225
- codeRepositoryId: codeRepository.id!,
226
- serviceCatalogId: new ObjectID(serviceCatalogId),
227
- copilotActionType: actionType,
228
- copilotActionProp: actionProps as any,
229
- },
230
- select: {
231
- _id: true,
232
- codeRepositoryId: true,
233
- serviceCatalogId: true,
234
- copilotActionStatus: true,
235
- copilotActionType: true,
236
- createdAt: true,
237
- copilotPullRequest: {
238
- _id: true,
239
- pullRequestId: true,
240
- copilotPullRequestStatus: true,
241
- },
242
- },
243
- sort: {
244
- createdAt: SortOrder.Descending,
245
- },
246
- props: {
247
- isRoot: true,
248
- },
249
- });
250
-
251
- return Response.sendJsonObjectResponse(req, res, {
252
- copilotAction: copilotAction
253
- ? CopilotAction.toJSONObject(copilotAction, CopilotAction)
254
- : null,
255
- });
256
- } catch (err) {
257
- next(err);
258
- }
259
- },
260
- );
261
-
262
- this.router.post(
263
- `${new this.entityType()
264
- .getCrudApiPath()
265
- ?.toString()}/create-copilot-action/:secretkey`,
266
- CodeRepositoryAuthorization.isAuthorizedRepository,
267
- async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
268
- try {
269
- const secretkey: string = req.params["secretkey"]!;
270
-
271
- if (!secretkey) {
272
- throw new BadDataException("Secret key is required");
273
- }
274
-
275
- const codeRepository: CopilotCodeRepository | null =
276
- await CopilotCodeRepositoryService.findOneBy({
277
- query: {
278
- secretToken: new ObjectID(secretkey),
279
- },
280
- select: {
281
- _id: true,
282
- projectId: true,
283
- },
284
- props: {
285
- isRoot: true,
286
- },
287
- });
288
-
289
- if (!codeRepository) {
290
- throw new BadDataException(
291
- "Code repository not found. Secret key is invalid.",
292
- );
293
- }
294
-
295
- const copilotAction: CopilotAction = CopilotAction.fromJSON(
296
- req.body["copilotAction"],
297
- CopilotAction,
298
- ) as CopilotAction;
299
-
300
- copilotAction.codeRepositoryId = codeRepository.id!;
301
- copilotAction.projectId = codeRepository.projectId!;
302
- copilotAction.copilotActionStatus = CopilotActionStatus.IN_QUEUE;
303
-
304
- const createdAction: CopilotAction =
305
- await CopilotActionService.create({
306
- data: copilotAction,
307
- props: {
308
- isRoot: true,
309
- },
310
- });
311
-
312
- return Response.sendEntityResponse(
313
- req,
314
- res,
315
- createdAction,
316
- CopilotAction,
317
- );
318
- } catch (err) {
319
- next(err);
320
- }
321
- },
322
- );
323
-
324
- this.router.post(
325
- `${new this.entityType()
326
- .getCrudApiPath()
327
- ?.toString()}/update-copilot-action/:secretkey`,
328
- CodeRepositoryAuthorization.isAuthorizedRepository,
329
- async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
330
- try {
331
- const secretkey: string = req.params["secretkey"]!;
332
-
333
- if (!secretkey) {
334
- throw new BadDataException("Secret key is required");
335
- }
336
-
337
- const codeRepository: CopilotCodeRepository | null =
338
- await CopilotCodeRepositoryService.findOneBy({
339
- query: {
340
- secretToken: new ObjectID(secretkey),
341
- },
342
- select: {
343
- _id: true,
344
- projectId: true,
345
- },
346
- props: {
347
- isRoot: true,
348
- },
349
- });
350
-
351
- if (!codeRepository) {
352
- throw new BadDataException(
353
- "Code repository not found. Secret key is invalid.",
354
- );
355
- }
356
-
357
- req.body = JSONFunctions.deserialize(req.body);
358
-
359
- const {
360
- actionStatus,
361
- pullRequestId,
362
- commitHash,
363
- statusMessage,
364
- logs,
365
- actionId,
366
- }: {
367
- actionStatus: CopilotActionStatus;
368
- pullRequestId?: ObjectID | undefined;
369
- commitHash?: string | undefined;
370
- statusMessage?: string | undefined;
371
- logs?: Array<string> | undefined;
372
- actionId: ObjectID;
373
- } = req.body;
374
-
375
- const exisingAction: CopilotAction | null =
376
- await CopilotActionService.findOneBy({
377
- query: {
378
- _id: actionId,
379
- codeRepositoryId: codeRepository.id!,
380
- },
381
- select: {
382
- _id: true,
383
- },
384
- props: {
385
- isRoot: true,
386
- },
387
- });
388
-
389
- if (!exisingAction) {
390
- throw new BadDataException("Action not found");
391
- }
392
-
393
- await CopilotActionService.updateOneBy({
394
- query: {
395
- _id: actionId,
396
- codeRepositoryId: codeRepository.id!,
397
- },
398
- data: {
399
- copilotActionStatus: actionStatus!,
400
- copilotPullRequestId: pullRequestId!,
401
- commitHash: commitHash!,
402
- statusMessage: statusMessage!,
403
- statusChangedAt: OneUptimeDate.getCurrentDate(),
404
- logs: logs?.join("\n") || "",
405
- },
406
- props: {
407
- isRoot: true,
408
- },
409
- });
410
-
411
- return Response.sendEmptySuccessResponse(req, res);
412
- } catch (err) {
413
- next(err);
414
- }
415
- },
416
- );
417
- }
418
- }
@@ -1,127 +0,0 @@
1
- import OneUptimeDate from "../../Types/Date";
2
- import CodeRepositoryAuthorization from "../Middleware/CodeRepositoryAuthorization";
3
- import CopilotCodeRepositoryService, {
4
- Service as CopilotCodeRepositoryServiceType,
5
- } from "../Services/CopilotCodeRepositoryService";
6
- import ServiceCopilotCodeRepositoryService from "../Services/ServiceCopilotCodeRepositoryService";
7
- import {
8
- ExpressRequest,
9
- ExpressResponse,
10
- NextFunction,
11
- } from "../Utils/Express";
12
- import Response from "../Utils/Response";
13
- import BaseAPI from "./BaseAPI";
14
- import { LIMIT_PER_PROJECT } from "../../Types/Database/LimitMax";
15
- import BadDataException from "../../Types/Exception/BadDataException";
16
- import ObjectID from "../../Types/ObjectID";
17
- import CopilotCodeRepository from "../../Models/DatabaseModels/CopilotCodeRepository";
18
- import ServiceCopilotCodeRepository from "../../Models/DatabaseModels/ServiceCopilotCodeRepository";
19
-
20
- export default class CopilotCodeRepositoryAPI extends BaseAPI<
21
- CopilotCodeRepository,
22
- CopilotCodeRepositoryServiceType
23
- > {
24
- public constructor() {
25
- super(CopilotCodeRepository, CopilotCodeRepositoryService);
26
-
27
- this.router.get(
28
- `${new this.entityType()
29
- .getCrudApiPath()
30
- ?.toString()}/is-valid/:secretkey`,
31
- CodeRepositoryAuthorization.isAuthorizedRepository,
32
- async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
33
- try {
34
- return Response.sendEmptySuccessResponse(req, res);
35
- } catch (err) {
36
- next(err);
37
- }
38
- },
39
- );
40
-
41
- this.router.get(
42
- `${new this.entityType()
43
- .getCrudApiPath()
44
- ?.toString()}/get-code-repository/:secretkey`,
45
- CodeRepositoryAuthorization.isAuthorizedRepository,
46
- async (req: ExpressRequest, res: ExpressResponse, next: NextFunction) => {
47
- try {
48
- const secretkey: string = req.params["secretkey"]!;
49
-
50
- if (!secretkey) {
51
- throw new BadDataException("Secret key is required");
52
- }
53
-
54
- const codeRepository: CopilotCodeRepository | null =
55
- await CopilotCodeRepositoryService.findOneBy({
56
- query: {
57
- secretToken: new ObjectID(secretkey),
58
- },
59
- select: {
60
- name: true,
61
- mainBranchName: true,
62
- organizationName: true,
63
- repositoryHostedAt: true,
64
- repositoryName: true,
65
- },
66
- props: {
67
- isRoot: true,
68
- },
69
- });
70
-
71
- if (!codeRepository) {
72
- throw new BadDataException(
73
- "Code repository not found. Secret key is invalid.",
74
- );
75
- }
76
-
77
- // update last run time.
78
-
79
- await CopilotCodeRepositoryService.updateOneById({
80
- id: codeRepository.id!,
81
- data: {
82
- lastCopilotRunDateTime: OneUptimeDate.getCurrentDate(),
83
- },
84
- props: {
85
- isRoot: true,
86
- },
87
- });
88
-
89
- const servicesRepository: Array<ServiceCopilotCodeRepository> =
90
- await ServiceCopilotCodeRepositoryService.findBy({
91
- query: {
92
- codeRepositoryId: codeRepository.id!,
93
- enablePullRequests: true,
94
- },
95
- select: {
96
- serviceCatalog: {
97
- name: true,
98
- _id: true,
99
- techStack: true,
100
- },
101
- servicePathInRepository: true,
102
- limitNumberOfOpenPullRequestsCount: true,
103
- },
104
- limit: LIMIT_PER_PROJECT,
105
- skip: 0,
106
- props: {
107
- isRoot: true,
108
- },
109
- });
110
-
111
- return Response.sendJsonObjectResponse(req, res, {
112
- codeRepository: CopilotCodeRepository.toJSON(
113
- codeRepository,
114
- CopilotCodeRepository,
115
- ),
116
- servicesRepository: ServiceCopilotCodeRepository.toJSONArray(
117
- servicesRepository,
118
- ServiceCopilotCodeRepository,
119
- ),
120
- });
121
- } catch (err) {
122
- next(err);
123
- }
124
- },
125
- );
126
- }
127
- }