Skip to content

Commit da1352b

Browse files
authored
Revert results controller and status endpoint changes (#459)
1 parent 124ffc6 commit da1352b

File tree

8 files changed

+38
-183
lines changed

8 files changed

+38
-183
lines changed

cmd/rwx/results.go

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,19 @@ package main
33
import (
44
"encoding/json"
55
"fmt"
6-
"os"
76

87
"github.com/rwx-cloud/rwx/internal/cli"
98
"github.com/rwx-cloud/rwx/internal/git"
109

11-
"github.com/skratchdot/open-golang/open"
1210
"github.com/spf13/cobra"
1311
)
1412

1513
var (
1614
ResultsWait bool
1715
ResultsFailFast bool
18-
ResultsOpen bool
1916
ResultsBranch string
2017
ResultsRepo string
2118
ResultsDefinition string
22-
ResultsCommit string
2319

2420
resultsCmd = &cobra.Command{
2521
GroupID: "outputs",
@@ -42,7 +38,6 @@ var (
4238
BranchName: ResultsBranch,
4339
RepositoryName: ResultsRepo,
4440
DefinitionPath: ResultsDefinition,
45-
CommitSha: ResultsCommit,
4641
})
4742
if err != nil {
4843
return err
@@ -83,9 +78,7 @@ var (
8378
}
8479
}
8580
}
86-
if result.TaskURL != "" {
87-
fmt.Printf("Task URL: %s\n", result.TaskURL)
88-
} else if result.RunURL != "" {
81+
if result.RunURL != "" {
8982
fmt.Printf("Run URL: %s\n", result.RunURL)
9083
}
9184
if result.Completed {
@@ -100,18 +93,6 @@ var (
10093
}
10194
}
10295

103-
if ResultsOpen {
104-
openURL := result.RunURL
105-
if result.TaskURL != "" {
106-
openURL = result.TaskURL
107-
}
108-
if openURL != "" {
109-
if err := open.Run(openURL); err != nil {
110-
fmt.Fprintf(os.Stderr, "Failed to open browser.\n")
111-
}
112-
}
113-
}
114-
11596
if result.Completed && result.ResultStatus != "succeeded" {
11697
return HandledError
11798
}
@@ -122,11 +103,9 @@ var (
122103
)
123104

124105
func init() {
125-
resultsCmd.Flags().BoolVar(&ResultsOpen, "open", false, "open the run in a browser")
126106
resultsCmd.Flags().BoolVar(&ResultsWait, "wait", false, "poll for the run to complete and report the result status")
127107
resultsCmd.Flags().BoolVar(&ResultsFailFast, "fail-fast", false, "stop waiting when failures are available (only has an effect when used with --wait)")
128108
resultsCmd.Flags().StringVar(&ResultsBranch, "branch", "", "get results for a specific branch instead of the current git branch")
129109
resultsCmd.Flags().StringVar(&ResultsRepo, "repo", "", "get results for a specific repository instead of the current git repository")
130110
resultsCmd.Flags().StringVar(&ResultsDefinition, "definition", "", "get results for a specific definition path")
131-
resultsCmd.Flags().StringVar(&ResultsCommit, "commit", "", "get results for a specific commit SHA")
132111
}

internal/api/client.go

Lines changed: 22 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ func (c Client) GetSkillLatestVersion() (string, error) {
8787
defer resp.Body.Close()
8888

8989
if resp.StatusCode != 200 {
90-
msg := extractErrorMessage(resp.Body)
91-
if msg == "" {
92-
msg = fmt.Sprintf("Unable to call RWX API - %s", resp.Status)
93-
}
94-
return "", errors.New(msg)
90+
return "", errors.New(fmt.Sprintf("Unable to call RWX API - %s", resp.Status))
9591
}
9692

9793
var result struct {
@@ -141,11 +137,7 @@ func (c Client) GetDebugConnectionInfo(debugKey string) (DebugConnectionInfo, er
141137
}
142138
return connectionInfo, errors.ErrGone
143139
default:
144-
msg := extractErrorMessage(resp.Body)
145-
if msg == "" {
146-
msg = fmt.Sprintf("Unable to call RWX API - %s", resp.Status)
147-
}
148-
return connectionInfo, errors.New(msg)
140+
return connectionInfo, errors.New(fmt.Sprintf("Unable to call RWX API - %s", resp.Status))
149141
}
150142

151143
if err := json.NewDecoder(resp.Body).Decode(&connectionInfo); err != nil {
@@ -202,11 +194,7 @@ func (c Client) GetSandboxConnectionInfo(runID, scopedToken string) (SandboxConn
202194
}
203195
return connectionInfo, errors.ErrGone
204196
default:
205-
msg := extractErrorMessage(resp.Body)
206-
if msg == "" {
207-
msg = fmt.Sprintf("Unable to call RWX API - %s", resp.Status)
208-
}
209-
return connectionInfo, errors.New(msg)
197+
return connectionInfo, errors.New(fmt.Sprintf("Unable to call RWX API - %s", resp.Status))
210198
}
211199

212200
if err := json.NewDecoder(resp.Body).Decode(&connectionInfo); err != nil {
@@ -352,11 +340,15 @@ func (c Client) InitiateDispatch(cfg InitiateDispatchConfig) (*InitiateDispatchR
352340
defer resp.Body.Close()
353341

354342
if resp.StatusCode != 201 {
355-
msg := extractErrorMessage(resp.Body)
356-
if msg == "" {
357-
msg = fmt.Sprintf("Unable to call RWX API - %s", resp.Status)
343+
errorStruct := struct {
344+
Error string `json:"error,omitempty"`
345+
}{}
346+
347+
if err := json.NewDecoder(resp.Body).Decode(&errorStruct); err != nil {
348+
return nil, errors.New(fmt.Sprintf("Unable to call RWX API - %s", resp.Status))
358349
}
359-
return nil, errors.New(msg)
350+
351+
return nil, errors.New(errorStruct.Error)
360352
}
361353

362354
respBody := struct {
@@ -389,11 +381,7 @@ func (c Client) GetDispatch(cfg GetDispatchConfig) (*GetDispatchResult, error) {
389381
defer resp.Body.Close()
390382

391383
if resp.StatusCode != 200 {
392-
msg := extractErrorMessage(resp.Body)
393-
if msg == "" {
394-
msg = fmt.Sprintf("Unable to call RWX API - %s", resp.Status)
395-
}
396-
return nil, errors.New(msg)
384+
return nil, errors.New(fmt.Sprintf("Unable to call RWX API - %s", resp.Status))
397385
}
398386

399387
respBody := struct {
@@ -440,11 +428,7 @@ func (c Client) ObtainAuthCode(cfg ObtainAuthCodeConfig) (*ObtainAuthCodeResult,
440428
defer resp.Body.Close()
441429

442430
if resp.StatusCode != 201 {
443-
msg := extractErrorMessage(resp.Body)
444-
if msg == "" {
445-
msg = fmt.Sprintf("Unable to call RWX API - %s", resp.Status)
446-
}
447-
return nil, errors.New(msg)
431+
return nil, errors.New(fmt.Sprintf("Unable to call RWX API - %s", resp.Status))
448432
}
449433

450434
respBody := ObtainAuthCodeResult{}
@@ -470,11 +454,7 @@ func (c Client) AcquireToken(tokenUrl string) (*AcquireTokenResult, error) {
470454
defer resp.Body.Close()
471455

472456
if resp.StatusCode != 200 {
473-
msg := extractErrorMessage(resp.Body)
474-
if msg == "" {
475-
msg = fmt.Sprintf("Unable to query the token URL - %s", resp.Status)
476-
}
477-
return nil, errors.New(msg)
457+
return nil, errors.New(fmt.Sprintf("Unable to query the token URL - %s", resp.Status))
478458
}
479459

480460
respBody := AcquireTokenResult{}
@@ -503,11 +483,7 @@ func (c Client) Whoami() (*WhoamiResult, error) {
503483
defer resp.Body.Close()
504484

505485
if resp.StatusCode != 200 {
506-
msg := extractErrorMessage(resp.Body)
507-
if msg == "" {
508-
msg = fmt.Sprintf("Unable to call RWX API - %s", resp.Status)
509-
}
510-
return nil, errors.New(msg)
486+
return nil, errors.New(fmt.Sprintf("Unable to call RWX API - %s", resp.Status))
511487
}
512488

513489
respBody := WhoamiResult{}
@@ -535,11 +511,7 @@ func (c Client) CreateDocsToken() (*DocsTokenResult, error) {
535511
defer resp.Body.Close()
536512

537513
if resp.StatusCode != 201 && resp.StatusCode != 200 {
538-
msg := extractErrorMessage(resp.Body)
539-
if msg == "" {
540-
msg = fmt.Sprintf("Unable to call RWX API - %s", resp.Status)
541-
}
542-
return nil, errors.New(msg)
514+
return nil, errors.New(fmt.Sprintf("Unable to call RWX API - %s", resp.Status))
543515
}
544516

545517
respBody := DocsTokenResult{}
@@ -955,10 +927,7 @@ func (c Client) ImagePushStatus(pushID string) (ImagePushStatusResult, error) {
955927
}
956928

957929
func (c Client) TaskKeyStatus(cfg TaskKeyStatusConfig) (TaskStatusResult, error) {
958-
params := url.Values{}
959-
params.Set("run_id", cfg.RunID)
960-
params.Set("task_key", cfg.TaskKey)
961-
endpoint := "/mint/api/results/task_status?" + params.Encode()
930+
endpoint := fmt.Sprintf("/mint/api/runs/%s/task_status?task_key=%s", url.PathEscape(cfg.RunID), url.PathEscape(cfg.TaskKey))
962931
result := TaskStatusResult{}
963932

964933
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
@@ -982,7 +951,7 @@ func (c Client) TaskKeyStatus(cfg TaskKeyStatusConfig) (TaskStatusResult, error)
982951
}
983952

984953
func (c Client) TaskIDStatus(cfg TaskIDStatusConfig) (TaskStatusResult, error) {
985-
endpoint := fmt.Sprintf("/mint/api/results/status?id=%s", url.QueryEscape(cfg.TaskID))
954+
endpoint := fmt.Sprintf("/mint/api/tasks/%s/status", url.PathEscape(cfg.TaskID))
986955
result := TaskStatusResult{}
987956

988957
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
@@ -1009,24 +978,16 @@ func (c Client) RunStatus(cfg RunStatusConfig) (RunStatusResult, error) {
1009978
var endpoint string
1010979
failFast := fmt.Sprintf("%t", cfg.FailFast)
1011980
if cfg.RunID != "" {
1012-
params := url.Values{}
1013-
params.Set("id", cfg.RunID)
1014-
params.Set("fail_fast", failFast)
1015-
endpoint = "/mint/api/results/status?" + params.Encode()
981+
endpoint = fmt.Sprintf("/mint/api/runs/%s?fail_fast=%s", url.PathEscape(cfg.RunID), failFast)
1016982
} else {
1017983
params := url.Values{}
1018984
params.Set("fail_fast", failFast)
1019-
if cfg.BranchName != "" {
1020-
params.Set("branch_name", cfg.BranchName)
1021-
}
985+
params.Set("branch_name", cfg.BranchName)
1022986
params.Set("repository_name", cfg.RepositoryName)
1023987
if cfg.DefinitionPath != "" {
1024988
params.Set("definition_path", cfg.DefinitionPath)
1025989
}
1026-
if cfg.CommitSha != "" {
1027-
params.Set("commit_sha", cfg.CommitSha)
1028-
}
1029-
endpoint = "/mint/api/results/latest?" + params.Encode()
990+
endpoint = "/mint/api/runs/latest?" + params.Encode()
1030991
}
1031992
result := RunStatusResult{}
1032993

@@ -1051,7 +1012,7 @@ func (c Client) RunStatus(cfg RunStatusConfig) (RunStatusResult, error) {
10511012
}
10521013

10531014
func (c Client) GetRunPrompt(runID string) (string, error) {
1054-
endpoint := fmt.Sprintf("/mint/api/results/prompt?id=%s", url.QueryEscape(runID))
1015+
endpoint := fmt.Sprintf("/mint/api/runs/%s/prompt", url.PathEscape(runID))
10551016

10561017
req, err := http.NewRequest(http.MethodGet, endpoint, nil)
10571018
if err != nil {

internal/api/client_test.go

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,7 @@ func TestAPIClient_ImagePushStatus(t *testing.T) {
375375
func TestAPIClient_TaskIDStatus(t *testing.T) {
376376
t.Run("builds the request and parses the response", func(t *testing.T) {
377377
roundTrip := func(req *http.Request) (*http.Response, error) {
378-
require.Equal(t, "/mint/api/results/status", req.URL.Path)
379-
require.Equal(t, "abc123", req.URL.Query().Get("id"))
378+
require.Equal(t, "/mint/api/tasks/abc123/status", req.URL.Path)
380379
require.Equal(t, http.MethodGet, req.Method)
381380

382381
body := `{"polling": {"completed": true}}`
@@ -892,8 +891,7 @@ func TestAPIClient_RunStatus(t *testing.T) {
892891
bodyBytes, _ := json.Marshal(body)
893892

894893
roundTrip := func(req *http.Request) (*http.Response, error) {
895-
require.Equal(t, "/mint/api/results/status", req.URL.Path)
896-
require.Equal(t, "run-123", req.URL.Query().Get("id"))
894+
require.Equal(t, "/mint/api/runs/run-123", req.URL.Path)
897895
require.Equal(t, "true", req.URL.Query().Get("fail_fast"))
898896
require.Equal(t, http.MethodGet, req.Method)
899897
return &http.Response{
@@ -953,8 +951,7 @@ func TestAPIClient_RunStatus(t *testing.T) {
953951
bodyBytes, _ := json.Marshal(body)
954952

955953
roundTrip := func(req *http.Request) (*http.Response, error) {
956-
require.Equal(t, "/mint/api/results/status", req.URL.Path)
957-
require.Equal(t, "run-456", req.URL.Query().Get("id"))
954+
require.Equal(t, "/mint/api/runs/run-456", req.URL.Path)
958955
require.Equal(t, http.MethodGet, req.Method)
959956
return &http.Response{
960957
Status: "200 OK",
@@ -1204,8 +1201,7 @@ func TestAPIClient_CreateSandboxToken(t *testing.T) {
12041201
func TestAPIClient_GetRunPrompt(t *testing.T) {
12051202
t.Run("builds the request and returns the prompt text", func(t *testing.T) {
12061203
roundTrip := func(req *http.Request) (*http.Response, error) {
1207-
require.Equal(t, "/mint/api/results/prompt", req.URL.Path)
1208-
require.Equal(t, "run-123", req.URL.Query().Get("id"))
1204+
require.Equal(t, "/mint/api/runs/run-123/prompt", req.URL.Path)
12091205
require.Equal(t, http.MethodGet, req.Method)
12101206
require.Equal(t, "text/plain", req.Header.Get("Accept"))
12111207
return &http.Response{

internal/api/config.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ type RunStatusConfig struct {
332332
BranchName string
333333
RepositoryName string
334334
DefinitionPath string
335-
CommitSha string
336335
FailFast bool
337336
}
338337

@@ -341,14 +340,11 @@ type RunStatus struct {
341340
}
342341

343342
type RunStatusResult struct {
344-
Status *RunStatus `json:"run_status,omitempty"`
345-
TaskStatus *TaskStatus `json:"task_status,omitempty"`
346-
RunID string `json:"run_id,omitempty"`
347-
RunURL string `json:"run_url,omitempty"`
348-
TaskID string `json:"task_id,omitempty"`
349-
TaskURL string `json:"task_url,omitempty"`
350-
Commit *string `json:"commit_sha,omitempty"`
351-
Polling PollingResult `json:"polling"`
343+
Status *RunStatus `json:"run_status,omitempty"`
344+
RunID string `json:"run_id,omitempty"`
345+
RunURL string `json:"run_url,omitempty"`
346+
Commit *string `json:"commit_sha,omitempty"`
347+
Polling PollingResult `json:"polling"`
352348
}
353349

354350
type AmbiguousTaskKeyError struct {

internal/cli/service.go

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,6 @@ type ResolveRunIDConfig struct {
233233
BranchName string
234234
RepositoryName string
235235
DefinitionPath string
236-
CommitSha string
237236
}
238237

239238
// ResolveRunIDFromGitContext resolves the latest run ID by looking up the
@@ -245,35 +244,28 @@ func (s Service) ResolveRunIDFromGitContext(overrides ...ResolveRunIDConfig) (st
245244
cfg = overrides[0]
246245
}
247246

248-
branchName := cfg.BranchName
249-
if branchName == "" && cfg.CommitSha == "" {
250-
branchName = s.GitClient.GetBranch()
247+
branchName := s.GitClient.GetBranch()
248+
if cfg.BranchName != "" {
249+
branchName = cfg.BranchName
251250
}
252251
repositoryName := git.RepoNameFromOriginUrl(s.GitClient.GetOriginUrl())
253252
if cfg.RepositoryName != "" {
254253
repositoryName = cfg.RepositoryName
255254
}
256255

257-
if repositoryName == "" || (branchName == "" && cfg.CommitSha == "") {
256+
if branchName == "" || repositoryName == "" {
258257
return "", errors.New("unable to determine the current branch and repository from git; please provide a run ID")
259258
}
260259

261260
result, err := s.APIClient.RunStatus(api.RunStatusConfig{
262261
BranchName: branchName,
263262
RepositoryName: repositoryName,
264263
DefinitionPath: cfg.DefinitionPath,
265-
CommitSha: cfg.CommitSha,
266264
})
267-
notFoundMsg := fmt.Sprintf("no run found for %s repository", repositoryName)
268-
if branchName != "" {
269-
notFoundMsg += fmt.Sprintf(" on branch %s", branchName)
270-
}
265+
notFoundMsg := fmt.Sprintf("no run found for %s repository on branch %s", repositoryName, branchName)
271266
if cfg.DefinitionPath != "" {
272267
notFoundMsg += fmt.Sprintf(" with definition %s", cfg.DefinitionPath)
273268
}
274-
if cfg.CommitSha != "" {
275-
notFoundMsg += fmt.Sprintf(" at commit %s", cfg.CommitSha)
276-
}
277269

278270
if err != nil {
279271
if errors.Is(err, api.ErrNotFound) {

0 commit comments

Comments
 (0)