Migrate octokit.NET to the new generated SDK #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
GitHub.Octokit.Client 利用 restful API 来构建 SDK。调用 SDK 的方式也遵循 restful 风格。例如,对于以下api
使用以下代码可以获取一个 Request 对象:
参数以及路径都是完全对应的,只有大小写的区别。
接下来,对该 Requset 调用 GetAsync 方法即可发起请求。方法返回 nullable 的结果对象,直接处理对象即可。
认证
虽然 Github OpenAPI 规范中对于所有 API 都要求提供 token,但并非所有 API 都需要。对于公开提供的内容,可以省略 Token。
通过以下方式配置的依赖注入,githubClient 对象可以在无需 token 的情况下访问公开资源:
如果需要使用 token,可以通过以下方式配置依赖注入:
Token 的传入方式既可以使用环境变量,也可以通过启动参数。详细查看
LoongsonNeuq.Common/Auth
下的代码。依赖的配置方法全部遵循 fluent create 设计模式,扩展方法可以在
LoongsonNeuq.Common/DependencyInjectionExtensions.cs
中添加