aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniel Fullmer <danielrf12@gmail.com>2022-05-05 10:46:48 -0700
committerDaniel Fullmer <danielrf12@gmail.com>2022-05-06 13:13:11 -0700
commit7a3d5b2ff0e39ae0d7b393f454671a08da56776b (patch)
tree03a20b3ca406295926af48bd27dc43d444ca7b56 /src
parentf4102de84ba4dd3b845a3e34fabab5400e066ad0 (diff)
Use correct URL for GitHub Enterprise
For GitHub Enterprise, the API is accessed through a slightly different URL. See [1], where it says: > Use http(s)://[hostname]/api/v3 to access the API for GitHub > Enterprise Server. Also tested working on a GHE instance. [1] https://docs.github.com/en/enterprise-server@3.3/rest/guides/getting-started-with-the-rest-api
Diffstat (limited to 'src')
-rw-r--r--src/libfetchers/github.cc10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc
index 1bdf2759f..50b3150ee 100644
--- a/src/libfetchers/github.cc
+++ b/src/libfetchers/github.cc
@@ -243,7 +243,10 @@ struct GitHubInputScheme : GitArchiveInputScheme
Hash getRevFromRef(nix::ref<Store> store, const Input & input) const override
{
auto host = maybeGetStrAttr(input.attrs, "host").value_or("github.com");
- auto url = fmt("https://api.%s/repos/%s/%s/commits/%s", // FIXME: check
+ auto url = fmt(
+ host == "github.com"
+ ? "https://api.%s/repos/%s/%s/commits/%s"
+ : "https://%s/api/v3/repos/%s/%s/commits/%s",
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"), *input.getRef());
Headers headers = makeHeadersWithAuthTokens(host);
@@ -262,7 +265,10 @@ struct GitHubInputScheme : GitArchiveInputScheme
// FIXME: use regular /archive URLs instead? api.github.com
// might have stricter rate limits.
auto host = maybeGetStrAttr(input.attrs, "host").value_or("github.com");
- auto url = fmt("https://api.%s/repos/%s/%s/tarball/%s", // FIXME: check if this is correct for self hosted instances
+ auto url = fmt(
+ host == "github.com"
+ ? "https://api.%s/repos/%s/%s/commits/%s"
+ : "https://%s/api/v3/repos/%s/%s/commits/%s",
host, getStrAttr(input.attrs, "owner"), getStrAttr(input.attrs, "repo"),
input.getRev()->to_string(Base16, false));