Skip to content

Commit

Permalink
Don't call get_fork_owner if already set
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Petiot committed Jan 19, 2024
1 parent 68b1662 commit 68a8b46
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
29 changes: 15 additions & 14 deletions bin/opam.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

open Bos_setup
open Dune_release
open Stdext.Result.Let_syntax

let get_pkg_dir pkg =
Pkg.build_dir pkg >>= fun bdir ->
Expand Down Expand Up @@ -166,19 +167,16 @@ let open_pr ~dry_run ~changes ~remote_repo ~fork_owner ~branch ~token ~title

(** Get the value from the [user] config, if it is unset try to parse it from
the [remote_repo]. *)
let get_fork_owner ~fork_owner ~remote_repo =
match fork_owner with
| Some o -> Ok o
| None -> (
match Github_repo.from_uri remote_repo with
| Some repo -> Ok repo.owner
| None ->
R.error_msgf
"The owner of the opam-repository fork on Github is needed but \
couldn't be parsed from the remote fork.\n\
Please configure your Github user name with `dune-release config \
set user <owner>` or providing it via the\n\
\ `--user` option.")
let get_fork_owner ~remote_repo =
match Github_repo.from_uri remote_repo with
| Some repo -> Ok repo.owner
| None ->
R.error_msgf
"The owner of the opam-repository fork on Github is needed but \
couldn't be parsed from the remote fork.\n\
Please configure your Github user name with `dune-release config set \
user <owner>` or providing it via the\n\
\ `--user` option."

let submit ~token ~dry_run ~yes ~opam_repo ~pkgs_to_submit
{
Expand Down Expand Up @@ -224,7 +222,10 @@ let submit ~token ~dry_run ~yes ~opam_repo ~pkgs_to_submit
| Some { owner; repo } -> Text.rewrite_github_refs ~user:owner ~repo changes
| None -> changes
in
get_fork_owner ~fork_owner ~remote_repo >>= fun fork_owner ->
let* fork_owner =
Bos_setup.R.of_option fork_owner ~none:(fun () ->
get_fork_owner ~remote_repo)
in
let msg = strf "%s\n\n%s\n" title changes in
App_log.status (fun l ->
l "Preparing %a to %a" Text.Pp.maybe_draft (draft, "pull request")
Expand Down
5 changes: 5 additions & 0 deletions lib/stdext.ml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@ module Result = struct
let iter ~f l =
List.fold_left (fun acc x -> acc >>= fun () -> f x) (Ok ()) l
end

module Let_syntax = struct
let ( let+ ) = Bos_setup.R.( >>| )
let ( let* ) = Bos_setup.R.( >>= )
end
end

module String = struct
Expand Down
10 changes: 10 additions & 0 deletions lib/stdext.mli
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,14 @@ module Result : sig
(** [iter ~f l] applies [f] on each element of list [l] until an error
occurs. *)
end

module Let_syntax : sig
val ( let+ ) :
('a, 'b) Result.result -> ('a -> 'c) -> ('c, 'b) Result.result

val ( let* ) :
('a, 'b) Result.result ->
('a -> ('c, 'b) Result.result) ->
('c, 'b) Result.result
end
end

0 comments on commit 68a8b46

Please sign in to comment.