Skip to content

Commit

Permalink
add meta-table when an issue is open, #14
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonLab committed Mar 9, 2018
1 parent 2ae7f55 commit 8720922
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
13 changes: 10 additions & 3 deletions lib/app_web/controllers/event_type_handlers.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
defmodule AppWeb.EventTypeHandlers do
use AppWeb, :controller
alias App.{Comment, Issue, Repo}
alias Ecto.Changeset
use AppWeb, :controller
alias AppWeb.MetaTable

@github_api Application.get_env(:app, :github_api)
@s3_api Application.get_env(:app, :s3_api)
Expand Down Expand Up @@ -44,21 +45,27 @@ defmodule AppWeb.EventTypeHandlers do
content = Poison.encode!(%{version_id => comment})
@s3_api.save_comment(issue.issue_id, content)

meta_table = MetaTable.get_meta_table(payload["issue"]["id"])
content = comment <> "\n" <> meta_table
repo_name = payload["repository"]["full_name"]
issue_number = payload["issue"]["number"]
token = @github_api.get_installation_token(payload["installation"]["id"])
@github_api.add_meta_table(repo_name, issue_number, content, token) |> IO.inspect

conn
|> put_status(200)
|> json(%{ok: "issue created"})
end

def issue_edited(conn, payload) do
issue_id = payload["issue"]["id"]

if Map.has_key?(payload["changes"], "title") do
issue = Repo.get_by!(Issue, issue_id: issue_id)
issue = Changeset.change issue, title: payload["issue"]["title"]
Repo.update!(issue)
end

if Map.has_key?(payload["changes"], "title") do
if Map.has_key?(payload["changes"], "body") do
comment = payload["issue"]["body"]
author = payload["sender"]["login"]
add_comment_version(issue_id, "#{issue_id}_1", comment, author)
Expand Down
5 changes: 5 additions & 0 deletions lib/app_web/controllers/github_api/http_client.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ defmodule AppWeb.GithubAPI.HTTPClient do
|> PP.parse!
end

def add_meta_table(repo_name, issue_id, content, token) do
"#{@github_root}/repos/#{repo_name}/issues/#{issue_id}"
|> HTTPoison.patch!(Poison.encode!(%{body: content}), header(token))
end

defp last_page?(headers) do
links_header = Map.get(Enum.into(headers, %{}), "Link")

Expand Down
3 changes: 3 additions & 0 deletions lib/app_web/controllers/github_api/in_memory.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ defmodule AppWeb.GithubAPI.InMemory do
[]
end

def add_meta_table(repo_name, issue_id, content, token) do
:ok
end
end
8 changes: 8 additions & 0 deletions lib/app_web/controllers/meta_table.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule AppWeb.MetaTable do

def get_meta_table(issue_id) do
# return the number of all edits
# get all the versions link to the issue
"Issue Edit Count: 9 | View History: link_to_the_app"
end
end

0 comments on commit 8720922

Please sign in to comment.