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

Endpoint to return number edits svg badge #77

Open SimonLab opened 6 years ago

SimonLab commented 6 years ago

linked to #14 (Meta table)

Each time a new version (edit) of the issue description or a comment of the issue is saved, the meta table will display the new incremented number of edits. We can update directly the issue description of the new number via the Github API, however a nicer solution is to use a svg served by the "github-backup" server. So in a similar way to https://github.com/dwyl/hits-elixir we need to:

format of the hit-elixir svg:

<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" width="80" height="20">

<rect width="30" height="20" fill="#555"/>
<rect x="30" width="50" height="20" fill="#4c1"/>

<rect rx="3" width="80" height="20" fill="transparent"/>
    <g fill="#fff" text-anchor="middle"
    font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
        <text x="15" y="14">hits</text>
        <text x="54" y="14">696</text>
    </g>
</svg>
SimonLab commented 6 years ago

We can render svg with Phoenix by adding the correct Mime type and using the send_resp function instead of using the html template and the render function

  def show(conn, _payload) do
    svg = File.read!("./assets/static/images/edit_count.svg") |> IO.inspect
    conn
    |> put_resp_content_type("image/svg+xml")
    |> send_resp(200, svg)
  end
SimonLab commented 6 years ago

From my understanding of #14 edits count = sum of edits on comments and issue description So we can get the issue from the Postgres with all the comments and versions linked to the issue, then return the number of versions - the sum of comments (the first version of the comments is not an edit but a creation)

SimonLab commented 6 years ago

image

with the meta table (the svg is not display because try to access localhost): image