Skip to content

Commit 96335e5

Browse files
batches: upsert batch change when running `src batch remote (#787)
* upsert batch change when running `src batch remote * use batchChangeName for execution url * update changelog * add createBatchSpecFromRaw query * Update CHANGELOG.md Co-authored-by: Adam Harvey <adam@adamharvey.name> * remove redundant UpsertBatchSpecInput method Co-authored-by: Adam Harvey <adam@adamharvey.name>
1 parent 524c89a commit 96335e5

4 files changed

Lines changed: 66 additions & 10 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ All notable changes to `src-cli` are documented in this file.
1919

2020
### Fixed
2121

22+
- The preview link shown when running `src batch remote` to create a new batch change no longer 404s. [sourcegraph/src-cli](https://github.com/sourcegraph/src-cli/pull/787)
23+
2224
### Removed
2325

2426
## 3.40.11

cmd/src/batch_remote.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,15 @@ Examples:
7878
}
7979
ui.ResolvingNamespaceSuccess(namespace.ID)
8080

81+
ui.SendingBatchChange()
82+
batchChangeName, err := svc.UpsertBatchChange(ctx, spec.Name, namespace.ID)
83+
if err != nil {
84+
return err
85+
}
86+
ui.SendingBatchChangeSuccess()
87+
8188
ui.SendingBatchSpec()
82-
batchSpecID, err := svc.UpsertBatchSpecInput(
89+
batchSpecID, err := svc.CreateBatchSpecFromRaw(
8390
ctx,
8491
raw,
8592
namespace.ID,
@@ -125,7 +132,7 @@ Examples:
125132
"%s/%s/batch-changes/%s/executions/%s",
126133
strings.TrimSuffix(cfg.Endpoint, "/"),
127134
strings.TrimPrefix(namespace.URL, "/"),
128-
spec.Name,
135+
batchChangeName,
129136
batchSpecID,
130137
)
131138
ui.RemoteSuccess(executionURL)

internal/batches/service/remote.go

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,54 @@ func (svc *Service) areServerSideBatchChangesSupported() error {
1515
return nil
1616
}
1717

18-
const upsertBatchSpecInputQuery = `
19-
mutation UpsertBatchSpecInput(
18+
const upsertEmptyBatchChangeQuery = `
19+
mutation UpsertEmptyBatchChange(
20+
$name: String!
21+
$namespace: ID!
22+
) {
23+
upsertEmptyBatchChange(
24+
name: $name,
25+
namespace: $namespace
26+
) {
27+
name
28+
}
29+
}
30+
`
31+
32+
func (svc *Service) UpsertBatchChange(
33+
ctx context.Context,
34+
name string,
35+
namespaceID string,
36+
) (string, error) {
37+
if err := svc.areServerSideBatchChangesSupported(); err != nil {
38+
return "", err
39+
}
40+
41+
var resp struct {
42+
UpsertEmptyBatchChange struct {
43+
Name string `json:"name"`
44+
} `json:"upsertEmptyBatchChange"`
45+
}
46+
47+
if ok, err := svc.client.NewRequest(upsertEmptyBatchChangeQuery, map[string]interface{}{
48+
"name": name,
49+
"namespace": namespaceID,
50+
}).Do(ctx, &resp); err != nil || !ok {
51+
return "", err
52+
}
53+
54+
return resp.UpsertEmptyBatchChange.Name, nil
55+
}
56+
57+
const createBatchSpecFromRawQuery = `
58+
mutation CreateBatchSpecFromRaw(
2059
$batchSpec: String!,
2160
$namespace: ID!,
2261
$allowIgnored: Boolean!,
2362
$allowUnsupported: Boolean!,
2463
$noCache: Boolean!,
2564
) {
26-
upsertBatchSpecInput(
65+
createBatchSpecFromRaw(
2766
batchSpec: $batchSpec,
2867
namespace: $namespace,
2968
allowIgnored: $allowIgnored,
@@ -35,7 +74,7 @@ mutation UpsertBatchSpecInput(
3574
}
3675
`
3776

38-
func (svc *Service) UpsertBatchSpecInput(
77+
func (svc *Service) CreateBatchSpecFromRaw(
3978
ctx context.Context,
4079
batchSpec string,
4180
namespaceID string,
@@ -48,12 +87,12 @@ func (svc *Service) UpsertBatchSpecInput(
4887
}
4988

5089
var resp struct {
51-
UpsertBatchSpecInput struct {
90+
CreateBatchSpecFromRaw struct {
5291
ID string `json:"id"`
53-
} `json:"upsertBatchSpecInput"`
92+
} `json:"createBatchSpecFromRaw"`
5493
}
5594

56-
if ok, err := svc.client.NewRequest(upsertBatchSpecInputQuery, map[string]interface{}{
95+
if ok, err := svc.client.NewRequest(createBatchSpecFromRawQuery, map[string]interface{}{
5796
"batchSpec": batchSpec,
5897
"namespace": namespaceID,
5998
"allowIgnored": allowIgnored,
@@ -63,7 +102,7 @@ func (svc *Service) UpsertBatchSpecInput(
63102
return "", err
64103
}
65104

66-
return resp.UpsertBatchSpecInput.ID, nil
105+
return resp.CreateBatchSpecFromRaw.ID, nil
67106
}
68107

69108
const executeBatchSpecQuery = `

internal/batches/ui/tui.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,14 @@ func (ui *TUI) ApplyingBatchSpecSuccess(batchChangeURL string) {
223223
block.Writef("%s", batchChangeURL)
224224
}
225225

226+
func (ui *TUI) SendingBatchChange() {
227+
ui.pending = batchCreatePending(ui.Out, "Sending batch change")
228+
}
229+
230+
func (ui *TUI) SendingBatchChangeSuccess() {
231+
batchCompletePending(ui.pending, "Sending batch change")
232+
}
233+
226234
func (ui *TUI) SendingBatchSpec() {
227235
ui.pending = batchCreatePending(ui.Out, "Sending batch spec")
228236
}

0 commit comments

Comments
 (0)