-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC][WIP] Step 1: Move The World #985
Conversation
If what I am saying is irrelevant, I will delete the comment to avoid clutter. Would this be the time to try and introduce a way to use the lib without any auth - as can be done if using the api directly? |
To be honest, I'd make it hard to use this library without auth. The API is very restrictive unless you're using an In the earlier samples, I had a snippet like this: var info = new ClientInfo
{
AppName = "my-cool-app",
Credentials = new Credentials("my-token"),
Server = "https://enterprise.my-work.com",
UseDefaultProxy = true
};
var http = HttpClientFactory.Create(info);
var client = new GitHubClient(http); We don't currently do this, but I'd like for the |
I know it might be a lot to ask, but is it possible to put the smallest, most relevant code sample at the end of the first comment? |
@M-Zuber okay, so this is what I've currently got: [IntegrationTest]
public void Setup()
{
// TODO: what other options may we get here
var info = new ClientInfo
{
Timeout = TimeSpan.MaxValue
};
// generate the client you need
var client = HttpClientFactory.Create(info);
// TODO: we probably need to guard here that we have enough
// information to use this client against the GitHub API
var github = new GitHubClient(new Connection(new ProductHeaderValue("The Future?"), client));
} The goal here (eventually?) is to find that right balance between convenience and customization |
There are some use cases though where no auth is needed and it just gets in the way. But its not a big enough problem to make a real issue out of it, so bowing out on this one |
Sure, and the rate-limiting will kick in quick enough for you to know. Anyway, nice feedback to know ✨ |
Looks simple enough
This would need to be done before creating any |
Not necessarily - this is what @haacked and I are probably going to debate about in here. On the one hand, most consumers won't care about the HTTP stack and just want to supply enough data to get going - a user-agent and perhaps some credentials. That scenario probably favours calling On the other, if you're wanting to tweak some settings (proxy, timeout, or even some extensibility that the |
From a first glance, it looks nice, |
Let's make sure this is the right direction, then I'll extract the tasks necessary to move on from there... |
I've identified some properties on |
And this is what composing a var info = new ClientInfo
{
UserAgent = "my-cool-app",
// TODO: make this of type `Credentials` - no need to keep the store here
Credentials = new InMemoryCredentialStore(new Credentials("my-token-here")),
Server = new Uri("https://github.my-cool-enterprise.com"),
Timeout = TimeSpan.MaxValue,
};
var github = new GitHubClient(info); |
👎 So my problem here is that certain properties (timeout for example) I would want to set per endpoint I use (long for uploading an attachment to a release, short default for the rest) rather than setting at a global connection level. From an API point of view I'd like to see an optional As for |
public GitHubClient(ProductHeaderValue productInformation) { }
public GitHubClient(ClientInfo info) { }
public GitHubClient(HttpClient httpClient) { } This is what the final situation will be once the dust settles, and there is no need for back compat ( If so, it looks good to me. |
I have given it some more thought, and I think this is a separate point. I woulds like to be able to do something like the following: var info = new ClientInfo
{
// Defaults for most endpoints.
};
var github = new GitHubClient(info);
var releaseInfo = new ClientInfo
{
// Any overrides specific for this endpoint.
}
github.Releases.SetOptions(releaseInfo); As I believe such a scenario is for more advanced users, it is okay to ask them to perform the extra steps. var info = new ClientInfo
{
// Defaults for most endpoints.
};
var releaseInfo = new ClientInfo
{
// Any overrides specific for this endpoint.
}
// How exactly this should work I am not sure
// Either separate methods for each endpoint, or some game with genrics/enum - just no magic strings
var github = new GitHubClient(info).SetOptionsForReleases(releaseInfo); |
As discussed in #963 we suspect the per-endpoint override (as in uploading release assets) will be ignored by the global setting - I'd love to get some more insight into that scenario as I know you've dealt with that in the past. Putting that aside (it's still To Be Resolved™) I'm not planning to remove that behaviour around setting per-request overrides (especially for uploading release assets) from Octokit, but we still lack a way for users to set a timeout globally. This change makes it easier to achieve this, but isn't the only reason why we're going down this path.
This feels not unlike #760 which was around giving more control to pagination options for endpoints that return collections. What other parts of a request might you looking to modify, generally speaking? |
I think this will be infinitely easier to do after this. I have some rough ideas in mind around extending the stack, but I may need to re-jig the |
Ok the scenario was this - we have automatic scripts to deploy releases to GitHub. The script does various things:
We hit a problem with attaching the compiled binary to the release. If the binary was too large the timeout would cause the upload to fail. So we upped the timeout to several hours. The problem is, I don't want any of the other tasks to wait several hours if they're going to timeout. For most of the communication a 60s timeout is fine, and only for the upload would I want to change that timeout. If you're interested, our release project that uses Octokit.net is https://github.com/Particular/GitHubReleaseNotes
Well, I was looking into handling the request caching to avoid using up the API limit when polling a repo for changes. So I was trying to support #352. So I guess what I'm really after here is a way to poll a repo for changes, and then have some automation happen because of that change. And suddenly as I write this I realized webhooks is a much better solution to this problem. Oh well. |
So you're not seeing an issue with the current 100s limit we have? That's something I want to confirm - or investigate further because I'm rather puzzled by it all. |
Not currently no. The upload was bigger but we've trimmed it down and it hasn't been a problem in a while. |
@shiftkey Clone this repo https://github.com/naveensrinivasan/octokit-test which has the testing-data folder. Then run this |
@naveensrinivasan @distantcam thanks for the details. I think there needs to be some changes here around how
We don't support that second scenario (perhaps that's the way out of this) and now I'm really grumpy at Will think on a solution some more. |
I think we could probably trim the constructors list down to... public GitHubClient(ProductHeaderValue productInformation) { }
public GitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore) { }
public GitHubClient(ProductHeaderValue productInformation, ICredentialStore credentialStore, Uri baseAddress) { }
public GitHubClient(ClientInfo info) { }
public GitHubClient(HttpClient httpClient) { } My thinking is that given that To make this even easier to use for one off scripts, we could even allow string overloads for product header where we would parse them and throw if they're invalid. For example: var client = new GitHubClient("Haackinator");
or
var client = new GitHubClient("Haackinator/3000"); Though I like that the |
Closing this out to take this off my plate. Don't worry, it'll return in some way, shape or colour. |
As @haacked mentioned, these are the
But I think that if we only keep these:
with throwing exceptions in case |
This is the first step in me rewriting the HTTP internals of Octokit as discussed in #984 - I've gone through this exercise a few times, and I think this is now simple enough to share with the world and actually commit to.
This is targeting a branch named
http-client-milestone
instead ofmaster
so I can work on this alongside other stuff - and others can get involved to hash out the API in parallel with Important Things™.What this PR is about:
GitHubClient
looks likeWhat this PR isn't about:
[Obsolete]
here to help with refactoring, however nothing is set in stoneTimeout
as an example property because it came up in Provided a httpclient timeout option #965 and I'd really like to avoid adding morector
parameters toGitHubClient
What I'm looking for feedback on:
ctors
forGitHubClient
we keep around, but see theMonkey
test for what the new setup looks like right nowChecklist:
ClientInfo
values are copied when creatingHttpClient
Timeout
ctor
overloads