-
Notifications
You must be signed in to change notification settings - Fork 124
/
waterfall.go
706 lines (592 loc) · 23.1 KB
/
waterfall.go
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
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
package service
import (
"fmt"
"net/http"
"sort"
"strconv"
"strings"
"time"
"github.com/evergreen-ci/evergreen"
"github.com/evergreen-ci/evergreen/apimodels"
"github.com/evergreen-ci/evergreen/model"
"github.com/evergreen-ci/evergreen/model/task"
"github.com/evergreen-ci/evergreen/model/user"
"github.com/evergreen-ci/gimlet"
"github.com/pkg/errors"
)
const (
waterfallPerPageLimit = 5
waterfallBVFilterParam = "bv_filter"
waterfallSkipParam = "skip"
showUpstreamParam = "upstream"
)
// uiStatus determines task status label.
func uiStatus(task waterfallTask) string {
switch task.Status {
case evergreen.TaskStarted, evergreen.TaskSucceeded,
evergreen.TaskFailed, evergreen.TaskDispatched:
return task.Status
case evergreen.TaskUndispatched:
if task.Activated {
return task.Status
} else {
return evergreen.TaskInactive
}
default:
return task.Status
}
}
type versionVariantData struct {
Rows map[string]waterfallRow `json:"rows"`
Versions []waterfallVersion `json:"versions"`
BuildVariants waterfallBuildVariants `json:"build_variants"`
}
// waterfallData is all of the data that gets sent to the waterfall page on load
type waterfallData struct {
Rows []waterfallRow `json:"rows"`
Versions []waterfallVersion `json:"versions"`
TotalVersions int `json:"total_versions"` // total number of versions (for pagination)
CurrentSkip int `json:"current_skip"` // number of versions skipped so far
PreviousPageCount int `json:"previous_page_count"` // number of versions on previous page
CurrentTime int64 `json:"current_time"` // time used to calculate the eta of started task
}
// waterfallBuildVariant stores the Id and DisplayName for a given build
// This struct is associated with one waterfallBuild
type waterfallBuildVariant struct {
Id string `json:"id"`
DisplayName string `json:"display_name"`
}
// waterfallRow represents one row associated with a build variant.
type waterfallRow struct {
BuildVariant waterfallBuildVariant `json:"build_variant"`
Builds map[string]waterfallBuild `json:"builds"`
}
// waterfallBuild represents one set of tests for a given build variant and version
type waterfallBuild struct {
Id string `json:"id"`
Active bool `json:"active"`
Version string `json:"version"`
Tasks []waterfallTask `json:"tasks"`
TaskStatusCount task.TaskStatusCount `json:"taskStatusCount"`
}
// waterfallTask represents one task in the waterfall UI.
type waterfallTask struct {
Id string `json:"id"`
Status string `json:"status"`
StatusDetails apimodels.TaskEndDetail `json:"task_end_details"`
DisplayName string `json:"display_name"`
TimeTaken time.Duration `json:"time_taken"`
Activated bool `json:"activated"`
Blocked bool `json:"blocked"`
FailedTestNames []string `json:"failed_test_names,omitempty"`
ExpectedDuration time.Duration `json:"expected_duration,omitempty"`
StartTime int64 `json:"start_time"`
}
// failedTest holds all the information for displaying context about tests that failed in a
// waterfall page tooltip.
// waterfallVersion holds the waterfall UI representation of a single version (column)
// If the RolledUp field is false, then it contains information about
// a single version and the metadata fields will be of length 1.
// If the RolledUp field is true, this represents multiple inactive versions, with each element
// in the metadata arrays corresponding to one inactive version,
// ordered from most recent inactive version to earliest.
type waterfallVersion struct {
// whether or not the version element actually consists of multiple inactive
// versions rolled up into one
RolledUp bool `json:"rolled_up"`
// metadata about the enclosed versions. if this version does not consist
// of multiple rolled-up versions, these will each only have length 1
Ids []string `json:"ids"`
Messages []string `json:"messages"`
Authors []string `json:"authors"`
CreateTimes []time.Time `json:"create_times"`
Revisions []string `json:"revisions"`
RevisionOrderNumber int `json:"revision_order"`
UpstreamData []uiUpstreamData `json:"upstream_data"`
GitTags []string `json:"git_tags"`
// used to hold any errors that were found in creating the version
Errors []waterfallVersionError `json:"errors"`
Warnings []waterfallVersionError `json:"warnings"`
Ignoreds []bool `json:"ignoreds"`
}
type waterfallVersionError struct {
Messages []string `json:"messages"`
}
// waterfallBuildVariants implements the sort interface to allow backend sorting.
type waterfallBuildVariants []waterfallBuildVariant
func (wfbv waterfallBuildVariants) Len() int {
return len(wfbv)
}
func (wfbv waterfallBuildVariants) Less(i, j int) bool {
return wfbv[i].DisplayName < wfbv[j].DisplayName
}
func (wfbv waterfallBuildVariants) Swap(i, j int) {
wfbv[i], wfbv[j] = wfbv[j], wfbv[i]
}
// waterfallVersions implements the sort interface to allow backend sorting.
type waterfallVersions []waterfallVersion
func (wfv waterfallVersions) Len() int {
return len(wfv)
}
func (wfv waterfallVersions) Less(i, j int) bool {
return wfv[i].RevisionOrderNumber > wfv[j].RevisionOrderNumber
}
func (wfv waterfallVersions) Swap(i, j int) {
wfv[i], wfv[j] = wfv[j], wfv[i]
}
// createWaterfallTasks takes in a list of tasks returns a list of waterfallTasks.
func createWaterfallTasks(tasks []task.Task) ([]waterfallTask, task.TaskStatusCount) {
//initialize and set TaskStatusCount fields to zero
statusCount := task.TaskStatusCount{}
waterfallTasks := []waterfallTask{}
// add the tasks to the build
for _, t := range tasks {
taskForWaterfall := waterfallTask{
Id: t.Id,
Status: t.Status,
StatusDetails: t.Details,
DisplayName: t.DisplayName,
Activated: t.Activated,
Blocked: t.Blocked(),
TimeTaken: t.TimeTaken,
StartTime: t.StartTime.UnixNano(),
}
taskForWaterfall.Status = uiStatus(taskForWaterfall)
statusCount.IncrementStatus(taskForWaterfall.Status, taskForWaterfall.StatusDetails)
waterfallTasks = append(waterfallTasks, taskForWaterfall)
}
return waterfallTasks, statusCount
}
// For given build variant, variant display name and variant search query
// checks if matched variant has active tasks
func variantHasActiveTasks(bvDisplayName, variantQuery string, tasks []task.Task) bool {
return strings.Contains(
strings.ToUpper(bvDisplayName), strings.ToUpper(variantQuery),
) && task.AnyActiveTasks(tasks)
}
// Fetch versions until 'numVersionElements' elements are created, including
// elements consisting of multiple versions rolled-up into one.
// The skip value indicates how many versions back in time should be skipped
// before starting to fetch versions, the project indicates which project the
// returned versions should be a part of.
func getVersionsAndVariants(skip, numVersionElements int, project *model.Project, variantQuery string, showTriggered bool) (versionVariantData, error) {
// the final array of versions to return
finalVersions := []waterfallVersion{}
// keep track of the build variants we see
bvSet := map[string]bool{}
waterfallRows := map[string]waterfallRow{}
// build variant mappings - used so we can store the display name as
// the build variant field of a build
buildVariantMappings := project.GetVariantMappings()
// keep track of the last rolled-up version, so inactive versions can
// be added
var lastRolledUpVersion *waterfallVersion
versionsCheckedCount := 0
if numVersionElements > model.MaxMainlineCommitVersionLimit {
numVersionElements = model.MaxMainlineCommitVersionLimit
}
// loop until we have enough from the db
for len(finalVersions) < numVersionElements && versionsCheckedCount < model.MaxMainlineCommitVersionLimit {
// fetch the versions and associated builds
versionsFromDB, buildsByVersion, tasksByBuild, err :=
model.FetchVersionsBuildsAndTasks(project, skip+versionsCheckedCount, numVersionElements, showTriggered)
if err != nil {
return versionVariantData{}, errors.Wrap(err, "fetching versions and builds")
}
// if we've reached the beginning of all versions
if len(versionsFromDB) == 0 {
break
}
versionsCheckedCount += len(versionsFromDB)
// create the necessary versions, rolling up inactive ones
for _, versionFromDB := range versionsFromDB {
// if we have hit enough versions, break out
if len(finalVersions) == numVersionElements {
break
}
// the builds for the version
buildsInVersion := buildsByVersion[versionFromDB.Id]
// see if there are any active tasks in the version
versionActive := false
for _, b := range buildsInVersion {
if task.AnyActiveTasks(tasksByBuild[b.Id]) {
versionActive = true
}
}
variantMatched := false
// add any represented build variants to the set and initialize rows
for _, b := range buildsInVersion {
bvSet[b.BuildVariant] = true
// variant may not be defined in project, in which case add display name to mapping
if buildVariantMappings[b.BuildVariant] == "" {
buildVariantMappings[b.BuildVariant] = b.DisplayName
}
buildVariant := waterfallBuildVariant{
Id: b.BuildVariant,
DisplayName: buildVariantMappings[b.BuildVariant],
}
// The version is marked active if there are any
// activated tasks for the variant
if variantQuery != "" {
if versionActive && !variantMatched {
variantMatched = variantHasActiveTasks(
buildVariant.DisplayName, variantQuery, tasksByBuild[b.Id],
)
}
} else {
variantMatched = true
}
if _, ok := waterfallRows[b.BuildVariant]; !ok {
waterfallRows[b.BuildVariant] = waterfallRow{
Builds: map[string]waterfallBuild{},
BuildVariant: buildVariant,
}
}
}
// if it is inactive, roll up the version and don't create any
// builds for it
if !versionActive || !variantMatched {
if lastRolledUpVersion == nil {
lastRolledUpVersion = &waterfallVersion{RolledUp: true, RevisionOrderNumber: versionFromDB.RevisionOrderNumber}
}
// add the version metadata into the last rolled-up version
lastRolledUpVersion.Ids = append(lastRolledUpVersion.Ids, versionFromDB.Id)
lastRolledUpVersion.Authors = append(lastRolledUpVersion.Authors, versionFromDB.Author)
lastRolledUpVersion.Errors = append(
lastRolledUpVersion.Errors, waterfallVersionError{versionFromDB.Errors})
lastRolledUpVersion.Warnings = append(
lastRolledUpVersion.Warnings, waterfallVersionError{versionFromDB.Warnings})
lastRolledUpVersion.Messages = append(
lastRolledUpVersion.Messages, versionFromDB.Message)
lastRolledUpVersion.Ignoreds = append(
lastRolledUpVersion.Ignoreds, versionFromDB.Ignored)
lastRolledUpVersion.CreateTimes = append(
lastRolledUpVersion.CreateTimes, versionFromDB.CreateTime)
lastRolledUpVersion.Revisions = append(
lastRolledUpVersion.Revisions, versionFromDB.Revision)
lastRolledUpVersion.GitTags = append(
lastRolledUpVersion.GitTags, model.GitTags(versionFromDB.GitTags).String())
// move on to the next version
continue
}
// add a pending rolled-up version, if it exists
if lastRolledUpVersion != nil {
finalVersions = append(finalVersions, *lastRolledUpVersion)
lastRolledUpVersion = nil
}
// if we have hit enough versions, break out
if len(finalVersions) == numVersionElements {
break
}
// if the version can not be rolled up, create a fully fledged
// version for it
activeVersion := waterfallVersion{
Ids: []string{versionFromDB.Id},
Messages: []string{versionFromDB.Message},
Authors: []string{versionFromDB.Author},
CreateTimes: []time.Time{versionFromDB.CreateTime},
Revisions: []string{versionFromDB.Revision},
Errors: []waterfallVersionError{{versionFromDB.Errors}},
Warnings: []waterfallVersionError{{versionFromDB.Warnings}},
Ignoreds: []bool{versionFromDB.Ignored},
RevisionOrderNumber: versionFromDB.RevisionOrderNumber,
GitTags: []string{model.GitTags(versionFromDB.GitTags).String()},
}
if versionFromDB.TriggerID != "" {
var projectName string
projectName, err = model.GetUpstreamProjectName(versionFromDB.TriggerID, versionFromDB.TriggerType)
if err != nil {
return versionVariantData{}, err
}
activeVersion.UpstreamData = []uiUpstreamData{
{ProjectName: projectName, TriggerID: versionFromDB.TriggerID, TriggerType: versionFromDB.TriggerType},
}
}
// add the builds to the waterfall row
for _, b := range buildsInVersion {
currentRow := waterfallRows[b.BuildVariant]
buildForWaterfall := waterfallBuild{
Id: b.Id,
Version: versionFromDB.Id,
}
tasks, statusCount := createWaterfallTasks(tasksByBuild[b.Id])
buildForWaterfall.Tasks = tasks
buildForWaterfall.TaskStatusCount = statusCount
currentRow.Builds[versionFromDB.Id] = buildForWaterfall
waterfallRows[b.BuildVariant] = currentRow
}
// add the version
finalVersions = append(finalVersions, activeVersion)
}
failedAndStartedTasks := []task.Task{}
for _, tasks := range tasksByBuild {
for _, t := range tasks {
if t.Status == evergreen.TaskFailed || t.Status == evergreen.TaskStarted {
failedAndStartedTasks = append(failedAndStartedTasks, t)
}
}
}
addFailedAndStartedTests(waterfallRows, failedAndStartedTasks)
}
// if the last version was rolled-up, add it
if lastRolledUpVersion != nil {
finalVersions = append(finalVersions, *lastRolledUpVersion)
}
// create the list of display names for the build variants represented
buildVariants := waterfallBuildVariants{}
for name := range bvSet {
displayName := buildVariantMappings[name]
if displayName == "" {
displayName = name
}
buildVariants = append(buildVariants, waterfallBuildVariant{Id: name, DisplayName: displayName})
}
return versionVariantData{
Rows: waterfallRows,
Versions: finalVersions,
BuildVariants: buildVariants,
}, nil
}
// addFailedTests adds all of the failed tests associated with a task to its entry in the waterfallRow.
// addFailedAndStartedTests adds all of the failed tests associated with a task to its entry in the waterfallRow
// and adds the estimated duration to started tasks.
func addFailedAndStartedTests(waterfallRows map[string]waterfallRow, failedAndStartedTasks []task.Task) {
failedTestsByTaskId := map[string][]string{}
expectedDurationByTaskId := map[string]time.Duration{}
for _, t := range failedAndStartedTasks {
failedTests := []string{}
for _, r := range t.LocalTestResults {
if r.Status == evergreen.TestFailedStatus {
failedTests = append(failedTests, r.GetDisplayTestName())
}
}
if t.Status == evergreen.TaskStarted {
expectedDurationByTaskId[t.Id] = t.ExpectedDuration
}
failedTestsByTaskId[t.Id] = failedTests
}
for buildVariant, row := range waterfallRows {
for versionId, build := range row.Builds {
for i, task := range build.Tasks {
if len(failedTestsByTaskId[task.Id]) != 0 {
waterfallRows[buildVariant].Builds[versionId].Tasks[i].FailedTestNames = append(
waterfallRows[buildVariant].Builds[versionId].Tasks[i].FailedTestNames,
failedTestsByTaskId[task.Id]...)
sort.Strings(waterfallRows[buildVariant].Builds[versionId].Tasks[i].FailedTestNames)
}
if duration, ok := expectedDurationByTaskId[task.Id]; ok {
waterfallRows[buildVariant].Builds[versionId].Tasks[i].ExpectedDuration = duration
}
}
}
}
}
// Calculates how many actual versions would appear on the previous page, given
// the starting skip for the current page as well as the number of version
// elements per page (including elements containing rolled-up versions).
func countOnPreviousPage(skip int, numVersionElements int, project *model.Project, variantQuery string, showTriggered bool) (int, error) {
buildVariantMappings := project.GetVariantMappings()
// if there is no previous page
if skip == 0 {
return 0, nil
}
// the initial number of versions to be fetched per iteration
toFetch := numVersionElements
// the initial number of elements to step back from the current point
// (capped to 0)
stepBack := skip - numVersionElements
if stepBack < 0 {
toFetch = skip // only fetch up to the current point
stepBack = 0
}
// bookkeeping: the number of version elements represented so far, as well
// as the total number of versions fetched
elementsCreated := 0
versionsFetched := 0
// bookkeeping: whether the previous version was active
prevActive := true
for {
// fetch the versions and builds
versionsFromDB, buildsByVersion, tasksByBuild, err :=
model.FetchVersionsBuildsAndTasks(project, stepBack, toFetch, showTriggered)
if err != nil {
return 0, errors.Wrap(err, "error fetching versions and builds")
}
// for each of the versions fetched (iterating backwards), calculate
// how much it contributes to the version elements that would be
// created
for i := len(versionsFromDB) - 1; i >= 0; i-- {
versionFromDB := versionsFromDB[i]
// increment the versions we've fetched
versionsFetched += 1
// if there are any active tasks
buildsInVersion := buildsByVersion[versionFromDB.Id]
variantMatched := false
versionActive := false
for _, b := range buildsInVersion {
if task.AnyActiveTasks(tasksByBuild[b.Id]) {
versionActive = true
}
}
if versionActive {
for _, b := range buildsInVersion {
bvDisplayName := buildVariantMappings[b.BuildVariant]
if bvDisplayName == "" {
bvDisplayName = b.BuildVariant
}
// When versions is active and variane query matches
// variant display name, mark the version as inactive
if variantQuery != "" {
if !variantMatched {
variantMatched = variantHasActiveTasks(
bvDisplayName, variantQuery, tasksByBuild[b.Id],
)
}
} else {
variantMatched = true
}
}
// Skip versions which doen't match variant search query
if !variantMatched {
continue
}
// we may have stepped one over where the versions end, if
// the last was inactive
if elementsCreated == numVersionElements {
return versionsFetched - 1, nil
}
// the active version would get its own element
elementsCreated += 1
prevActive = true
// see if it's the last
if elementsCreated == numVersionElements {
return versionsFetched, nil
}
} else if prevActive {
// only record a rolled-up version when we hit the first version
// in it (walking backwards)
elementsCreated += 1
prevActive = false
}
}
// if we've hit the most recent versions (can't step back farther)
if stepBack == 0 {
return versionsFetched, nil
}
// recalculate where to skip to and how many to fetch
stepBack -= numVersionElements
if stepBack < 0 {
toFetch = stepBack + numVersionElements
stepBack = 0
}
}
}
func waterfallDataAdaptor(vvData versionVariantData, project *model.Project, skip int, variantQuery string, showUpstream bool) (waterfallData, error) {
var err error
finalData := waterfallData{}
var wfv waterfallVersions = vvData.Versions
sort.Sort(wfv)
finalData.Versions = wfv
sort.Sort(vvData.BuildVariants)
rows := []waterfallRow{}
for _, bv := range vvData.BuildVariants {
rows = append(rows, vvData.Rows[bv.Id])
}
finalData.Rows = rows
// compute the total number of versions that exist
finalData.TotalVersions, err = model.VersionCount(model.VersionByProjectId(project.Identifier))
if err != nil {
return waterfallData{}, err
}
// compute the number of versions on the previous page
finalData.PreviousPageCount, err = countOnPreviousPage(skip, waterfallPerPageLimit, project, variantQuery, showUpstream)
if err != nil {
return waterfallData{}, err
}
// add in the skip value
finalData.CurrentSkip = skip
// pass it the current time
finalData.CurrentTime = time.Now().UnixNano()
return finalData, nil
}
// Create and return the waterfall data we need to render the page.
// Http handler for the waterfall page
func (uis *UIServer) waterfallPage(w http.ResponseWriter, r *http.Request) {
projCtx := MustHaveProjectContext(r)
project, err := projCtx.GetProject()
if err != nil || project == nil {
uis.LoggedError(w, r, http.StatusNotFound, errors.New("project not found"))
return
}
newUILink := ""
if len(uis.Settings.Ui.UIv2Url) > 0 {
newUILink = fmt.Sprintf("%s/commits/%s", uis.Settings.Ui.UIv2Url, project.Identifier)
}
if RedirectSpruceUsers(w, r, newUILink) {
return
}
uis.render.WriteResponse(w, http.StatusOK, struct {
NewUILink string
JiraHost string
ViewData
}{newUILink, uis.Settings.Jira.Host, uis.GetCommonViewData(w, r, false, true)}, "base", "waterfall.html", "base_angular.html", "menu.html")
}
// Create and return a redirect to the spruce mainline commits page if the user is opted in to the new UI.
func (uis *UIServer) mainlineCommitsRedirect(w http.ResponseWriter, r *http.Request) {
u := gimlet.GetUser(r.Context())
if u != nil {
usr, ok := u.(*user.DBUser)
if ok {
// If the user is opted in to the new UI, redirect to the new UI.
if usr.Settings.UseSpruceOptions.SpruceV1 {
http.Redirect(w, r, fmt.Sprintf("%s/commits/", uis.Settings.Ui.UIv2Url), http.StatusSeeOther)
}
}
}
// fallback and redirect to the old UI waterfall.
http.Redirect(w, r, "/waterfall", http.StatusSeeOther)
}
func (restapi restAPI) getWaterfallData(w http.ResponseWriter, r *http.Request) {
projCtx := MustHaveRESTContext(r)
project, err := projCtx.GetProject()
if err != nil || project == nil {
gimlet.WriteJSONResponse(w, http.StatusNotFound, responseError{Message: "error finding project"})
return
}
query := r.URL.Query()
skipQ := query.Get(waterfallSkipParam)
skip := 0
if skipQ != "" {
skip, err = strconv.Atoi(skipQ)
if err != nil {
gimlet.WriteJSONResponse(
w, http.StatusNotFound, responseError{Message: errors.Wrapf(
err, "Invalid 'skip' value '%s'", skipQ).Error()},
)
return
}
}
limit, err := strconv.Atoi(query.Get("limit"))
if err != nil {
limit = waterfallPerPageLimit
}
variantQuery := strings.TrimSpace(query.Get(waterfallBVFilterParam))
showUpstream := (query.Get(showUpstreamParam) == "true")
vvData, err := getVersionsAndVariants(skip, limit, project, variantQuery, showUpstream)
if err != nil {
gimlet.WriteJSONResponse(
w, http.StatusNotFound, responseError{Message: errors.Wrap(
err, "Error while loading versions and variants data").Error()},
)
return
}
finalData, err := waterfallDataAdaptor(vvData, project, skip, variantQuery, showUpstream)
if err != nil {
gimlet.WriteJSONResponse(
w, http.StatusNotFound, responseError{Message: errors.Wrap(
err, "Error while processing versions and variants data").Error()},
)
return
}
gimlet.WriteJSONResponse(w, http.StatusOK, finalData)
}