Skip to content

Commit

Permalink
feat: Add support for Codeberg as a git resolver
Browse files Browse the repository at this point in the history
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
```
  • Loading branch information
miry committed Nov 7, 2024
1 parent 9a5e5b6 commit f613812
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
9 changes: 8 additions & 1 deletion docs/shard.yml.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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).
Expand Down
10 changes: 10 additions & 0 deletions docs/shard.yml.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 12 additions & 2 deletions man/shard.yml.5
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -815,4 +825,4 @@ targets:
Written by Julien Portalier and the Crystal project.
.SH "SEE ALSO"
.sp
\fBshards\fP(1)
\fBshards\fP(1)
2 changes: 2 additions & 0 deletions spec/unit/git_resolver_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]/Repo/Path.git?Shallow=true")[1].should eq "https://User:[email protected]/repo/path.git?Shallow=true"
GitResolver.normalize_key_source("git", "HTTPS://User:[email protected]/Repo/Path.Git?Shallow=true")[1].should eq "https://User:[email protected]/repo/path.git?Shallow=true"
GitResolver.normalize_key_source("git", "HTTPS://User:[email protected]/Repo/Path?Shallow=true")[1].should eq "https://User:[email protected]/repo/path.git?Shallow=true"
GitResolver.normalize_key_source("git", "HTTPS://User:[email protected]/Repo/Path?Shallow=true")[1].should eq "https://User:[email protected]/repo/path.git?Shallow=true"
GitResolver.normalize_key_source("git", "HTTPS://User:[email protected]/Repo/Path.Git?Shallow=true")[1].should eq "https://User:[email protected]/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"})
Expand Down
13 changes: 12 additions & 1 deletion src/resolvers/git.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -458,5 +468,6 @@ module Shards
register_resolver "github", GitResolver
register_resolver "gitlab", GitResolver
register_resolver "bitbucket", GitResolver
register_resolver "codeberg", GitResolver
end
end

0 comments on commit f613812

Please sign in to comment.