diff options
Diffstat (limited to 'src/libstore/fetchers/github.cc')
-rw-r--r-- | src/libstore/fetchers/github.cc | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/src/libstore/fetchers/github.cc b/src/libstore/fetchers/github.cc index c75680649..13ac4e2f1 100644 --- a/src/libstore/fetchers/github.cc +++ b/src/libstore/fetchers/github.cc @@ -19,6 +19,8 @@ struct GitHubInput : Input std::optional<std::string> ref; std::optional<Hash> rev; + std::string type() const override { return "github"; } + bool operator ==(const Input & other) const override { auto other2 = dynamic_cast<const GitHubInput *>(&other); @@ -48,6 +50,18 @@ struct GitHubInput : Input return s; } + Attrs toAttrsInternal() const override + { + Attrs attrs; + attrs.emplace("owner", owner); + attrs.emplace("repo", repo); + if (ref) + attrs.emplace("ref", *ref); + if (rev) + attrs.emplace("rev", rev->gitRev()); + return attrs; + } + void clone(const Path & destDir) const override { std::shared_ptr<const Input> input = inputFromURL(fmt("git+ssh://git@github.com/%s/%s.git", owner, repo)); @@ -138,7 +152,6 @@ struct GitHubInputScheme : InputScheme auto path = tokenizeString<std::vector<std::string>>(url.path, "/"); auto input = std::make_unique<GitHubInput>(); - input->type = "github"; if (path.size() == 2) { } else if (path.size() == 3) { @@ -176,6 +189,18 @@ struct GitHubInputScheme : InputScheme return input; } + + std::unique_ptr<Input> inputFromAttrs(const Input::Attrs & attrs) override + { + if (maybeGetStrAttr(attrs, "type") != "github") return {}; + auto input = std::make_unique<GitHubInput>(); + input->owner = getStrAttr(attrs, "owner"); + input->repo = getStrAttr(attrs, "repo"); + input->ref = maybeGetStrAttr(attrs, "ref"); + if (auto rev = maybeGetStrAttr(attrs, "rev")) + input->rev = Hash(*rev, htSHA1); + return input; + } }; static auto r1 = OnStartup([] { registerInputScheme(std::make_unique<GitHubInputScheme>()); }); |