diff --git a/README.md b/README.md index c38c511..8010e5f 100644 --- a/README.md +++ b/README.md @@ -28,3 +28,4 @@ We will welcome all help with open arms! - [Michael Fellinger](https://github.com/manveru) - [Peter Hoeg](https://github.com/peterhoeg) +- [Vidhvath J](https://github.com/vidhvath28) diff --git a/crystal2nix b/crystal2nix new file mode 100644 index 0000000..2246d06 Binary files /dev/null and b/crystal2nix differ diff --git a/shard.lock b/shard.lock index 4e55dee..c378083 100644 --- a/shard.lock +++ b/shard.lock @@ -8,3 +8,6 @@ shards: git: https://github.com/hugopl/version_from_shard.git version: 1.2.5 + carbon_smtp_adapter: + hg: https://hg.sr.ht/~peterhoeg/dummy + version: 0.1.1+hg.commit.4048cd7e156f3d4317e10ebd4e742020c8049310 \ No newline at end of file diff --git a/shard.yml b/shard.yml index 1c6257b..db1c628 100644 --- a/shard.yml +++ b/shard.yml @@ -22,3 +22,8 @@ development_dependencies: spectator: gitlab: arctic-fox/spectator version: ~> 0.10.5 + +dependencies: + carbon_smtp_adapter: + hg: https://hg.sr.ht/~peterhoeg/dummy + version: ~> 0.1.1 \ No newline at end of file diff --git a/shards.nix b/shards.nix index 728aefb..88f502d 100644 --- a/shards.nix +++ b/shards.nix @@ -9,4 +9,13 @@ rev = "v1.2.5"; sha256 = "0xizj0q4rd541rwjbx04cjifc2gfx4l5v6q2y7gmd0ndjmkgb8ik"; }; + carbon_smtp_adapter = { + hg = "https://hg.sr.ht/~peterhoeg/dummy"; + rev = "v0.1.1"; + sha256 = "0kdb0k1xzl4yysfmlif7xmr2mnb3y5f3knqr8dy08f3sq9n31x4z"; + + } } + + + \ No newline at end of file diff --git a/spec/repo_spec.cr b/spec/repo_spec.cr index d1e6e8c..c889e98 100644 --- a/spec/repo_spec.cr +++ b/spec/repo_spec.cr @@ -1,6 +1,6 @@ require "./spec_helper" -Spectator.describe Repo do +Spectator.describe Crystal2Nix::Repo do context "commit" do let(:with_commit) { <<-EOF @@ -9,8 +9,12 @@ Spectator.describe Repo do EOF } + let(:shard) { + Crystal2Nix::Shard.from_yaml(with_commit) + } + let(:repo) { - Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_commit)) + Crystal2Nix::Repo.new(shard.url, shard.rev, shard.type) } it "should have the commit as revision" do @@ -26,12 +30,56 @@ Spectator.describe Repo do EOF } + let(:shard) { + Crystal2Nix::Shard.from_yaml(with_version) + } + let(:repo) { - Crystal2Nix::Repo.new(Crystal2Nix::Shard.from_yaml(with_version)) + Crystal2Nix::Repo.new(shard.url, shard.rev, shard.type) } it "should prefix version references with a v" do expect(repo.rev).to eq("v0.1.1") end end + + context "http url" do + let(:with_http_url) { + <<-EOF + http: https://example.com/archive.tar.gz + EOF + } + + let(:shard) { + Crystal2Nix::Shard.from_yaml(with_http_url) + } + + let(:repo) { + Crystal2Nix::Repo.new(shard.url, shard.rev, shard.type) + } + + it "should have the correct url" do + expect(repo.url).to eq("https://example.com/archive.tar.gz") + end + end + + context "git without revision" do + let(:without_revision) { + <<-EOF + git: https://github.com/example/repo.git + EOF + } + + let(:shard) { + Crystal2Nix::Shard.from_yaml(without_revision) + } + + let(:repo) { + Crystal2Nix::Repo.new(shard.url, shard.rev, shard.type) + } + + it "should have the correct url" do + expect(repo.url).to eq("https://github.com/example/repo.git") + end + end end diff --git a/src/repo.cr b/src/repo.cr index e41a466..17e0ce2 100644 --- a/src/repo.cr +++ b/src/repo.cr @@ -1,19 +1,13 @@ module Crystal2Nix class Repo - @url : URI - getter rev : String + property url : String + property rev : String? + property type : Symbol - def initialize(entry : Shard) - @url = URI.parse(entry.git).normalize - @rev = if entry.version =~ /^(?.+)\+git\.commit\.(?.+)$/ - $~["rev"] - else - "v#{entry.version}" - end - end - - def url : String - @url.to_s + def initialize(url : String, rev : String? = nil, type : Symbol = :git) + @url = url + @rev = rev + @type = type end end end diff --git a/src/runner.cr b/src/runner.cr index 467c918..c98c4ee 100644 --- a/src/runner.cr +++ b/src/runner.cr @@ -1,4 +1,4 @@ require "./crystal2nix" require "./cli" -Crystal2Nix::Cli.new.run +Crystal2Nix::Cli.new.run \ No newline at end of file diff --git a/src/worker.cr b/src/worker.cr index caec6cf..3842f04 100644 --- a/src/worker.cr +++ b/src/worker.cr @@ -15,6 +15,9 @@ module Crystal2Nix exit 1 end sha256 = "" + case + when repo.url.ends_with?(".git") + args = [ "--no-deepClone", "--url", repo.url, @@ -24,6 +27,22 @@ module Crystal2Nix x.error.each_line { |e| puts e } sha256 = PrefetchJSON.from_json(x.output).sha256 end + when repo.url.starts_with?("hg://") || repo.url.ends_with?(".hg") + args = [ + "--url", repo.url, + "--rev", repo.rev, + ] + Process.run("nix-prefetch-hg", args: args) do |x| + x.error.each_line { |e| puts e } + sha256 = PrefetchJSON.from_json(x.output).sha256 + end + when repo.url.ends_with?(".fossil") + STDERR.puts "Fossil repositories are not supported." + next + else + STDERR.puts "Unknown repository type for #{repo.url}" + next + end file.puts %( #{key} = {) file.puts %( url = "#{repo.url}";) @@ -35,4 +54,4 @@ module Crystal2Nix end end end -end +end \ No newline at end of file