git-point
git-point copied to clipboard
Issues and Pull Requests count is wrong

The react repository definitely has more than 20 open and closed issues :). If the total number of issues and pull requests aren't easily retrievable from the API - we should probably just remove it.
Looks like this is because we're not taking into account the pagination. To deal with this, let's use the open_issues property from the repo API (https://api.github.com/repos/gitpoint/git-point). Note this will mean getting rid of closed issues because GitHub doesn't give us that count.
That api endpoint has open_issues_count and open_issues. In our case, the numbers are the same. Is there any case in which they would be different?
Looking at this we could fetch https://api.github.com/repos/gitpoint/git-point/issues?state=closed&per_page=21 and count them. If the count is 21, we can just show 20+. Otherwise, we can just show the count. (or any other number would do.
I don't think per_page has an upper limit, so technically we can use any number, but maybe we don't want to overfetch info.
@SammyIsra Actually here's a fun trick:
Make a request to https://api.github.com/repos/gitpoint/git-point/issues?state=closed&per_page=1&page=1. This shows us the most recently closed issue (or opened if state=open) from the repository, but that's not what we're interested in. We'll receive a Link header that looks something like this:
Link:<https://api.github.com/repositories/86202845/issues?state=closed&per_page=1&page=2>; rel="next", <https://api.github.com/repositories/86202845/issues?state=closed&per_page=1&page=102>; rel="last"
Note this part:
<https://api.github.com/repositories/86202845/issues?state=closed&per_page=1&page=102>; rel="last"
That's the link to the last page using the same per_page as we defined earlier. As we said only 1 item per page, we can parse the URL to determine that there are 102 closed issues in this repository. Sadly this endpoint combines issues and pull requests, though, so we're going to have to do the same thing with pull requests and subtract that number to get the total closed issues.
I think that's a little confusing (and I just woke up so I feel like I'm typing nonsense) so here's a quick TL;DR/summary:
- Make a request to
https://api.github.com/repos/gitpoint/git-point/issues?state=closed&per_page=1&page=1. - Determine total number of closed issues/pull requests from the last page returned in the
Linkheader. - Make another request to
https://api.github.com/repos/gitpoint/git-point/pulls?state=closed&per_page=1&page=1. - Determine total number of closed pull requests from the last page returned in the
Linkheader. closed_issues = closed_issues_and_prs - closed_prs
Repeat for open issues and PR's. This method takes 4 requests and should work well regardless of the total number of issues. Just tested on tensorflow/tensorflow and it works flawlessly, even with 6,500 closed issues and 4,180 closed PR's.
You really are a wizard @andrewda, 4 requests is a bit more than I would love but I think that's definitely worth it to get that information. This is great thank you so much.
For future GraphQL reference, here's how we'd get the first 3 issues on the repository screen, along with the total number of open/closed issues:
{
repository(owner: "gitpoint", name: "git-point") {
open: issues(first: 3, states: OPEN) {
totalCount
edges {
node {
title
}
}
}
closed: issues(first: 3, states: CLOSED) {
totalCount
edges {
node {
title
}
}
}
}
}
And for pull requests:
{
repository(owner: "gitpoint", name: "git-point") {
open: pullRequests(first: 3, states: OPEN) {
totalCount
edges {
node {
title
}
}
}
closed: pullRequests(first: 3, states: [CLOSED, MERGED]) {
totalCount
edges {
node {
title
}
}
}
}
}
Edit: and both of them combined looks like this:
{
repository(owner: "gitpoint", name: "git-point") {
openIssues: issues(first: 3, states: OPEN) {
totalCount
edges {
node {
title
}
}
}
closedIssues: issues(first: 3, states: CLOSED) {
totalCount
edges {
node {
title
}
}
}
openPullRequests: pullRequests(first: 3, states: OPEN) {
totalCount
edges {
node {
title
}
}
}
closedPullRequests: pullRequests(first: 3, states: [CLOSED, MERGED]) {
totalCount
edges {
node {
title
}
}
}
}
}
I love GraphQL now :joy: This simplifies things a ton.
Amazing, queries look so nice 😍
I think this (and #46) is a great place to start introducing GraphQL to the app
Awesome @housseindjirdeh! I have a graphql branch made where we can start working on this and merge it into master when we're satisfied :)
@andrewda yes that would be amazing <3
There are no issues/pull requests count on UI now. Shall we add them back?