Skip to content

Commit 34814f1

Browse files
Merge branch 'dependabot:main' into main
2 parents 5e7de98 + a61544f commit 34814f1

File tree

8 files changed

+129
-42
lines changed

8 files changed

+129
-42
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ jobs:
2222
go-version-file: go.mod
2323

2424
- name: Initialize CodeQL
25-
uses: github/codeql-action/init@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
25+
uses: github/codeql-action/init@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
2626
with:
2727
languages: 'go'
2828

2929
- name: Autobuild
30-
uses: github/codeql-action/autobuild@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
30+
uses: github/codeql-action/autobuild@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
3131

3232
- name: Perform CodeQL Analysis
33-
uses: github/codeql-action/analyze@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
33+
uses: github/codeql-action/analyze@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
ldflags: >-
3838
-X github.com/dependabot/cli/cmd/dependabot/internal/cmd.version=${{ github.event.release.tag_name }}
3939
40-
- uses: actions/attest-build-provenance@db473fddc028af60658334401dc6fa3ffd8669fd # v2.3.3
40+
- uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.3.3
4141
with:
4242
subject-path: |
4343
${{ steps.go_release.outputs.release_asset_dir }}/*

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ jobs:
3333
results_file: results.sarif
3434
results_format: sarif
3535

36-
- uses: github/codeql-action/upload-sarif@ff0a06e83cb2de871e5a09832bc6a81e7276941f # v3.28.18
36+
- uses: github/codeql-action/upload-sarif@ce28f5bb42b7a9f2c824e633a3f6ee835bab6858 # v3.29.0
3737
with:
3838
sarif_file: results.sarif

go.mod

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ go 1.24.0
44

55
require (
66
github.com/MakeNowJust/heredoc v1.0.0
7-
github.com/docker/cli v28.2.2+incompatible
8-
github.com/docker/docker v28.2.2+incompatible
9-
github.com/google/go-containerregistry v0.20.5
7+
github.com/docker/cli v28.3.0+incompatible
8+
github.com/docker/docker v28.3.0+incompatible
9+
github.com/google/go-containerregistry v0.20.6
1010
github.com/goware/prefixer v0.0.0-20160118172347-395022866408
1111
github.com/hexops/gotextdiff v1.0.3
12-
github.com/moby/moby v28.2.2+incompatible
12+
github.com/moby/moby v28.3.0+incompatible
1313
github.com/moby/sys/signal v0.7.1
1414
github.com/spf13/cobra v1.9.1
1515
gopkg.in/yaml.v3 v3.0.1
@@ -56,9 +56,9 @@ require (
5656
go.opentelemetry.io/otel/metric v1.36.0 // indirect
5757
go.opentelemetry.io/otel/trace v1.36.0 // indirect
5858
go.opentelemetry.io/proto/otlp v1.7.0 // indirect
59-
golang.org/x/sync v0.14.0 // indirect
59+
golang.org/x/sync v0.15.0 // indirect
6060
golang.org/x/sys v0.33.0 // indirect
61-
golang.org/x/time v0.11.0 // indirect
62-
golang.org/x/tools v0.33.0 // indirect
61+
golang.org/x/time v0.12.0 // indirect
62+
golang.org/x/tools v0.34.0 // indirect
6363
google.golang.org/protobuf v1.36.6 // indirect
6464
)

go.sum

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
2424
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
2525
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
2626
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
27-
github.com/docker/cli v28.2.2+incompatible h1:qzx5BNUDFqlvyq4AHzdNB7gSyVTmU4cgsyN9SdInc1A=
28-
github.com/docker/cli v28.2.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
27+
github.com/docker/cli v28.3.0+incompatible h1:s+ttruVLhB5ayeuf2BciwDVxYdKi+RoUlxmwNHV3Vfo=
28+
github.com/docker/cli v28.3.0+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
2929
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
3030
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
31-
github.com/docker/docker v28.2.2+incompatible h1:CjwRSksz8Yo4+RmQ339Dp/D2tGO5JxwYeqtMOEe0LDw=
32-
github.com/docker/docker v28.2.2+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
31+
github.com/docker/docker v28.3.0+incompatible h1:ffS62aKWupCWdvcee7nBU9fhnmknOqDPaJAMtfK0ImQ=
32+
github.com/docker/docker v28.3.0+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
3333
github.com/docker/docker-credential-helpers v0.9.3 h1:gAm/VtF9wgqJMoxzT3Gj5p4AqIjCBS4wrsOh9yRqcz8=
3434
github.com/docker/docker-credential-helpers v0.9.3/go.mod h1:x+4Gbw9aGmChi3qTLZj8Dfn0TD20M/fuWy0E5+WDeCo=
3535
github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj1Br63c=
@@ -47,8 +47,8 @@ github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
4747
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
4848
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
4949
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
50-
github.com/google/go-containerregistry v0.20.5 h1:4RnlYcDs5hoA++CeFjlbZ/U9Yp1EuWr+UhhTyYQjOP0=
51-
github.com/google/go-containerregistry v0.20.5/go.mod h1:Q14vdOOzug02bwnhMkZKD4e30pDaD9W65qzXpyzF49E=
50+
github.com/google/go-containerregistry v0.20.6 h1:cvWX87UxxLgaH76b4hIvya6Dzz9qHB31qAwjAohdSTU=
51+
github.com/google/go-containerregistry v0.20.6/go.mod h1:T0x8MuoAoKX/873bkeSfLD2FAkwCDf9/HZgsFJ02E2Y=
5252
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
5353
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
5454
github.com/goware/prefixer v0.0.0-20160118172347-395022866408 h1:Y9iQJfEqnN3/Nce9cOegemcy/9Ai5k3huT6E80F3zaw=
@@ -73,8 +73,8 @@ github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3N
7373
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
7474
github.com/moby/go-archive v0.1.0 h1:Kk/5rdW/g+H8NHdJW2gsXyZ7UnzvJNOy6VKJqueWdcQ=
7575
github.com/moby/go-archive v0.1.0/go.mod h1:G9B+YoujNohJmrIYFBpSd54GTUB4lt9S+xVQvsJyFuo=
76-
github.com/moby/moby v28.2.2+incompatible h1:sBNZudYVackyiyn2yoBUpAoRcDun9bnUCozAW6lAnPs=
77-
github.com/moby/moby v28.2.2+incompatible/go.mod h1:fDXVQ6+S340veQPv35CzDahGBmHsiclFwfEygB/TWMc=
76+
github.com/moby/moby v28.3.0+incompatible h1:BnZpCciB9dCnfNC+MerxqsHV4I6/gLiZIzzbRFJIhUY=
77+
github.com/moby/moby v28.3.0+incompatible/go.mod h1:fDXVQ6+S340veQPv35CzDahGBmHsiclFwfEygB/TWMc=
7878
github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk=
7979
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
8080
github.com/moby/sys/atomicwriter v0.1.0 h1:kw5D/EqkBwsBFi0ss9v1VG3wIkVhzGvLklJ+w3A14Sw=
@@ -145,13 +145,13 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
145145
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
146146
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
147147
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
148-
golang.org/x/net v0.40.0 h1:79Xs7wF06Gbdcg4kdCCIQArK11Z1hr5POQ6+fIYHNuY=
149-
golang.org/x/net v0.40.0/go.mod h1:y0hY0exeL2Pku80/zKK7tpntoX23cqL3Oa6njdgRtds=
148+
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
149+
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
150150
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
151151
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
152152
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
153-
golang.org/x/sync v0.14.0 h1:woo0S4Yywslg6hp4eUFjTVOyKt0RookbpAHG4c1HmhQ=
154-
golang.org/x/sync v0.14.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
153+
golang.org/x/sync v0.15.0 h1:KWH3jNZsfyT6xfAfKiz6MRNmd46ByHDYaZ7KSkCtdW8=
154+
golang.org/x/sync v0.15.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
155155
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
156156
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
157157
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -163,14 +163,14 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
163163
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
164164
golang.org/x/text v0.25.0 h1:qVyWApTSYLk/drJRO5mDlNYskwQznZmkpV2c8q9zls4=
165165
golang.org/x/text v0.25.0/go.mod h1:WEdwpYrmk1qmdHvhkSTNPm3app7v4rsT8F2UD6+VHIA=
166-
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
167-
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
166+
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
167+
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
168168
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
169169
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
170170
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
171171
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
172-
golang.org/x/tools v0.33.0 h1:4qz2S3zmRxbGIhDIAgjxvFutSvH5EfnsYrRBj0UI0bc=
173-
golang.org/x/tools v0.33.0/go.mod h1:CIJMaWEY88juyUfo7UbgPqbC8rU2OqfAV1h2Qp0oMYI=
172+
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
173+
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
174174
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
175175
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
176176
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

internal/infra/run.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"encoding/base64"
77
"encoding/json"
88
"fmt"
9-
"github.com/docker/docker/api/types/container"
109
"io"
1110
"log"
1211
"net/http"
@@ -17,6 +16,8 @@ import (
1716
"syscall"
1817
"time"
1918

19+
"github.com/docker/docker/api/types/container"
20+
2021
"github.com/dependabot/cli/internal/model"
2122
"github.com/dependabot/cli/internal/server"
2223
"github.com/docker/docker/api/types/image"
@@ -273,6 +274,8 @@ var packageManagerLookup = map[string]string{
273274
"swift": "swift",
274275
"devcontainers": "devcontainers",
275276
"uv": "uv",
277+
"vcpkg": "vcpkg",
278+
"rust_toolchain": "rust-toolchain",
276279
}
277280

278281
func setImageNames(params *RunParams) error {
@@ -423,11 +426,17 @@ func runContainers(ctx context.Context, params RunParams) (err error) {
423426
return err
424427
}
425428
} else {
429+
// First, update CA certificates as root
430+
if err := updater.RunCmd(ctx, "update-ca-certificates", root); err != nil {
431+
return err
432+
}
433+
434+
// Then run the dependabot commands as the dependabot user
426435
env := userEnv(prox.url, params.ApiUrl)
427436
if params.Flamegraph {
428437
env = append(env, "FLAMEGRAPH=1")
429438
}
430-
const cmd = "update-ca-certificates && bin/run fetch_files && bin/run update_files"
439+
const cmd = "bin/run fetch_files && bin/run update_files"
431440
if err := updater.RunCmd(ctx, cmd, dependabot, env...); err != nil {
432441
return err
433442
}

internal/server/api.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,22 @@ func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request) {
121121

122122
parts := strings.Split(r.URL.String(), "/")
123123
kind := parts[len(parts)-1]
124+
124125
actual, err := decodeWrapper(kind, data)
125126
if err != nil {
126127
a.pushError(err)
127128
}
128129

130+
a.outputRequestData(kind, actual)
131+
132+
if kind == "create_pull_request" && actual != nil {
133+
createPR := actual.Data.(model.CreatePullRequest)
134+
createPR.UpdatedDependencyFiles = replaceBinaryWithHash(createPR.UpdatedDependencyFiles)
135+
} else if kind == "update_pull_request" && actual != nil {
136+
updatePR := actual.Data.(model.UpdatePullRequest)
137+
updatePR.UpdatedDependencyFiles = replaceBinaryWithHash(updatePR.UpdatedDependencyFiles)
138+
}
139+
129140
if actual == nil {
130141
// indicates the kind (endpoint) isn't implemented in decodeWrapper, so return a 501
131142
w.WriteHeader(http.StatusNotImplemented)
@@ -134,7 +145,6 @@ func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request) {
134145

135146
if kind == "increment_metric" {
136147
// Let's just output the metrics data and stop
137-
a.outputRequestData(kind, actual)
138148
return
139149
}
140150

@@ -144,7 +154,6 @@ func (a *API) ServeHTTP(w http.ResponseWriter, r *http.Request) {
144154
}
145155

146156
if !a.hasExpectations {
147-
a.outputRequestData(kind, actual)
148157
return
149158
}
150159

@@ -178,12 +187,12 @@ func (a *API) assertExpectation(kind string, actual *model.UpdateWrapper) {
178187
}
179188
}
180189

181-
func (a *API) outputRequestData(kind string, actual *model.UpdateWrapper) {
190+
func (a *API) outputRequestData(kind string, data *model.UpdateWrapper) {
182191
if a.writer != nil {
183192
// output the data received to stdout
184193
if err := json.NewEncoder(a.writer).Encode(map[string]any{
185194
"type": kind,
186-
"data": actual.Data,
195+
"data": data.Data,
187196
}); err != nil {
188197
// Fail so the user knows stdout is not working
189198
log.Panicln("Failed to write to stdout: ", err)
@@ -220,15 +229,9 @@ func decodeWrapper(kind string, data []byte) (actual *model.UpdateWrapper, err e
220229
case "update_dependency_list":
221230
actual.Data, err = decode[model.UpdateDependencyList](data)
222231
case "create_pull_request":
223-
var createPR model.CreatePullRequest
224-
createPR, err = decode[model.CreatePullRequest](data)
225-
createPR.UpdatedDependencyFiles = replaceBinaryWithHash(createPR.UpdatedDependencyFiles)
226-
actual.Data = createPR
232+
actual.Data, err = decode[model.CreatePullRequest](data)
227233
case "update_pull_request":
228-
var updatePR model.UpdatePullRequest
229-
updatePR, err = decode[model.UpdatePullRequest](data)
230-
updatePR.UpdatedDependencyFiles = replaceBinaryWithHash(updatePR.UpdatedDependencyFiles)
231-
actual.Data = updatePR
234+
actual.Data, err = decode[model.UpdatePullRequest](data)
232235
case "close_pull_request":
233236
actual.Data, err = decode[model.ClosePullRequest](data)
234237
case "mark_as_processed":

internal/server/api_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
package server
22

33
import (
4+
"bytes"
5+
"crypto/sha256"
6+
"encoding/base64"
7+
"encoding/hex"
8+
"encoding/json"
9+
"fmt"
10+
"github.com/dependabot/cli/internal/model"
411
"net/http"
512
"net/http/httptest"
613
"testing"
@@ -28,3 +35,71 @@ func TestAPI_ServeHTTP(t *testing.T) {
2835
}
2936
})
3037
}
38+
39+
type Wrapper[T any] struct {
40+
Data T `json:"data"`
41+
}
42+
43+
func TestAPI_CreatePullRequest_ReplacesBinaryWithHash(t *testing.T) {
44+
var stdout bytes.Buffer
45+
46+
api := NewAPI(nil, &stdout)
47+
defer api.Stop()
48+
49+
content := base64.StdEncoding.EncodeToString([]byte("Hello, world!"))
50+
hash := sha256.Sum256([]byte(content))
51+
expectedHashedContent := hex.EncodeToString(hash[:])
52+
53+
// Construct the request body for create_pull_request
54+
createPullRequest := model.CreatePullRequest{
55+
UpdatedDependencyFiles: []model.DependencyFile{
56+
{
57+
Content: content,
58+
ContentEncoding: "base64",
59+
},
60+
},
61+
}
62+
var body bytes.Buffer
63+
if err := json.NewEncoder(&body).Encode(model.UpdateWrapper{Data: createPullRequest}); err != nil {
64+
t.Fatalf("failed to encode request body: %v", err)
65+
}
66+
67+
url := "http://127.0.0.1:" + // use the API's port
68+
fmt.Sprintf("%d/create_pull_request", api.Port())
69+
req, err := http.NewRequest("POST", url, &body)
70+
if err != nil {
71+
t.Fatalf("failed to create request: %v", err)
72+
}
73+
req.Header.Set("Content-Type", "application/json")
74+
75+
client := &http.Client{}
76+
resp, err := client.Do(req)
77+
if err != nil {
78+
t.Fatalf("failed to send request: %v", err)
79+
}
80+
defer resp.Body.Close()
81+
82+
if len(api.Errors) > 0 {
83+
t.Fatalf("expected no errors, got %d errors: %v", len(api.Errors), api.Errors)
84+
}
85+
86+
// The API should have replaced the content with a SHA hash in a.Actual.Output
87+
if len(api.Actual.Output) != 1 {
88+
t.Fatalf("expected 1 output, got %d", len(api.Actual.Output))
89+
}
90+
if api.Actual.Output[0].Type != "create_pull_request" {
91+
t.Fatalf("expected output type 'create_pull_request', got '%s'", api.Actual.Output[0].Type)
92+
}
93+
if api.Actual.Output[0].Expect.Data.(model.CreatePullRequest).UpdatedDependencyFiles[0].Content != expectedHashedContent {
94+
t.Errorf("expected content to be 'hello', got '%s'", api.Actual.Output[0].Expect.Data.(model.CreatePullRequest).UpdatedDependencyFiles[0].Content)
95+
}
96+
97+
// stdout should contain the original content so folks can create PRs
98+
var wrapper Wrapper[model.CreatePullRequest]
99+
if err := json.NewDecoder(&stdout).Decode(&wrapper); err != nil {
100+
t.Fatalf("failed to decode stdout: %v", err)
101+
}
102+
if wrapper.Data.UpdatedDependencyFiles[0].Content != content {
103+
t.Errorf("expected stdout to contain the original content, got '%s'", stdout.String())
104+
}
105+
}

0 commit comments

Comments
 (0)