dwyl / github-backup

:octocat: :back: 🆙 Backup your GitHub Issues so you can still work when (they/you are) offline.
https://github-backup.herokuapp.com
GNU General Public License v2.0
32 stars 3 forks source link

How to get closed issues? #29

Open SimonLab opened 6 years ago

SimonLab commented 6 years ago

From: https://developer.github.com/v3/issues/#list-issues-for-a-repository To get the list of issues of a repository we need to send a GET request to /repos/:owner/:repo/issues

By adding the state query parameter to the query we can choose to get all the issues and not just the open ones: image

We already have the get_issues function: https://github.com/dwyl/github-backup/blob/295ee9e7cf0bc9b5f6d88e89601c5341a2351956/lib/app_web/controllers/github_api/http_client.ex#L47-L52 We need to update this function to add the state query parameter with the value all

ref:

SimonLab commented 6 years ago

because of: image

We also need to filter the list of issues that we get from Github to only keep the "real" issues and exclude the PRs

nelsonic commented 6 years ago

@SimonLab PRs deserve their own "Story". they are classified as "issues" by GitHub. and we do want to track the comments in them eventually ...

SimonLab commented 6 years ago

@nelsonic see #30 I'll update the issue with more details (github api documentation link and any other info that might be useful to help us implement this issue)

SimonLab commented 6 years ago

The Github API use pagination when returning result, see: https://developer.github.com/v3/guides/traversing-with-pagination/

image

The information of the pagination will be in the header of the reply.

SimonLab commented 6 years ago

I copy/paste taking inspiration from Tentacat regex to get the Link header data intead of spliting/filter the headers: https://github.com/edgurgel/tentacat/blob/d4c9ba7d8dbc4825d43e5f4a5b0ce7698688b0e4/lib/tentacat.ex#L141-L151

SimonLab commented 6 years ago

Trying to get the total number of pages with the following function:

  defp last_page(headers) do
    for {"Link", link_header} <- headers, links <- String.split(link_header, ",") do
      Regex.named_captures(~r/<(?<link>.*)>;\s*rel=\"(?<rel>.*)\"/, links)
      |> case do
        %{"link" => link, "rel" => "last"} -> link
        _ -> nil
      end
    end
    |> Enum.filter(&(not is_nil(&1)))
    |>List.first
    |>Regex.named_captures(~r/page=(?<page>.*)/)
  end

My last Regex is not correct and can't manage to match for example the following url:

image

SimonLab commented 6 years ago

The arguments of the Regex.named_captures are on the wrong order! :face_with_head_bandage: regex first then string

SimonLab commented 6 years ago

The function to get all the closed issues has been added to the project with #33 however as we don't save yet the data in Postgres and S3 and we don't have the UI linked to the data this issue can't be directly tested yet. At the end this issue is more a technicall issue. I'll remove the awaiting-review label and add a please-test later one when a way to see that closed issue have been collected (app UI or AWS S3 UI) has been added

Cleop commented 6 years ago

Putting blocker label on this issue as it can't be progressed until it is testable with the UI and postgres data.

SimonLab commented 6 years ago

This can now be tested. I can access one of my closed issues: image However it's not very clear that the issue is closed from the UI, we might need to find a way to indicate this.

Cleop commented 6 years ago

@SimonLab - perhaps we should open a new issue to create UI resemble something like the github UI: image Is that what you were thinking?