From f613812bf31806554fa26775a69ffb6f6c44b8e6 Mon Sep 17 00:00:00 2001 From: Michael Nikitochkin Date: Thu, 7 Nov 2024 08:49:59 +0100 Subject: [PATCH 1/3] feat: Add support for Codeberg as a git resolver Enhances the `shard.yml` configuration to support Codeberg, a popular Git hosting service in Germany, as a dependency source. This allows developers to specify Codeberg repositories directly in their configuration. Example usage: ```yaml dependencies: foo: codeberg: repo/foo ``` --- docs/shard.yml.adoc | 9 ++++++++- docs/shard.yml.schema.json | 10 ++++++++++ man/shard.yml.5 | 14 ++++++++++++-- spec/unit/git_resolver_spec.cr | 2 ++ src/resolvers/git.cr | 13 ++++++++++++- 5 files changed, 44 insertions(+), 4 deletions(-) diff --git a/docs/shard.yml.adoc b/docs/shard.yml.adoc index 1cf4092a..3229e28a 100644 --- a/docs/shard.yml.adoc +++ b/docs/shard.yml.adoc @@ -273,7 +273,7 @@ A path to the source file to compile (string). == DEPENDENCY ATTRIBUTES Each dependency needs at least one attribute that defines the resolver for this -dependency. Those can be _path_, _git_, _github_, _gitlab_, _bitbucket_. +dependency. Those can be _path_, _git_, _github_, _gitlab_, _bitbucket_, _codeberg_. *path*:: A local path (string). @@ -320,6 +320,13 @@ Extends the _git_ resolver, and acts exactly like it. + *Example:* _bitbucket: tom/library_ +*codeberg*:: +Codeberg repository URL as _user/repo_ (string). ++ +Extends the _git_ resolver, and acts exactly like it. ++ +*Example:* _codeberg: tom/library_ + *hg*:: A Mercurial repository URL (string). diff --git a/docs/shard.yml.schema.json b/docs/shard.yml.schema.json index 60e13fc7..6e94700a 100644 --- a/docs/shard.yml.schema.json +++ b/docs/shard.yml.schema.json @@ -57,6 +57,11 @@ "title": "Bitbucket URL", "description": "Bitbucket repository URL as user/repo" }, + "codeberg": { + "type": "string", + "title": "Codeberg URL", + "description": "Codeberg repository URL as user/repo" + }, "git": { "type": "string", "title": "git URL", @@ -130,6 +135,11 @@ "title": "Bitbucket URL", "description": "Bitbucket repository URL as user/repo" }, + "codeberg": { + "type": "string", + "title": "Codeberg URL", + "description": "Codeberg repository URL as user/repo" + }, "git": { "type": "string", "title": "git URL", diff --git a/man/shard.yml.5 b/man/shard.yml.5 index a72a627b..bcc4660c 100644 --- a/man/shard.yml.5 +++ b/man/shard.yml.5 @@ -524,7 +524,8 @@ A path to the source file to compile (string). .SH "DEPENDENCY ATTRIBUTES" .sp Each dependency needs at least one attribute that defines the resolver for this -dependency. Those can be \fIpath\fP, \fIgit\fP, \fIgithub\fP, \fIgitlab\fP, \fIbitbucket\fP. +dependency. Those can be \fIpath\fP, \fIgit\fP, \fIgithub\fP, \fIgitlab\fP, \fIbitbucket\fP, +\fIcodeberg\fP. .sp \fBpath\fP .RS 4 @@ -582,6 +583,15 @@ Extends the \fIgit\fP resolver, and acts exactly like it. \fBExample:\fP \fIbitbucket: tom/library\fP .RE .sp +\fBcodeberg\fP +.RS 4 +Codeberg repository URL as \fIuser/repo\fP (string). +.sp +Extends the \fIgit\fP resolver, and acts exactly like it. +.sp +\fBExample:\fP \fIcodeberg: tom/library\fP +.RE +.sp \fBhg\fP .RS 4 A Mercurial repository URL (string). @@ -815,4 +825,4 @@ targets: Written by Julien Portalier and the Crystal project. .SH "SEE ALSO" .sp -\fBshards\fP(1) \ No newline at end of file +\fBshards\fP(1) diff --git a/spec/unit/git_resolver_spec.cr b/spec/unit/git_resolver_spec.cr index 102a647c..fbaa04c8 100644 --- a/spec/unit/git_resolver_spec.cr +++ b/spec/unit/git_resolver_spec.cr @@ -39,12 +39,14 @@ module Shards GitResolver.normalize_key_source("gitlab", "repo/path").should eq({"git", "https://gitlab.com/repo/path.git"}) GitResolver.normalize_key_source("gitlab", "rEpo/pAth").should eq({"git", "https://gitlab.com/repo/path.git"}) GitResolver.normalize_key_source("gitlab", "REPO/PATH").should eq({"git", "https://gitlab.com/repo/path.git"}) + GitResolver.normalize_key_source("codeberg", "REPO/PATH").should eq({"git", "https://codeberg.org/repo/path.git"}) # normalise full git paths GitResolver.normalize_key_source("git", "HTTPS://User:Pass@Github.com/Repo/Path.git?Shallow=true")[1].should eq "https://User:Pass@github.com/repo/path.git?Shallow=true" GitResolver.normalize_key_source("git", "HTTPS://User:Pass@Bitbucket.com/Repo/Path.Git?Shallow=true")[1].should eq "https://User:Pass@bitbucket.com/repo/path.git?Shallow=true" GitResolver.normalize_key_source("git", "HTTPS://User:Pass@Gitlab.com/Repo/Path?Shallow=true")[1].should eq "https://User:Pass@gitlab.com/repo/path.git?Shallow=true" GitResolver.normalize_key_source("git", "HTTPS://User:Pass@www.Github.com/Repo/Path?Shallow=true")[1].should eq "https://User:Pass@github.com/repo/path.git?Shallow=true" + GitResolver.normalize_key_source("git", "HTTPS://User:Pass@codeBerg.org/Repo/Path.Git?Shallow=true")[1].should eq "https://User:Pass@codeberg.org/repo/path.git?Shallow=true" # don't normalise other domains GitResolver.normalize_key_source("git", "HTTPs://mygitserver.com/Repo.git").should eq({"git", "HTTPs://mygitserver.com/Repo.git"}) diff --git a/src/resolvers/git.cr b/src/resolvers/git.cr index c1f7d652..20632686 100644 --- a/src/resolvers/git.cr +++ b/src/resolvers/git.cr @@ -100,7 +100,15 @@ module Shards "git" end - private KNOWN_PROVIDERS = {"www.github.com", "github.com", "www.bitbucket.com", "bitbucket.com", "www.gitlab.com", "gitlab.com"} + private KNOWN_PROVIDERS = { + "www.github.com", + "github.com", + "www.bitbucket.com", + "bitbucket.com", + "www.gitlab.com", + "gitlab.com", + "codeberg.org", + } def self.normalize_key_source(key : String, source : String) : {String, String} case key @@ -120,6 +128,8 @@ module Shards end when "github", "bitbucket", "gitlab" {"git", "https://#{key}.com/#{source.downcase}.git"} + when "codeberg" + {"git", "https://#{key}.org/#{source.downcase}.git"} else raise "Unknown resolver #{key}" end @@ -458,5 +468,6 @@ module Shards register_resolver "github", GitResolver register_resolver "gitlab", GitResolver register_resolver "bitbucket", GitResolver + register_resolver "codeberg", GitResolver end end From aac040757c2b543658812336bfb31179619c51c6 Mon Sep 17 00:00:00 2001 From: Michael Nikitochkin Date: Thu, 7 Nov 2024 13:45:40 +0100 Subject: [PATCH 2/3] Add www.codeberg.org to the list Co-authored-by: Devonte --- src/resolvers/git.cr | 1 + 1 file changed, 1 insertion(+) diff --git a/src/resolvers/git.cr b/src/resolvers/git.cr index 20632686..955c8d4f 100644 --- a/src/resolvers/git.cr +++ b/src/resolvers/git.cr @@ -107,6 +107,7 @@ module Shards "bitbucket.com", "www.gitlab.com", "gitlab.com", + "www.codeberg.org", "codeberg.org", } From e33947bab3cc367a91613b65d6cb557c791ca896 Mon Sep 17 00:00:00 2001 From: Michael Nikitochkin Date: Thu, 7 Nov 2024 16:11:01 +0100 Subject: [PATCH 3/3] Update manpage --- man/shard.yml.5 | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/man/shard.yml.5 b/man/shard.yml.5 index bcc4660c..12687725 100644 --- a/man/shard.yml.5 +++ b/man/shard.yml.5 @@ -524,8 +524,7 @@ A path to the source file to compile (string). .SH "DEPENDENCY ATTRIBUTES" .sp Each dependency needs at least one attribute that defines the resolver for this -dependency. Those can be \fIpath\fP, \fIgit\fP, \fIgithub\fP, \fIgitlab\fP, \fIbitbucket\fP, -\fIcodeberg\fP. +dependency. Those can be \fIpath\fP, \fIgit\fP, \fIgithub\fP, \fIgitlab\fP, \fIbitbucket\fP, \fIcodeberg\fP. .sp \fBpath\fP .RS 4 @@ -825,4 +824,4 @@ targets: Written by Julien Portalier and the Crystal project. .SH "SEE ALSO" .sp -\fBshards\fP(1) +\fBshards\fP(1) \ No newline at end of file