-
Notifications
You must be signed in to change notification settings - Fork 126
/
get_step_run_diff.go
43 lines (33 loc) · 1.13 KB
/
get_step_run_diff.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
package workflows
import (
"errors"
"fmt"
"github.com/labstack/echo/v4"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/apierrors"
"github.com/hatchet-dev/hatchet/api/v1/server/oas/gen"
"github.com/hatchet-dev/hatchet/internal/integrations/vcs/vcsutils"
"github.com/hatchet-dev/hatchet/internal/repository/prisma/db"
)
func (t *WorkflowService) StepRunGetDiff(ctx echo.Context, request gen.StepRunGetDiffRequestObject) (gen.StepRunGetDiffResponseObject, error) {
stepRun := ctx.Get("step-run").(*db.StepRunModel)
diffs, originalValues, err := vcsutils.GetStepRunOverrideDiffs(t.config.APIRepository.StepRun(), stepRun)
if err != nil {
if errors.Is(err, vcsutils.ErrNoInput) {
return gen.StepRunGetDiff404JSONResponse(
apierrors.NewAPIErrors("step run does not have an input"),
), nil
}
return nil, fmt.Errorf("could not get diffs: %s", err)
}
resp := make([]gen.StepRunDiff, 0)
for key, val := range diffs {
resp = append(resp, gen.StepRunDiff{
Key: key,
Modified: val,
Original: originalValues[key],
})
}
return gen.StepRunGetDiff200JSONResponse(gen.GetStepRunDiffResponse{
Diffs: resp,
}), nil
}