Skip to content
Closed
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
10 changes: 7 additions & 3 deletions src/libfetchers/github.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <optional>
#include <nlohmann/json.hpp>
#include <fstream>
#include <regex>

namespace nix::fetchers {

Expand Down Expand Up @@ -332,9 +333,10 @@ struct GitLabInputScheme : GitArchiveInputScheme
Hash getRevFromRef(nix::ref<Store> store, const Input & input) const override
{
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
auto repo = std::regex_replace(getStrAttr(input.attrs, "repo"), std::regex("/"), "%2F");
// See rate limiting note below
auto url = fmt("https://%s/api/v4/projects/%s%%2F%s/repository/commits?ref_name=%s",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we constructing urls with string concatenation 🤦

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of repo has to go into the url encoded, one way or another.
Currently people are manually encoding it for example: build%2Fomnibus-mirror%2Falertmanager.

The goal of this change is to allow both build%2Fomnibus-mirror%2Falertmanager and build/omnibus-mirror/alertmanager

host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"), *input.getRef());
host, getStrAttr(input.attrs, "owner"), repo, *input.getRef());

Headers headers = makeHeadersWithAuthTokens(host);

Expand All @@ -355,8 +357,9 @@ struct GitLabInputScheme : GitArchiveInputScheme
// is 10 reqs/sec/ip-addr. See
// https://docs.gitlab.com/ee/user/gitlab_com/index.html#gitlabcom-specific-rate-limits
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
auto repo = std::regex_replace(getStrAttr(input.attrs, "repo"), std::regex("/"), "%2F");
auto url = fmt("https://%s/api/v4/projects/%s%%2F%s/repository/archive.tar.gz?sha=%s",
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"),
host, getStrAttr(input.attrs, "owner"), repo,
input.getRev()->to_string(Base16, false));

Headers headers = makeHeadersWithAuthTokens(host);
Expand All @@ -366,9 +369,10 @@ struct GitLabInputScheme : GitArchiveInputScheme
void clone(const Input & input, const Path & destDir) const override
{
auto host = maybeGetStrAttr(input.attrs, "host").value_or("gitlab.com");
auto repo = std::regex_replace(getStrAttr(input.attrs, "repo"), std::regex("/"), "%2F");
// FIXME: get username somewhere
Input::fromURL(fmt("git+https://%s/%s/%s.git",
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo")))
host, getStrAttr(input.attrs, "owner"), repo))
.applyOverrides(input.getRef(), input.getRev())
.clone(destDir);
}
Expand Down
9 changes: 9 additions & 0 deletions src/nix/flake.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,15 @@ Currently the `type` attribute can be one of the following:

* `gitlab:veloren%2Fdev/rfcs`

However, if using Attribute set representation slashes are permitted as the ``repo`` value:
```nix
inputs.nixpkgs = {
type = "gitlab";
owner = "gitlab-org";
repo = "release/tasks";
};
```

* `sourcehut`: Similar to `github`, is a more efficient way to fetch
SourceHut repositories. The following attributes are required:

Expand Down