Skip to content

Commit

Permalink
Fallback for GraphQL query without message for older asgard versions(#…
Browse files Browse the repository at this point in the history
…192)

Older versions of the Asgard API server do not support the `message` field. This PR adds a fallback for those cases.
  • Loading branch information
tushar-deepsource authored Nov 21, 2022
1 parent f1d60fe commit ecb1bfe
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
3 changes: 2 additions & 1 deletion command/report/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ Notes:
Documentation:
https://deepsource.io/docs/cli#report
`
reportGraphqlQuery = "mutation($input: CreateArtifactInput!) {\r\n createArtifact(input: $input) {\r\n ok\r\n message\r\n error\r\n }\r\n}"
reportGraphqlQuery = "mutation($input: CreateArtifactInput!) {\r\n createArtifact(input: $input) {\r\n ok\r\n message\r\n error\r\n }\r\n}"
reportGraphqlQueryOld = "mutation($input: CreateArtifactInput!) {\r\n createArtifact(input: $input) {\r\n ok\r\n error\r\n }\r\n}"
)
27 changes: 21 additions & 6 deletions command/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,6 @@ func (opts *ReportOptions) Run() int {
reportMeta := make(map[string]string)
reportMeta["workDir"] = currentDir

query := ReportQuery{Query: reportGraphqlQuery}

queryInput := ReportQueryInput{
AccessToken: dsnAccessToken,
CommitOID: headCommitOID,
Expand All @@ -209,6 +207,7 @@ func (opts *ReportOptions) Run() int {
Metadata: reportMeta,
}

query := ReportQuery{Query: reportGraphqlQuery}
query.Variables.Input = queryInput

// Marshal request body
Expand All @@ -226,11 +225,27 @@ func (opts *ReportOptions) Run() int {
opts.SkipCertificateVerification,
)
if err != nil {
fmt.Fprintln(os.Stderr, "DeepSource | Error | Reporting failed |", err)
sentry.CaptureException(err)
return 1
// Make Query without message field.
query := ReportQuery{Query: reportGraphqlQueryOld}
query.Variables.Input = queryInput
queryBodyBytes, err := json.Marshal(query)
if err != nil {
fmt.Fprintln(os.Stderr, "DeepSource | Error | Unable to marshal query body")
sentry.CaptureException(err)
return 1
}
queryResponseBody, err = makeQuery(
dsnProtocol+"://"+dsnHost+"/graphql/cli/",
queryBodyBytes,
"application/json",
opts.SkipCertificateVerification,
)
if err != nil {
fmt.Fprintln(os.Stderr, "DeepSource | Error | Reporting failed |", err)
sentry.CaptureException(err)
return 1
}
}

// Parse query's response body
queryResponse := QueryResponse{}
err = json.Unmarshal(queryResponseBody, &queryResponse)
Expand Down

0 comments on commit ecb1bfe

Please sign in to comment.