From 7e312bbcc4340b30991e5faf45e74d5a63fed3f3 Mon Sep 17 00:00:00 2001 From: Michael Nikitochkin Date: Mon, 18 Nov 2024 14:55:38 +0100 Subject: [PATCH] Add support for Codeberg as a git resolver (#656) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Devonte Co-authored-by: Johannes Müller --- docs/shard.yml.adoc | 9 ++++++++- docs/shard.yml.schema.json | 10 ++++++++++ man/shard.yml.5 | 11 ++++++++++- spec/unit/git_resolver_spec.cr | 2 ++ src/resolvers/git.cr | 14 +++++++++++++- 5 files changed, 43 insertions(+), 3 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..12687725 100644 --- a/man/shard.yml.5 +++ b/man/shard.yml.5 @@ -524,7 +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. +dependency. Those can be \fIpath\fP, \fIgit\fP, \fIgithub\fP, \fIgitlab\fP, \fIbitbucket\fP, \fIcodeberg\fP. .sp \fBpath\fP .RS 4 @@ -582,6 +582,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). 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..955c8d4f 100644 --- a/src/resolvers/git.cr +++ b/src/resolvers/git.cr @@ -100,7 +100,16 @@ 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", + "www.codeberg.org", + "codeberg.org", + } def self.normalize_key_source(key : String, source : String) : {String, String} case key @@ -120,6 +129,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 +469,6 @@ module Shards register_resolver "github", GitResolver register_resolver "gitlab", GitResolver register_resolver "bitbucket", GitResolver + register_resolver "codeberg", GitResolver end end