Skip to content

Commit 010bfe5

Browse files
authored
Merge pull request ActiveState#3321 from ActiveState/DX-2784
Update `state eval` to trigger a build
2 parents fbb7ea6 + 1bdd2cb commit 010bfe5

File tree

5 files changed

+50
-67
lines changed

5 files changed

+50
-67
lines changed

activestate.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,4 @@ events:
467467
- name: file-changed
468468
scope: ["internal/locale/locales"]
469469
value: build
470+
config_version: 1

internal/runners/eval/rationalize.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func rationalizeError(rerr *error) {
2222
switch {
2323
case errors.Is(*rerr, rationalize.ErrNotAuthenticated):
2424
*rerr = errs.WrapUserFacing(*rerr,
25-
locale.T("err_init_authenticated"),
25+
locale.Tl("err_eval_not_authenticated", "You need to authenticate to evaluate a target"),
2626
errs.SetInput(),
2727
)
2828

pkg/platform/api/buildplanner/model/buildplan.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ const (
9696
RevertConflictErrorType = "RevertConflict"
9797
CommitNotInTargetHistoryErrorType = "CommitNotInTargetHistory"
9898
ComitHasNoParentErrorType = "CommitHasNoParent"
99+
TargetNotFoundErrorType = "TargetNotFound"
99100
)
100101

101102
func IsStateToolArtifact(mimeType string) bool {
@@ -416,6 +417,12 @@ func processPlanningError(message string, subErrors []*BuildExprLocation) error
416417
}
417418

418419
for _, se := range subErrors {
420+
if se.Type == TargetNotFoundErrorType {
421+
return &BuildPlannerError{
422+
Err: locale.NewInputError("err_buildplanner_target_not_found", "{{.V0}}", se.Message),
423+
}
424+
}
425+
419426
if se.Type != RemediableSolveErrorType && se.Type != GenericSolveErrorType {
420427
continue
421428
}
@@ -559,7 +566,7 @@ type MergeCommitResult struct {
559566
}
560567

561568
type BuildTargetResult struct {
562-
Project *Project `json:"Project"`
569+
Build *Build `json:"buildCommitTarget"`
563570
*Error
564571
*NotFoundError
565572
}

pkg/platform/api/buildplanner/request/evaluate.go

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,47 @@ type evaluate struct {
1515

1616
func (b *evaluate) Query() string {
1717
return `
18-
query ($organization: String!, $project: String!, $commitId: String!, $target: String!) {
19-
project(organization: $organization, project: $project) {
20-
... on Project {
18+
mutation ($organization: String!, $project: String!, $commitId: String!, $target: String) {
19+
buildCommitTarget(
20+
input: {organization: $organization, project: $project, commitId: $commitId, target: $target}
21+
) {
22+
... on Build {
2123
__typename
22-
commit(vcsRef: $commitId) {
23-
... on Commit {
24-
__typename
25-
build(target: $target) {
26-
... on Build {
27-
__typename
28-
status
29-
}
30-
... on PlanningError {
31-
__typename
32-
message
33-
subErrors {
34-
__typename
35-
... on GenericSolveError {
36-
path
37-
message
38-
isTransient
39-
validationErrors {
40-
error
41-
jsonPath
42-
}
43-
}
44-
... on RemediableSolveError {
45-
path
46-
message
47-
isTransient
48-
errorType
49-
validationErrors {
50-
error
51-
jsonPath
52-
}
53-
suggestedRemediations {
54-
remediationType
55-
command
56-
parameters
57-
}
58-
}
59-
}
60-
}
24+
status
25+
}
26+
... on PlanningError {
27+
__typename
28+
message
29+
subErrors {
30+
__typename
31+
... on GenericSolveError {
32+
buildExprPath
33+
message
34+
isTransient
35+
validationErrors {
36+
error
37+
jsonPath
38+
}
39+
}
40+
... on RemediableSolveError {
41+
buildExprPath
42+
message
43+
isTransient
44+
errorType
45+
validationErrors {
46+
error
47+
jsonPath
48+
}
49+
suggestedRemediations {
50+
remediationType
51+
command
52+
parameters
6153
}
6254
}
63-
... on NotFound {
64-
type
55+
... on TargetNotFound {
6556
message
66-
resource
67-
mayNeedAuthentication
57+
requestedTarget
58+
possibleTargets
6859
}
6960
}
7061
}

pkg/platform/model/buildplanner.go

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -687,28 +687,12 @@ func (bp *BuildPlanner) BuildTarget(owner, project, commitID, target string) err
687687
return processBuildPlannerError(err, "Failed to evaluate target")
688688
}
689689

690-
if resp.Project == nil {
691-
return errs.New("Project is nil")
692-
}
693-
694-
if bpModel.IsErrorResponse(resp.Project.Type) {
695-
return bpModel.ProcessProjectError(resp.Project, "Could not evaluate target")
696-
}
697-
698-
if resp.Project.Commit == nil {
699-
return errs.New("Commit is nil")
700-
}
701-
702-
if bpModel.IsErrorResponse(resp.Project.Commit.Type) {
703-
return bpModel.ProcessCommitError(resp.Project.Commit, "Could not process error response from evaluate target")
704-
}
705-
706-
if resp.Project.Commit.Build == nil {
690+
if resp.Build == nil {
707691
return errs.New("Build is nil")
708692
}
709693

710-
if bpModel.IsErrorResponse(resp.Project.Commit.Build.Type) {
711-
return bpModel.ProcessBuildError(resp.Project.Commit.Build, "Could not process error response from evaluate target")
694+
if bpModel.IsErrorResponse(resp.Build.Type) {
695+
return bpModel.ProcessBuildError(resp.Build, "Could not process error response from evaluate target")
712696
}
713697

714698
return nil

0 commit comments

Comments
 (0)