Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add codeberg Source Kind #10904

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 17 additions & 0 deletions test/blackbox-tests/test-cases/codeberg.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
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"
rgrinberg marked this conversation as resolved.
Show resolved Hide resolved
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
Loading