-
Notifications
You must be signed in to change notification settings - Fork 532
Expand file tree
/
Copy pathassets_output.go
More file actions
455 lines (415 loc) · 17.1 KB
/
Copy pathassets_output.go
File metadata and controls
455 lines (415 loc) · 17.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
package asc
import (
"fmt"
"sort"
"strings"
)
// AppScreenshotSetWithScreenshots groups a set with its screenshots.
type AppScreenshotSetWithScreenshots struct {
Set Resource[AppScreenshotSetAttributes] `json:"set"`
Screenshots []Resource[AppScreenshotAttributes] `json:"screenshots"`
}
// AppScreenshotListResult represents screenshot list output by localization.
type AppScreenshotListResult struct {
VersionLocalizationID string `json:"versionLocalizationId"`
Sets []AppScreenshotSetWithScreenshots `json:"sets"`
}
// AppPreviewSetWithPreviews groups a set with its previews.
type AppPreviewSetWithPreviews struct {
Set Resource[AppPreviewSetAttributes] `json:"set"`
Previews []Resource[AppPreviewAttributes] `json:"previews"`
}
// AppPreviewListResult represents preview list output by localization.
type AppPreviewListResult struct {
VersionLocalizationID string `json:"versionLocalizationId"`
Sets []AppPreviewSetWithPreviews `json:"sets"`
}
// AssetUploadResultItem represents a single uploaded asset.
type AssetUploadResultItem struct {
FileName string `json:"fileName"`
FilePath string `json:"filePath"`
AssetID string `json:"assetId"`
State string `json:"state,omitempty"`
Skipped bool `json:"skipped,omitempty"`
}
// AssetUploadFailureItem represents a failed upload item.
type AssetUploadFailureItem struct {
FileName string `json:"fileName,omitempty"`
FilePath string `json:"filePath,omitempty"`
Error string `json:"error"`
}
// AppScreenshotUploadResult represents screenshot upload output.
type AppScreenshotUploadResult struct {
VersionLocalizationID string `json:"versionLocalizationId"`
SetID string `json:"setId"`
DisplayType string `json:"displayType"`
DryRun bool `json:"dryRun,omitempty"`
Resumed bool `json:"resumed,omitempty"`
Total int `json:"total,omitempty"`
Uploaded int `json:"uploaded,omitempty"`
Skipped int `json:"skipped,omitempty"`
Pending int `json:"pending,omitempty"`
Failed int `json:"failed,omitempty"`
FailureArtifactPath string `json:"failureArtifactPath,omitempty"`
Results []AssetUploadResultItem `json:"results"`
Failures []AssetUploadFailureItem `json:"failures,omitempty"`
}
// AppScreenshotLocalizationUploadResult represents one localization in a fan-out screenshot upload.
type AppScreenshotLocalizationUploadResult struct {
Locale string `json:"locale"`
VersionLocalizationID string `json:"versionLocalizationId"`
SetID string `json:"setId"`
DisplayType string `json:"displayType"`
DryRun bool `json:"dryRun,omitempty"`
Total int `json:"total,omitempty"`
Uploaded int `json:"uploaded,omitempty"`
Skipped int `json:"skipped,omitempty"`
Pending int `json:"pending,omitempty"`
Failed int `json:"failed,omitempty"`
FailureArtifactPath string `json:"failureArtifactPath,omitempty"`
Results []AssetUploadResultItem `json:"results"`
Failures []AssetUploadFailureItem `json:"failures,omitempty"`
}
// AppScreenshotFanoutUploadResult represents an app/version-scoped screenshot upload fan-out.
type AppScreenshotFanoutUploadResult struct {
AppID string `json:"appId"`
Version string `json:"version"`
VersionID string `json:"versionId"`
Platform string `json:"platform"`
DisplayType string `json:"displayType"`
DryRun bool `json:"dryRun,omitempty"`
Localizations []AppScreenshotLocalizationUploadResult `json:"localizations"`
}
// AppPreviewUploadResult represents preview upload output.
type AppPreviewUploadResult struct {
VersionLocalizationID string `json:"versionLocalizationId"`
SetID string `json:"setId"`
PreviewType string `json:"previewType"`
DryRun bool `json:"dryRun,omitempty"`
Results []AssetUploadResultItem `json:"results"`
Failures []AssetUploadFailureItem `json:"failures,omitempty"`
}
// CustomProductPageScreenshotUploadResult represents custom product page screenshot upload output.
type CustomProductPageScreenshotUploadResult struct {
CustomProductPageLocalizationID string `json:"customProductPageLocalizationId"`
SetID string `json:"setId"`
DisplayType string `json:"displayType"`
Results []AssetUploadResultItem `json:"results"`
}
// ExperimentTreatmentLocalizationScreenshotUploadResult represents PPO treatment localization screenshot upload output.
type ExperimentTreatmentLocalizationScreenshotUploadResult struct {
ExperimentTreatmentLocalizationID string `json:"experimentTreatmentLocalizationId"`
SetID string `json:"setId"`
DisplayType string `json:"displayType"`
Results []AssetUploadResultItem `json:"results"`
}
// CustomProductPagePreviewUploadResult represents custom product page preview upload output.
type CustomProductPagePreviewUploadResult struct {
CustomProductPageLocalizationID string `json:"customProductPageLocalizationId"`
SetID string `json:"setId"`
PreviewType string `json:"previewType"`
Results []AssetUploadResultItem `json:"results"`
}
// AssetDeleteResult represents deletion output for assets.
type AssetDeleteResult struct {
ID string `json:"id"`
Deleted bool `json:"deleted"`
}
func appScreenshotSetsRows(resp *AppScreenshotSetsResponse) ([]string, [][]string) {
headers := []string{"ID", "Display Type"}
rows := make([][]string, 0, len(resp.Data))
for _, item := range resp.Data {
rows = append(rows, []string{
SanitizeTerminalText(item.ID),
SanitizeTerminalText(item.Attributes.ScreenshotDisplayType),
})
}
return headers, rows
}
func appScreenshotsRows(resp *AppScreenshotsResponse) ([]string, [][]string) {
headers := []string{"ID", "File Name", "File Size", "State"}
rows := make([][]string, 0, len(resp.Data))
for _, item := range resp.Data {
rows = append(rows, []string{
SanitizeTerminalText(item.ID),
SanitizeTerminalText(item.Attributes.FileName),
fmt.Sprintf("%d", item.Attributes.FileSize),
SanitizeTerminalText(assetDeliveryStateValue(item.Attributes.AssetDeliveryState)),
})
}
return headers, rows
}
func appPreviewSetsRows(resp *AppPreviewSetsResponse) ([]string, [][]string) {
headers := []string{"ID", "Preview Type"}
rows := make([][]string, 0, len(resp.Data))
for _, item := range resp.Data {
rows = append(rows, []string{
SanitizeTerminalText(item.ID),
SanitizeTerminalText(item.Attributes.PreviewType),
})
}
return headers, rows
}
func appPreviewsRows(resp *AppPreviewsResponse) ([]string, [][]string) {
headers := []string{"ID", "File Name", "File Size", "Poster Frame", "State"}
rows := make([][]string, 0, len(resp.Data))
for _, item := range resp.Data {
rows = append(rows, []string{
SanitizeTerminalText(item.ID),
SanitizeTerminalText(item.Attributes.FileName),
fmt.Sprintf("%d", item.Attributes.FileSize),
SanitizeTerminalText(item.Attributes.PreviewFrameTimeCode),
SanitizeTerminalText(assetDeliveryStateValue(item.Attributes.AssetDeliveryState)),
})
}
return headers, rows
}
func appScreenshotListResultRows(result *AppScreenshotListResult) ([]string, [][]string) {
headers := []string{"Set ID", "Display Type", "Screenshot ID", "File Name", "File Size", "State"}
var rows [][]string
for _, set := range result.Sets {
setID := SanitizeTerminalText(set.Set.ID)
displayType := SanitizeTerminalText(set.Set.Attributes.ScreenshotDisplayType)
if len(set.Screenshots) == 0 {
rows = append(rows, []string{setID, displayType, "", "", "", ""})
continue
}
for _, item := range set.Screenshots {
rows = append(rows, []string{
setID,
displayType,
SanitizeTerminalText(item.ID),
SanitizeTerminalText(item.Attributes.FileName),
fmt.Sprintf("%d", item.Attributes.FileSize),
SanitizeTerminalText(assetDeliveryStateValue(item.Attributes.AssetDeliveryState)),
})
}
}
return headers, rows
}
func appPreviewListResultRows(result *AppPreviewListResult) ([]string, [][]string) {
headers := []string{"Set ID", "Preview Type", "Preview ID", "File Name", "File Size", "Poster Frame", "State"}
var rows [][]string
for _, set := range result.Sets {
setID := SanitizeTerminalText(set.Set.ID)
previewType := SanitizeTerminalText(set.Set.Attributes.PreviewType)
if len(set.Previews) == 0 {
rows = append(rows, []string{setID, previewType, "", "", "", "", ""})
continue
}
for _, item := range set.Previews {
rows = append(rows, []string{
setID,
previewType,
SanitizeTerminalText(item.ID),
SanitizeTerminalText(item.Attributes.FileName),
fmt.Sprintf("%d", item.Attributes.FileSize),
SanitizeTerminalText(item.Attributes.PreviewFrameTimeCode),
SanitizeTerminalText(assetDeliveryStateValue(item.Attributes.AssetDeliveryState)),
})
}
}
return headers, rows
}
func appScreenshotUploadResultMainRows(result *AppScreenshotUploadResult) ([]string, [][]string) {
headers := []string{"Localization ID", "Set ID", "Display Type", "Dry Run", "Resumed", "Total", "Uploaded", "Skipped", "Pending", "Failed", "Failure Artifact"}
rows := [][]string{{
SanitizeTerminalText(result.VersionLocalizationID),
SanitizeTerminalText(result.SetID),
SanitizeTerminalText(result.DisplayType),
fmt.Sprintf("%t", result.DryRun),
fmt.Sprintf("%t", result.Resumed),
fmt.Sprintf("%d", result.Total),
fmt.Sprintf("%d", result.Uploaded),
fmt.Sprintf("%d", result.Skipped),
fmt.Sprintf("%d", result.Pending),
fmt.Sprintf("%d", result.Failed),
SanitizeTerminalText(result.FailureArtifactPath),
}}
return headers, rows
}
func appScreenshotFanoutUploadResultMainRows(result *AppScreenshotFanoutUploadResult) ([]string, [][]string) {
headers := []string{"App ID", "Version", "Version ID", "Platform", "Display Type", "Dry Run", "Localizations"}
rows := [][]string{{
SanitizeTerminalText(result.AppID),
SanitizeTerminalText(result.Version),
SanitizeTerminalText(result.VersionID),
SanitizeTerminalText(result.Platform),
SanitizeTerminalText(result.DisplayType),
fmt.Sprintf("%t", result.DryRun),
fmt.Sprintf("%d", len(result.Localizations)),
}}
return headers, rows
}
func appScreenshotFanoutUploadLocalizationRows(result *AppScreenshotFanoutUploadResult) ([]string, [][]string) {
headers := []string{"Locale", "Localization ID", "Set ID", "Files", "Uploaded", "Skipped", "Pending", "Failed", "Failure Artifact", "States"}
rows := make([][]string, 0, len(result.Localizations))
for _, item := range result.Localizations {
total := item.Total
if total == 0 {
total = len(item.Results) + item.Pending
}
rows = append(rows, []string{
SanitizeTerminalText(item.Locale),
SanitizeTerminalText(item.VersionLocalizationID),
SanitizeTerminalText(item.SetID),
fmt.Sprintf("%d", total),
fmt.Sprintf("%d", item.Uploaded),
fmt.Sprintf("%d", item.Skipped),
fmt.Sprintf("%d", item.Pending),
fmt.Sprintf("%d", item.Failed),
SanitizeTerminalText(item.FailureArtifactPath),
summarizeAssetUploadStates(item.Results),
})
}
return headers, rows
}
func appScreenshotFanoutUploadResultItemRows(result *AppScreenshotFanoutUploadResult) ([]string, [][]string) {
headers := []string{"Locale", "File Name", "Asset ID", "State"}
rows := make([][]string, 0)
for _, localization := range result.Localizations {
locale := SanitizeTerminalText(localization.Locale)
if len(localization.Results) == 0 {
rows = append(rows, []string{locale, "", "", ""})
continue
}
for _, item := range localization.Results {
rows = append(rows, []string{
locale,
SanitizeTerminalText(item.FileName),
SanitizeTerminalText(item.AssetID),
SanitizeTerminalText(assetUploadItemState(item)),
})
}
}
return headers, rows
}
func appScreenshotFanoutUploadFailureRows(result *AppScreenshotFanoutUploadResult) ([]string, [][]string) {
headers := []string{"Locale", "File Name", "File Path", "Error"}
rows := make([][]string, 0)
for _, localization := range result.Localizations {
locale := SanitizeTerminalText(localization.Locale)
for _, item := range localization.Failures {
rows = append(rows, []string{
locale,
SanitizeTerminalText(item.FileName),
SanitizeTerminalText(item.FilePath),
SanitizeTerminalText(item.Error),
})
}
}
return headers, rows
}
func appPreviewUploadResultMainRows(result *AppPreviewUploadResult) ([]string, [][]string) {
headers := []string{"Localization ID", "Set ID", "Preview Type", "Dry Run"}
rows := [][]string{{
SanitizeTerminalText(result.VersionLocalizationID),
SanitizeTerminalText(result.SetID),
SanitizeTerminalText(result.PreviewType),
fmt.Sprintf("%t", result.DryRun),
}}
return headers, rows
}
func customProductPageScreenshotUploadResultMainRows(result *CustomProductPageScreenshotUploadResult) ([]string, [][]string) {
headers := []string{"Localization ID", "Set ID", "Display Type"}
rows := [][]string{{
SanitizeTerminalText(result.CustomProductPageLocalizationID),
SanitizeTerminalText(result.SetID),
SanitizeTerminalText(result.DisplayType),
}}
return headers, rows
}
func experimentTreatmentLocalizationScreenshotUploadResultMainRows(result *ExperimentTreatmentLocalizationScreenshotUploadResult) ([]string, [][]string) {
headers := []string{"Localization ID", "Set ID", "Display Type"}
rows := [][]string{{
SanitizeTerminalText(result.ExperimentTreatmentLocalizationID),
SanitizeTerminalText(result.SetID),
SanitizeTerminalText(result.DisplayType),
}}
return headers, rows
}
func customProductPagePreviewUploadResultMainRows(result *CustomProductPagePreviewUploadResult) ([]string, [][]string) {
headers := []string{"Localization ID", "Set ID", "Preview Type"}
rows := [][]string{{
SanitizeTerminalText(result.CustomProductPageLocalizationID),
SanitizeTerminalText(result.SetID),
SanitizeTerminalText(result.PreviewType),
}}
return headers, rows
}
func assetUploadResultItemRows(results []AssetUploadResultItem) ([]string, [][]string) {
headers := []string{"File Name", "Asset ID", "State"}
rows := make([][]string, 0, len(results))
for _, item := range results {
rows = append(rows, []string{
SanitizeTerminalText(item.FileName),
SanitizeTerminalText(item.AssetID),
SanitizeTerminalText(assetUploadItemState(item)),
})
}
return headers, rows
}
func assetDeliveryStateValue(state *AssetDeliveryState) string {
if state == nil {
return ""
}
return state.State
}
func assetUploadItemState(item AssetUploadResultItem) string {
if item.State == "" && item.Skipped {
return "skipped"
}
return item.State
}
func summarizeAssetUploadStates(results []AssetUploadResultItem) string {
if len(results) == 0 {
return "n/a"
}
counts := make(map[string]int)
states := make([]string, 0, len(results))
for _, item := range results {
state := SanitizeTerminalText(assetUploadItemState(item))
if state == "" {
state = "uploaded"
}
if _, ok := counts[state]; !ok {
states = append(states, state)
}
counts[state]++
}
sort.Strings(states)
parts := make([]string, 0, len(states))
for _, state := range states {
parts = append(parts, fmt.Sprintf("%s=%d", state, counts[state]))
}
return strings.Join(parts, ", ")
}
func assetUploadFailureItemRows(results []AssetUploadFailureItem) ([]string, [][]string) {
headers := []string{"File Name", "File Path", "Error"}
rows := make([][]string, 0, len(results))
for _, item := range results {
rows = append(rows, []string{
SanitizeTerminalText(item.FileName),
SanitizeTerminalText(item.FilePath),
SanitizeTerminalText(item.Error),
})
}
return headers, rows
}
func screenshotSizesRows(result *ScreenshotSizesResult) ([]string, [][]string) {
headers := []string{"Display Type", "Family", "Dimensions"}
rows := make([][]string, 0, len(result.Sizes))
for _, item := range result.Sizes {
rows = append(rows, []string{
SanitizeTerminalText(item.DisplayType),
SanitizeTerminalText(item.Family),
formatScreenshotDimensions(item.Dimensions),
})
}
return headers, rows
}
func assetDeleteResultRows(result *AssetDeleteResult) ([]string, [][]string) {
headers := []string{"ID", "Deleted"}
rows := [][]string{{SanitizeTerminalText(result.ID), fmt.Sprintf("%t", result.Deleted)}}
return headers, rows
}