Skip to content

Commit

Permalink
Add codeberg Source Kind (ocaml#10904)
Browse files Browse the repository at this point in the history
* Add `codeberg` Source Kind

Add a new kind to the `source` stanza for Codeberg projects.

Signed-off-by: Nicholas Rodrigues Lordello <[email protected]>

* Test Codeberg Not Supported <3.17

Adds additional steps to the Codeberg cram test to check that specifying
a Dune-lang prior to 3.17 and using 'codeberg' with the 'source' stanza
results in an error.

Signed-off-by: Nicholas Rodrigues Lordello <[email protected]>

---------

Signed-off-by: Nicholas Rodrigues Lordello <[email protected]>
  • Loading branch information
nlordell authored and anmonteiro committed Nov 17, 2024
1 parent 241738f commit 4b982c2
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 8 deletions.
2 changes: 2 additions & 0 deletions doc/changes/10904.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add `codeberg` as an option for defining project sources in dune-project
files. For example, `(source (codeberg user/repo))`. (#10904, @nlordell)
2 changes: 2 additions & 0 deletions doc/reference/dune-project/generate_opam_files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ defined in the project:
| ``(gitlab organization/project/repo)`` *(New in 3.17)*
* - `Sourcehut <https://sr.ht>`_
- ``(sourcehut user/repo)``
* - `Codeberg <https://codeberg.org>`_
- ``(codeberg user/repo)``

Examples:

Expand Down
25 changes: 17 additions & 8 deletions src/dune_lang/source_kind.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ module Host = struct
| Bitbucket of user_repo
| Gitlab of gitlab_repo
| Sourcehut of user_repo
| Codeberg of user_repo

let kind_string = function
| Github _ -> "github"
| Bitbucket _ -> "bitbucket"
| Gitlab _ -> "gitlab"
| Sourcehut _ -> "sourcehut"
| Codeberg _ -> "codeberg"
;;

let dyn_of_user_repo kind { user; repo } =
Expand All @@ -45,7 +47,7 @@ module Host = struct
let kind = Dyn.string (kind_string repo) in
match repo with
| Gitlab gitlab_repo -> dyn_of_gitlab_repo kind gitlab_repo
| Github user_repo | Bitbucket user_repo | Sourcehut user_repo ->
| Github user_repo | Bitbucket user_repo | Sourcehut user_repo | Codeberg user_repo ->
dyn_of_user_repo kind user_repo
;;

Expand All @@ -54,25 +56,29 @@ module Host = struct
| Bitbucket _ -> "bitbucket.org"
| Gitlab _ -> "gitlab.com"
| Sourcehut _ -> "sr.ht"
| Codeberg _ -> "codeberg.org"
;;

let base_uri repo =
let host = host_of_repo repo in
match repo with
| Gitlab (Org_repo { org; proj; repo }) -> sprintf "%s/%s/%s/%s" host org proj repo
| Sourcehut { user; repo } -> sprintf "%s/~%s/%s" host user repo
| Gitlab (User_repo { user; repo }) | Github { user; repo } | Bitbucket { user; repo }
-> sprintf "%s/%s/%s" host user repo
| Github { user; repo }
| Bitbucket { user; repo }
| Gitlab (User_repo { user; repo })
| Codeberg { user; repo } -> sprintf "%s/%s/%s" host user repo
;;

let add_https s = "https://" ^ s
let homepage t = add_https (base_uri t)

let bug_reports = function
| Gitlab _ as repo -> homepage repo ^ "/-/issues"
| Github _ as repo -> homepage repo ^ "/issues"
| Bitbucket _ as repo -> homepage repo ^ "/issues"
| Gitlab _ as repo -> homepage repo ^ "/-/issues"
| Sourcehut _ as repo -> add_https ("todo." ^ base_uri repo)
| Codeberg _ as repo -> homepage repo ^ "/issues"
;;

let enum k =
Expand All @@ -82,6 +88,7 @@ module Host = struct
[ Github stub_user_repo
; Bitbucket stub_user_repo
; Sourcehut stub_user_repo
; Codeberg stub_user_repo
; Gitlab (User_repo stub_user_repo)
; Gitlab stub_org_repo
]
Expand All @@ -92,6 +99,7 @@ module Host = struct
| Github _, [ user; repo ] -> Github { user; repo }, None
| Bitbucket _, [ user; repo ] -> Bitbucket { user; repo }, Some ((2, 8), name)
| Sourcehut _, [ user; repo ] -> Sourcehut { user; repo }, Some ((3, 1), name)
| Codeberg _, [ user; repo ] -> Codeberg { user; repo }, Some ((3, 17), name)
| Gitlab _, [ user; repo ] ->
Gitlab (User_repo { user; repo }), Some ((2, 8), name)
| Gitlab _, [ org; proj; repo ] ->
Expand Down Expand Up @@ -128,10 +136,11 @@ module Host = struct
let path =
match repo with
| Gitlab (Org_repo { org; proj; repo }) -> sprintf "%s/%s/%s" org proj repo
| Gitlab (User_repo { user; repo }) -> sprintf "%s/%s" user repo
| Sourcehut { user; repo } -> sprintf "%s/%s" user repo
| Github { user; repo } -> sprintf "%s/%s" user repo
| Bitbucket { user; repo } -> sprintf "%s/%s" user repo
| Github { user; repo }
| Bitbucket { user; repo }
| Gitlab (User_repo { user; repo })
| Sourcehut { user; repo }
| Codeberg { user; repo } -> sprintf "%s/%s" user repo
in
let open Encoder in
let forge = kind_string repo in
Expand Down
1 change: 1 addition & 0 deletions src/dune_lang/source_kind.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Host : sig
| Bitbucket of user_repo
| Gitlab of gitlab_repo
| Sourcehut of user_repo
| Codeberg of user_repo

val homepage : t -> string
val bug_reports : t -> string
Expand Down
29 changes: 29 additions & 0 deletions test/blackbox-tests/test-cases/codeberg.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Test the codeberg source type in project files.

$ cat >dune-project <<EOF
> (lang dune 3.17)
> (name foo)
> (generate_opam_files true)
> (source (codeberg john/doe))
> (package
> (allow_empty)
> (name foo))
> EOF

$ dune build
$ cat foo.opam | grep -i codeberg.org
homepage: "https://codeberg.org/john/doe"
bug-reports: "https://codeberg.org/john/doe/issues"
dev-repo: "git+https://codeberg.org/john/doe.git"

The 'codeberg' source kind is only supported in Dune lang >=3.17; check that
Dune errors as expected with earlier Dune lang versions.

$ sed -i -e '1s|.*|(lang dune 3.16)|' dune-project
$ dune build
File "dune-project", line 4, characters 8-27:
4 | (source (codeberg john/doe))
^^^^^^^^^^^^^^^^^^^
Error: Codeberg is only available since version 3.17 of the dune language.
Please update your dune-project file to have (lang dune 3.17).
[1]
20 changes: 20 additions & 0 deletions test/blackbox-tests/test-cases/source-stanza.t
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ Test a generated 'gitlab' organization repo
bug-reports: "https://gitlab.com/organization/project/repo/-/issues"
dev-repo: "git+https://gitlab.com/organization/project/repo.git"

Test a generated 'codeberg' user repo

$ sed -i -e '4s|.*|(source (codeberg user/repo))|' dune-project
$ dune build
$ cat foo.opam | grep -i codeberg.org
homepage: "https://codeberg.org/user/repo"
bug-reports: "https://codeberg.org/user/repo/issues"
dev-repo: "git+https://codeberg.org/user/repo.git"

Test that the creation of a source stanza of the form 'org/project/repo' is
disallowed by any forge type other than gitlab and that associated error
messages are provided
Expand Down Expand Up @@ -92,6 +101,17 @@ Test sourcehut forge.
Hint: The provided form 'org/proj/repo' is specific to Gitlab projects
[1]

Test codeberg forge.

$ sed -i -e '4s|.*|(source (codeberg org/proj/repo))|' dune-project
$ dune build
File "dune-project", line 4, characters 18-31:
4 | (source (codeberg org/proj/repo))
^^^^^^^^^^^^^
Error: Codeberg repository must be of form user/repo
Hint: The provided form 'org/proj/repo' is specific to Gitlab projects
[1]

So far we have been using '(lang dune 3.17)' which supports gitlab organization
style syntax, we will bump the version down and check to make sure an error is
thrown telling us we need a more recent version of dune to use orginaziton
Expand Down

0 comments on commit 4b982c2

Please sign in to comment.