Skip to content

Commit

Permalink
Fix fine-grained handling of errors in backport management.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zimmi48 committed Jan 15, 2025
1 parent eb647e5 commit 4627265
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bot-components/GitHub_queries.ml
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ let get_project_field_values ~bot_info ~organization ~project ~field ~options =
let open GitHub_GraphQL.GetProjectFieldValues in
makeVariables ~organization ~project ~field ~options ()
|> serializeVariables |> variablesToJson
|> send_graphql_query ~bot_info ~query
|> send_graphql_query ~bot_info ~query ~ignore_errors:true
~parse:(Fn.compose parse unsafe_fromJson)
>>= function
| Ok result -> (
Expand Down
29 changes: 16 additions & 13 deletions bot-components/GraphQL_query.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ open Utils

type api = GitHub | GitLab of string

let send_graphql_query ~bot_info ?(extra_headers = []) ~api ~query ~parse
variables =
let send_graphql_query ~bot_info ?(extra_headers = []) ?(ignore_errors = false)
~api ~query ~parse variables =
let uri =
( match api with
| GitLab gitlab_domain ->
Expand Down Expand Up @@ -46,17 +46,20 @@ let send_graphql_query ~bot_info ?(extra_headers = []) ~api ~query ~parse
let json = Yojson.Basic.from_string body in
let open Yojson.Basic.Util in
let data = json |> member "data" |> parse in
match member "errors" json with
| `Null ->
Ok data
| errors ->
let errors =
to_list errors
|> List.map ~f:(fun error -> error |> member "message" |> to_string)
in
Error
( "Server responded to GraphQL request with errors: "
^ String.concat ~sep:", " errors )
if ignore_errors then Ok data
else
match member "errors" json with
| `Null ->
Ok data
| errors ->
let errors =
to_list errors
|> List.map ~f:(fun error ->
error |> member "message" |> to_string )
in
Error
( "Server responded to GraphQL request with errors: "
^ String.concat ~sep:", " errors )
with
| Failure err ->
Error (f "Exception: %s" err)
Expand Down
1 change: 1 addition & 0 deletions bot-components/GraphQL_query.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type api = GitHub | GitLab of string
val send_graphql_query :
bot_info:Bot_info.t
-> ?extra_headers:(string * string) list
-> ?ignore_errors:bool
-> api:api
-> query:string
-> parse:(Yojson.Basic.t -> 'a)
Expand Down

0 comments on commit 4627265

Please sign in to comment.