@stack-spot/portal-network 0.161.0 → 0.162.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.
@@ -3,15 +3,12 @@ import { HttpError } from '@oazapfts/runtime'
3
3
  import {
4
4
  checkRoleRouteV1RolesRoleGet,
5
5
  createAccountSettingsV1SettingsPut,
6
- createApplicationsBatchServiceV1ApplicationsBatchPost,
7
- createApplicationServiceV1ApplicationsPost,
8
6
  createIntegrationServiceV1IntegrationsPost,
9
7
  createModuleServiceV1ModulesPost,
10
8
  createProgramGroupServiceV1ProgramGroupsPost,
11
9
  createReposBatchServiceV1ReposBatchPost,
12
10
  createRepositoryServiceV1ReposPost,
13
11
  defaults,
14
- deleteApplicationServiceV1ApplicationsApplicationIdDelete,
15
12
  deleteIntegrationServiceV1IntegrationsIntegrationIdDelete,
16
13
  deleteProgramGroupServiceV1ProgramGroupsProgramGroupIdDelete,
17
14
  deleteRepositoryServiceV1ReposRepositoryIdDelete,
@@ -19,14 +16,13 @@ import {
19
16
  downloadReportV1ReportsReportIdDownloadGet,
20
17
  downloadSearchReposScmServiceV1ReposSearchScmSearchRepoIdDownloadGet,
21
18
  getAccountSettingsV1SettingsGet,
22
- getApplicationByIdServiceV1ApplicationsApplicationIdGet,
23
19
  getIntegrationByIdServiceV1IntegrationsIntegrationIdGet,
24
20
  getProgramGroupByIdServiceV1ProgramGroupsProgramGroupIdGet,
21
+ getReportPullRequestContentV1ReportsReportIdPullRequestGet,
25
22
  getReportV1ReportsReportIdGet,
26
23
  getRepositoryByIdServiceV1ReposRepositoryIdGet,
27
24
  getStatusSearchReposScmServiceV1ReposSearchScmSearchRepoIdStatusGet,
28
- listApplicationReportV1ApplicationsApplicationIdReportsGet,
29
- listApplicationServiceV1ApplicationsGet,
25
+ listBranchesServiceV1ReposBranchesGet,
30
26
  listIntegrationServiceV1IntegrationsGet,
31
27
  listModulesServiceV1ModulesGet,
32
28
  listProgramGroupReportServiceV1ProgramGroupsProgramGroupIdReportsGet,
@@ -35,10 +31,11 @@ import {
35
31
  listRepositoryServiceV1ReposGet,
36
32
  listTagsServiceV1TagsGet,
37
33
  searchReposScmServiceV1ReposSearchScmGet,
38
- updateApplicationServiceV1ApplicationsApplicationIdPut,
39
34
  updateIntegrationServiceV1IntegrationsIntegrationIdPut,
35
+ updateProgramGroupComponentsServiceV1ProgramGroupsProgramGroupIdComponentsPut,
40
36
  updateProgramGroupServiceV1ProgramGroupsProgramGroupIdPut,
41
37
  updateRepositoryServiceV1ReposRepositoryIdPut,
38
+ validateScmUrlServiceV1ReposValidateScmUrlPost,
42
39
  } from '../api/codeShift'
43
40
  import { DefaultAPIError } from '../error/DefaultAPIError'
44
41
  import { codeShiftDictionary } from '../error/dictionary/code-shift'
@@ -56,36 +53,6 @@ class CodeShift extends ReactQueryNetworkClient {
56
53
  return new DefaultAPIError(error.data, error.status, codeShiftDictionary, error.headers)
57
54
  }
58
55
 
59
- /**
60
- * @deprecated use createRepository instead
61
- * Creates a code shift application.
62
- */
63
- createApplication = this.mutation(removeAuthorizationParam(createApplicationServiceV1ApplicationsPost))
64
- /**
65
- * @deprecated use createRepositoriesBatch instead
66
- * Creates a code shift application in batch.
67
- */
68
- createApplicationBatch = this.mutation(removeAuthorizationParam(createApplicationsBatchServiceV1ApplicationsBatchPost))
69
- /**
70
- * @deprecated use repositories instead
71
- * Gets code shift applications.
72
- */
73
- applications = this.query(removeAuthorizationParam(listApplicationServiceV1ApplicationsGet))
74
- /**
75
- * @deprecated use repository instead
76
- * Gets code shift application
77
- */
78
- application = this.query(removeAuthorizationParam(getApplicationByIdServiceV1ApplicationsApplicationIdGet))
79
- /**
80
- * @deprecated use updateRepository instead
81
- * Updates a code shift application
82
- */
83
- updateApplication = this.mutation(removeAuthorizationParam(updateApplicationServiceV1ApplicationsApplicationIdPut))
84
- /**
85
- * @deprecated use deleteRepository instead
86
- * Deletes a code shift application.
87
- */
88
- deleteImportedApp = this.mutation(removeAuthorizationParam(deleteApplicationServiceV1ApplicationsApplicationIdDelete))
89
56
  /**
90
57
  * Creates a repository.
91
58
  */
@@ -110,6 +77,10 @@ class CodeShift extends ReactQueryNetworkClient {
110
77
  * Updates a repository
111
78
  */
112
79
  updateRepository = this.mutation(removeAuthorizationParam(updateRepositoryServiceV1ReposRepositoryIdPut))
80
+ /**
81
+ * Get a report for a pull request by id.
82
+ */
83
+ getReportPullRequestContent = this.query(removeAuthorizationParam(getReportPullRequestContentV1ReportsReportIdPullRequestGet))
113
84
  /**
114
85
  * Gets modules.
115
86
  */
@@ -122,11 +93,6 @@ class CodeShift extends ReactQueryNetworkClient {
122
93
  * Generates a report.
123
94
  */
124
95
  generateReport = this.mutation(removeAuthorizationParam(dispatchModuleServiceV1ModulesDispatchesPost))
125
- /**
126
- * @deprecated use repositoryReports instead
127
- * Gets reports.
128
- */
129
- reports = this.query(removeAuthorizationParam(listApplicationReportV1ApplicationsApplicationIdReportsGet))
130
96
  /**
131
97
  * Gets repository reports.
132
98
  */
@@ -164,67 +130,68 @@ class CodeShift extends ReactQueryNetworkClient {
164
130
  * We do not use opa in this api, so this is the fn needed to check permissions.
165
131
  */
166
132
  validateRolePermissions = this.query(removeAuthorizationParam(checkRoleRouteV1RolesRoleGet))
167
-
168
133
  /**
169
134
  * Creates an integration
170
135
  */
171
136
  createIntegration = this.mutation(removeAuthorizationParam(createIntegrationServiceV1IntegrationsPost))
172
-
173
137
  /**
174
138
  * Lists integrations
175
139
  */
176
140
  listIntegration = this.query(removeAuthorizationParam(listIntegrationServiceV1IntegrationsGet))
177
-
178
141
  /**
179
142
  * Gets an integration by id
180
143
  */
181
144
  getIntegrationById = this.query(removeAuthorizationParam(getIntegrationByIdServiceV1IntegrationsIntegrationIdGet))
182
-
183
145
  /**
184
146
  * Updates an integration
185
147
  */
186
148
  updateIntegration = this.mutation(removeAuthorizationParam(updateIntegrationServiceV1IntegrationsIntegrationIdPut))
187
-
188
149
  /**
189
150
  * Deletes an integration
190
151
  */
191
152
  deleteIntegration = this.mutation(removeAuthorizationParam(deleteIntegrationServiceV1IntegrationsIntegrationIdDelete))
192
-
193
153
  /**
194
154
  * Creates a program group.
195
155
  */
196
156
  createProgramGroup = this.mutation(removeAuthorizationParam(createProgramGroupServiceV1ProgramGroupsPost))
197
-
198
157
  /**
199
158
  * Gets list of program groups.
200
159
  */
201
160
  listProgramGroups = this.query(removeAuthorizationParam(listProgramGroupServiceV1ProgramGroupsGet))
202
-
203
161
  /**
204
162
  * Gets a program group by id.
205
163
  */
206
164
  getProgramGroupById = this.query(removeAuthorizationParam(getProgramGroupByIdServiceV1ProgramGroupsProgramGroupIdGet))
207
-
208
165
  /**
209
- * List Program Group Report Service
210
- */
166
+ * List Program Group Report Service
167
+ */
211
168
  listProgramGroupReport = this.query(removeAuthorizationParam(listProgramGroupReportServiceV1ProgramGroupsProgramGroupIdReportsGet))
212
-
213
169
  /**
214
170
  * Updates a program group.
215
171
  */
216
172
  updateProgramGroup = this.mutation(removeAuthorizationParam(updateProgramGroupServiceV1ProgramGroupsProgramGroupIdPut))
217
-
173
+ /**
174
+ * Updates a program group components.
175
+ */
176
+ updateProgramGroupComponents = this.mutation(
177
+ removeAuthorizationParam(updateProgramGroupComponentsServiceV1ProgramGroupsProgramGroupIdComponentsPut),
178
+ )
218
179
  /**
219
180
  * Deletes a program group.
220
181
  */
221
182
  deleteProgramGroup = this.mutation(removeAuthorizationParam(deleteProgramGroupServiceV1ProgramGroupsProgramGroupIdDelete))
222
-
223
183
  /**
224
184
  * Gets list of tags.
225
185
  */
226
186
  tags = this.query(removeAuthorizationParam(listTagsServiceV1TagsGet))
227
-
187
+ /**
188
+ * Validates a SCM URL.
189
+ */
190
+ validateSCMUrl = this.mutation(removeAuthorizationParam(validateScmUrlServiceV1ReposValidateScmUrlPost))
191
+ /**
192
+ * Get Branches for a Repository
193
+ */
194
+ getBranches = this.query(removeAuthorizationParam(listBranchesServiceV1ReposBranchesGet))
228
195
  }
229
196
 
230
197
  export const codeShiftClient = new CodeShift()
@@ -1,6 +1,5 @@
1
1
  import { Dictionary, Language } from '@stack-spot/portal-translate'
2
2
  import { every, isString } from 'lodash'
3
- import { ErrorResponse, ValidationDetails } from '../api/account'
4
3
  import { actionDetails } from './dictionary/action-details'
5
4
  import { baseDictionary } from './dictionary/base'
6
5
  import { cntFields } from './dictionary/cnt-fields'
@@ -8,6 +7,7 @@ import { workspaceDetails } from './dictionary/workspace-details'
8
7
  import { workspaceFields } from './dictionary/workspace-fields'
9
8
  import { ignoredTitleErrorCodes } from './IgnoredErrorCodes'
10
9
  import { ErrorDetailsProperties, StackspotAPIError } from './StackspotAPIError'
10
+ import { ErrorResponse, LanguageSuggestedMessageKeys, ValidationDetails } from './types'
11
11
 
12
12
  // these details don't say anything the status already doesn't and we'd better use local translations for them.
13
13
  const ignoredDescriptions = [
@@ -35,6 +35,11 @@ function getValues(detail: ValidationDetails) {
35
35
  return detail.values && every(detail.values, isString) ? `\n${detail.values.join('\n')}` : ''
36
36
  }
37
37
 
38
+ function getSuggestedMessages(suggestedMessage: ErrorResponse['suggestedMessages'] | null | undefined, language?: Language) {
39
+ const parseLanguage: Record<Language, LanguageSuggestedMessageKeys> = { pt: 'ptBr', en: 'enUs' }
40
+ return suggestedMessage?.[parseLanguage?.[language || 'en']]
41
+ }
42
+
38
43
  const UNIT_REGEX_TEMPLATE = /{\d}/g
39
44
  const RANGE_REGEX_TEMPLATE = /{1-n}/g
40
45
 
@@ -61,21 +66,39 @@ function createMessage(status: number, raw: ErrorResponse, dictionary: Dictionar
61
66
  const dictDetails = (detailsDictionary[api?.toLowerCase() as keyof typeof detailsDictionary] ?? {})[language || 'en']
62
67
  const dictionaryDetails = raw.code && dictDetails ? dictDetails[raw.code] : {}
63
68
 
64
- if (!raw.validationDetails?.length) return { description: title, ...dictionaryDetails }
69
+ if (raw?.validationDetails?.length) {
65
70
 
66
- const details = raw.validationDetails?.map((detail) => {
67
- const dict: Record<string, string> = (fieldDictionary[api?.toLowerCase() as keyof typeof fieldDictionary] ?? {})[language || 'en'] ?? {}
68
- const codeTranslatedMessage = raw.code !== detail.code && dictionary[language || 'en'][detail.code]
71
+ const suggestedMessages = raw.validationDetails.map((detail) =>
72
+ getSuggestedMessages(detail?.suggestedMessages, language)).filter((msg) => !!msg)
69
73
 
70
- if (codeTranslatedMessage && containsNumberInBraces(codeTranslatedMessage) && (detail.values?.length || detail.field?.length)) {
71
- const value = detail.values?.length ? detail.values : (detail.field ? [detail.field] : [])
72
- return interpolateErrors(codeTranslatedMessage, value, dict)
74
+ if (suggestedMessages.length) {
75
+ return { description: suggestedMessages.join('\n'), ...dictionaryDetails }
73
76
  }
74
77
 
75
- const name = dict[detail.code] || detail.field || codeTranslatedMessage || detail.details || ''
76
- return `${name}${getValues(detail)}`
77
- })?.filter(d => !!d)
78
- return { description: details ? `${title}\n${details?.join('\n')}` : title, ...dictionaryDetails }
78
+ const details = raw.validationDetails?.map((detail) => {
79
+ const dict: Record<string, string> =
80
+ (fieldDictionary[api?.toLowerCase() as keyof typeof fieldDictionary] ?? {})[language || 'en'] ?? {}
81
+ const codeTranslatedMessage = raw.code !== detail.code && dictionary[language || 'en'][detail.code]
82
+
83
+ if (codeTranslatedMessage && containsNumberInBraces(codeTranslatedMessage) && (detail.values?.length || detail.field?.length)) {
84
+ const value = detail.values?.length ? detail.values : (detail.field ? [detail.field] : [])
85
+ return interpolateErrors(codeTranslatedMessage, value, dict)
86
+ }
87
+
88
+ const name = dict[detail.code] || detail.field || codeTranslatedMessage || detail.details || ''
89
+ return `${name}${getValues(detail)}`
90
+ })?.filter(d => !!d)
91
+ return { description: details ? `${title}\n${details?.join('\n')}` : title, ...dictionaryDetails }
92
+ }
93
+
94
+ if (raw?.suggestedMessages) {
95
+ const suggestedMessages = getSuggestedMessages(raw?.suggestedMessages, language)
96
+ if (suggestedMessages) {
97
+ return { description: suggestedMessages, ...dictionaryDetails }
98
+ }
99
+ }
100
+
101
+ return { description: title, ...dictionaryDetails }
79
102
  }
80
103
 
81
104
  /**
@@ -0,0 +1,21 @@
1
+ export type LanguageSuggestedMessageKeys = 'ptBr' | 'enUs';
2
+
3
+ export type SuggestedMessage = {
4
+ [key in LanguageSuggestedMessageKeys]: string | null
5
+ };
6
+
7
+ export type ValidationDetails = {
8
+ code: string,
9
+ field?: string,
10
+ details?: string,
11
+ values?: string[],
12
+ suggestedMessages?: SuggestedMessage | null,
13
+ };
14
+
15
+ export type ErrorResponse = {
16
+ code: string,
17
+ status: number,
18
+ details: string,
19
+ validationDetails?: ValidationDetails[],
20
+ suggestedMessages?: SuggestedMessage | null,
21
+ };