I'd like to be able to show the Issues list of private repositories so I can show customers what I'm working on without sharing the repo itself, or for that matter have to log into GitHub.
Of course, there are projects like Octokit for exactly this, but it does a bazillion things. I would prefer a really targeted client that uses Refit. I'm always wanting to practice more with Refit and build up a portfolio of examples.
Key parts of this repo:
- CLI project. This is what I'm testing interactively with on the console.
- ApiClient project. This is where the main work is, with the Refit interface and the client object itself that you would use. I'm using Postman to execute fetches against the GitHub API itself, and using responses to build my
Response
Models. - Razor Class Library project. I'm not sure how far this will get. I originally envisioned creating a component or two that I can use within another Blazor app. This may turn out to be more ambitious than I want to get into right now, and I may just be happy with the API client alone.
For now, I care mainly about Issues and Issue Events. I did add support for getting Comments, but I'm not sure actually need it. There is also support for querying repository info, but that was merely so I'd have access to the open_issues_count, a metric I'm intersted in.
The client methods themselves follow this pattern:
- A
Get
method returns a single page of results always. You must manually increment anyPage
argument and call your method again to get additional pages of results. - There are two kinds of
GetAll
methods. These are used to enumerate all pages of a collection automatically via EnumAllPagesAsync. Because some collections may be quite large and inefficent to query completely, some of theGetAll
methods have ashouldContinue
delegate you can use to cause theGetAll
to stop after some condition is met. For example, one query I want to do is to get 10 most recently closed issues. I can do that like this:
var events = (await client.GetAllEventsAsync("MyRepo",
(qry, results) => results.Count(ev => ev.event_name.Equals("closed")) < 10))
.Where(ev => ev.event_name.Equals("closed"))
.Take(10);
This says, "get events in 'MyRepo' while the total number of 'closed' events is less than 10. Then, from the all the returns events, give me the first 10 of those that are 'closed'.
- Task<IReadOnlyCollection<Repository>> GetMyRepositoriesAsync ([ RepositoryQuery? query ])
- Task<IReadOnlyCollection<Repository>> GetAllMyRepositoriesAsync ([ RepositoryQuery? query ])
- Task<IReadOnlyCollection<Issue>> GetIssuesAsync (string repositoryName, [ IssuesQuery? query ])
- Task<IReadOnlyCollection<Issue>> GetAllIssuesAsync (string repositoryName, [ IssuesQuery? query ])
- Task<IReadOnlyCollection<Issue>> GetAllIssuesAsync (string repositoryName, Func<IssuesQuery, IEnumerable, bool> shouldContine, [ IssuesQuery? query ])
- Task<IReadOnlyCollection<IssueEvent>> GetEventsAsync (string repositoryName, [ BaseQuery? query ])
- Task<IReadOnlyCollection<IssueEvent>> GetAllEventsAsync (string repositoryName, Func<BaseQuery, IEnumerable, bool> shouldContinue, [ BaseQuery? query ])
- Task<IReadOnlyCollection<Comment>> GetCommentsAsync (string repositoryName, [ CommentQuery? query ])
- Task<IReadOnlyCollection<Comment>> GetAllCommentsAsync (string repositoryName, [ CommentQuery? query ])
- Task<IReadOnlyCollection<Comment>> GetAllCommentsAsync (string repositoryName, Func<CommentQuery, IEnumerable, bool> shouldContine, [ CommentQuery? query ])