mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-26 07:46:21 +02:00
Fix gitlab-fetcher to obtain tags and branches
Until now, the `gitlab`-fetcher determined the source's rev by checking the latest commit of the given `ref` using the `/repository/branches`-API. This breaks however when trying to fetch a gitlab-repo by its tag: ``` $ nix repl nix-repl> builtins.fetchTree gitlab:Ma27/nvim.nix/0.2.0 error: --- Error ------------------------------------------------------------------------------------- nix unable to download 'https://gitlab.com/api/v4/projects/Ma27%2Fnvim.nix/repository/branches/0.2.0': HTTP error 404 ('') ``` When using the `/commits?ref_name`-endpoint[1] you can pass any kind of valid ref to the `gitlab`-fetcher. Please note that this fetches the only first 20 commits on a ref, unfortunately there's currently no endpoint which only retrieves the latest commit of any kind of `ref`. [1] https://docs.gitlab.com/ee/api/commits.html#list-repository-commits
This commit is contained in:
parent
9223603908
commit
cf9f33995b
1 changed files with 2 additions and 2 deletions
|
@ -229,13 +229,13 @@ struct GitLabInputScheme : GitArchiveInputScheme
|
||||||
Hash getRevFromRef(nix::ref<Store> store, const Input & input) const override
|
Hash getRevFromRef(nix::ref<Store> store, const Input & input) const override
|
||||||
{
|
{
|
||||||
auto host_url = maybeGetStrAttr(input.attrs, "url").value_or("gitlab.com");
|
auto host_url = maybeGetStrAttr(input.attrs, "url").value_or("gitlab.com");
|
||||||
auto url = fmt("https://%s/api/v4/projects/%s%%2F%s/repository/branches/%s",
|
auto url = fmt("https://%s/api/v4/projects/%s%%2F%s/repository/commits?ref_name=%s",
|
||||||
host_url, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"), *input.getRef());
|
host_url, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"), *input.getRef());
|
||||||
auto json = nlohmann::json::parse(
|
auto json = nlohmann::json::parse(
|
||||||
readFile(
|
readFile(
|
||||||
store->toRealPath(
|
store->toRealPath(
|
||||||
downloadFile(store, url, "source", false).storePath)));
|
downloadFile(store, url, "source", false).storePath)));
|
||||||
auto rev = Hash(std::string(json["commit"]["id"]), htSHA1);
|
auto rev = Hash(std::string(json[0]["id"]), htSHA1);
|
||||||
debug("HEAD revision for '%s' is %s", url, rev.gitRev());
|
debug("HEAD revision for '%s' is %s", url, rev.gitRev());
|
||||||
return rev;
|
return rev;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue