8000 Add support for Codeberg as a git resolver by miry · Pull Request #656 · crystal-lang/shards · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add support for Codeberg as a git resolver #656

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

Merged
merged 4 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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: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"})
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