Skip to content

Commit ac6bf84

Browse files
committed
Fix opam submit so it doesn't rely on a github dev-repo anymore
1 parent b79c4d8 commit ac6bf84

File tree

4 files changed

+26
-16
lines changed

4 files changed

+26
-16
lines changed

CHANGES.md

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949

5050
### Fixed
5151

52+
- Fix a bug in `opam submit` preventing non-github users to create the opam-repo PR
53+
via dune-release. (#???, @NathanReb)
5254
- Fix a bug where `opam submit` would try to parse the custom URI provided through
5355
`--distrib-uri` as a github repo URI instead of using the dev-repo (#358, @NathanReb)
5456
- Fix the priority of the `--distrib-uri` option in `dune-release opam pkg`.

bin/opam.ml

+22-12
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ let pp_opam_repo fmt opam_repo =
111111
let user, repo = opam_repo in
112112
Format.fprintf fmt "%s/%s" user repo
113113

114-
let open_pr ~dry_run ~changes ~remote_repo ~user ~distrib_user ~branch ~token
115-
~title ~opam_repo ~auto_open ~yes ~draft pkg =
114+
let open_pr ~dry_run ~changes ~remote_repo ~user ~branch ~token ~title
115+
~opam_repo ~auto_open ~yes ~draft pkg =
116116
Pkg.opam_descr pkg >>= fun (syn, _) ->
117117
Pkg.opam_homepage pkg >>= fun homepage ->
118118
Pkg.opam_doc pkg >>= fun doc ->
@@ -138,15 +138,14 @@ let open_pr ~dry_run ~changes ~remote_repo ~user ~distrib_user ~branch ~token
138138
l "Opening %a to merge branch %a of %a into %a" Text.Pp.maybe_draft
139139
(draft, "pull request") Text.Pp.commit branch Text.Pp.url remote_repo
140140
pp_opam_repo opam_repo);
141-
Github.open_pr ~token ~dry_run ~title ~distrib_user ~user ~branch ~opam_repo
142-
~draft msg pkg
141+
Github.open_pr ~token ~dry_run ~title ~user ~branch ~opam_repo ~draft msg pkg
143142
>>= function
144143
| `Already_exists ->
145144
App_log.blank_line ();
146145
App_log.success (fun l ->
147146
l "The existing pull request for %a has been automatically updated."
148147
Fmt.(styled `Bold string)
149-
(distrib_user ^ ":" ^ branch));
148+
(user ^ ":" ^ branch));
150149
Ok 0
151150
| `Url url -> (
152151
let msg () =
@@ -197,25 +196,36 @@ let submit ~token ~dry_run ~yes ~opam_repo ~user local_repo remote_repo pkgs
197196
list_map Pkg.name pkgs >>= fun names ->
198197
let title = strf "[new release] %a (%s)" (pp_list Fmt.string) names version in
199198
Pkg.publish_msg pkg >>= fun changes ->
200-
Pkg.infer_github_repo pkg >>= fun { owner; repo } ->
199+
let gh_repo = Rresult.R.to_option (Pkg.infer_github_repo pkg) in
200+
let changes =
201+
match gh_repo with
202+
| Some { owner; repo } -> Text.rewrite_github_refs ~user:owner ~repo changes
203+
| None -> changes
204+
in
201205
let user =
202206
match user with
203-
| Some user -> user (* from the .yaml configuration file *)
207+
| Some user -> Ok user (* from the .yaml configuration file *)
204208
| None -> (
205209
match Github.Parse.user_from_remote remote_repo with
206-
| Some user -> user (* trying to infer it from the remote repo URI *)
207-
| None -> owner)
210+
| Some user -> Ok user (* trying to infer it from the remote repo URI *)
211+
| None ->
212+
Rresult.R.error_msg
213+
"Could not determine on the behalf of which github user the \
214+
opam-repository PR should be created.\n\
215+
Try setting up your config using `dune-release config set user \
216+
<username>`\n\
217+
\ or passing one explicitly with `--user`.")
208218
in
209-
let changes = Text.rewrite_github_refs ~user:owner ~repo changes in
219+
user >>= fun user ->
210220
let msg = strf "%s\n\n%s\n" title changes in
211221
App_log.status (fun l ->
212222
l "Preparing %a to %a" Text.Pp.maybe_draft (draft, "pull request")
213223
pp_opam_repo opam_repo);
214224
Opam.prepare ~dry_run ~msg ~local_repo ~remote_repo ~opam_repo ~version ~tag
215225
names
216226
>>= fun branch ->
217-
open_pr ~dry_run ~changes ~remote_repo ~user ~distrib_user:owner ~branch
218-
~token ~title ~opam_repo ~auto_open ~yes ~draft pkg
227+
open_pr ~dry_run ~changes ~remote_repo ~user ~branch ~token ~title ~opam_repo
228+
~auto_open ~yes ~draft pkg
219229

220230
let field pkgs field =
221231
match field with

lib/github.ml

+2-3
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,12 @@ let curl_upload_archive ~token ~dry_run ~yes archive user repo release_id =
244244
>>= fun url ->
245245
Github_v3_api.Archive.Response.name response >>= fun name -> Ok (url, name))
246246

247-
let open_pr ~token ~dry_run ~title ~distrib_user ~user ~branch ~opam_repo ~draft
248-
body pkg =
247+
let open_pr ~token ~dry_run ~title ~user ~branch ~opam_repo ~draft body pkg =
249248
let curl_t =
250249
Github_v3_api.Pull_request.Request.open_ ~title ~user ~branch ~body
251250
~opam_repo ~draft
252251
in
253-
github_v3_auth ~dry_run ~user:distrib_user token >>= fun auth ->
252+
github_v3_auth ~dry_run ~user token >>= fun auth ->
254253
let curl_t = Github_v3_api.with_auth ~auth curl_t in
255254
let default_body = `Assoc [ ("html_url", `String D.pr_url) ] in
256255
run_with_auth ~dry_run ~default_body curl_t >>= fun json ->

lib/github.mli

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ val open_pr :
6060
token:Fpath.t ->
6161
dry_run:bool ->
6262
title:string ->
63-
distrib_user:string ->
6463
user:string ->
6564
branch:Vcs.commit_ish ->
6665
opam_repo:string * string ->

0 commit comments

Comments
 (0)