Skip to content

Commit

Permalink
Add support for Codeberg as a git resolver (#656)
Browse files Browse the repository at this point in the history
Co-authored-by: Devonte <[email protected]>
Co-authored-by: Johannes Müller <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2024
1 parent 20aaeaf commit 7e312bb
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 3 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
11 changes: 10 additions & 1 deletion man/shard.yml.5

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
14 changes: 13 additions & 1 deletion src/resolvers/git.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -458,5 +469,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 7e312bb

Please sign in to comment.