Skip to content

Commit ecb1bfe

Browse files
Fallback for GraphQL query without message for older asgard versions(#192)
Older versions of the Asgard API server do not support the `message` field. This PR adds a fallback for those cases.
1 parent f1d60fe commit ecb1bfe

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

command/report/constants.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,6 @@ Notes:
2929
Documentation:
3030
https://deepsource.io/docs/cli#report
3131
`
32-
reportGraphqlQuery = "mutation($input: CreateArtifactInput!) {\r\n createArtifact(input: $input) {\r\n ok\r\n message\r\n error\r\n }\r\n}"
32+
reportGraphqlQuery = "mutation($input: CreateArtifactInput!) {\r\n createArtifact(input: $input) {\r\n ok\r\n message\r\n error\r\n }\r\n}"
33+
reportGraphqlQueryOld = "mutation($input: CreateArtifactInput!) {\r\n createArtifact(input: $input) {\r\n ok\r\n error\r\n }\r\n}"
3334
)

command/report/report.go

+21-6
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,6 @@ func (opts *ReportOptions) Run() int {
196196
reportMeta := make(map[string]string)
197197
reportMeta["workDir"] = currentDir
198198

199-
query := ReportQuery{Query: reportGraphqlQuery}
200-
201199
queryInput := ReportQueryInput{
202200
AccessToken: dsnAccessToken,
203201
CommitOID: headCommitOID,
@@ -209,6 +207,7 @@ func (opts *ReportOptions) Run() int {
209207
Metadata: reportMeta,
210208
}
211209

210+
query := ReportQuery{Query: reportGraphqlQuery}
212211
query.Variables.Input = queryInput
213212

214213
// Marshal request body
@@ -226,11 +225,27 @@ func (opts *ReportOptions) Run() int {
226225
opts.SkipCertificateVerification,
227226
)
228227
if err != nil {
229-
fmt.Fprintln(os.Stderr, "DeepSource | Error | Reporting failed |", err)
230-
sentry.CaptureException(err)
231-
return 1
228+
// Make Query without message field.
229+
query := ReportQuery{Query: reportGraphqlQueryOld}
230+
query.Variables.Input = queryInput
231+
queryBodyBytes, err := json.Marshal(query)
232+
if err != nil {
233+
fmt.Fprintln(os.Stderr, "DeepSource | Error | Unable to marshal query body")
234+
sentry.CaptureException(err)
235+
return 1
236+
}
237+
queryResponseBody, err = makeQuery(
238+
dsnProtocol+"://"+dsnHost+"/graphql/cli/",
239+
queryBodyBytes,
240+
"application/json",
241+
opts.SkipCertificateVerification,
242+
)
243+
if err != nil {
244+
fmt.Fprintln(os.Stderr, "DeepSource | Error | Reporting failed |", err)
245+
sentry.CaptureException(err)
246+
return 1
247+
}
232248
}
233-
234249
// Parse query's response body
235250
queryResponse := QueryResponse{}
236251
err = json.Unmarshal(queryResponseBody, &queryResponse)

0 commit comments

Comments
 (0)