Display issues list

This commit is contained in:
kagel 2016-08-29 01:16:08 +03:00
parent 4a5196987b
commit 7f6cb564a0
11 changed files with 194 additions and 36 deletions

View File

@ -16,11 +16,6 @@ html, body {
}
.profile-settings {
padding-top: 20px;
.form-group {
padding-top: 20px;
}
button {
margin-top: 20px;
@ -42,3 +37,8 @@ html, body {
padding-left: 10px;
padding-right: 10px;
}
h3 {
padding-top: 40px;
padding-bottom: 20px;
}

View File

@ -78,11 +78,12 @@ WHERE repo_id = :repo_id;
-- :name create-issue! :! :n
-- :doc creates issue
INSERT INTO issues (repo_id, issue_id, issue_number, address)
INSERT INTO issues (repo_id, issue_id, issue_number, title, address)
SELECT
:repo_id,
:issue_id,
:issue_number,
:title,
:address
WHERE NOT exists(SELECT 1
FROM issues
@ -93,16 +94,17 @@ INSERT INTO issues (repo_id, issue_id, issue_number, address)
UPDATE issues
SET commit_id = :commit_id
WHERE issue_id = :issue_id
RETURNING repo_id, issue_id, issue_number, address, commit_id;
RETURNING repo_id, issue_id, issue_number, title, address, commit_id;
-- Pull Requests -------------------------------------------------------------------
-- :name create-pull-request! :! :n
-- :doc creates pull request
INSERT INTO pull_requests (repo_id, pr_id, user_id, parents)
INSERT INTO pull_requests (repo_id, pr_id, pr_number, user_id, parents)
SELECT
:repo_id,
:pr_id,
:pr_number,
:user_id,
:parents
WHERE NOT exists(SELECT 1
@ -114,14 +116,19 @@ INSERT INTO pull_requests (repo_id, pr_id, user_id, parents)
-- :name bounties-list :? :*
-- :doc lists fixed issues
SELECT
i.address AS issue_address,
i.repo_id AS repo_id,
p.pr_id AS pr_id,
p.user_id AS user_id,
u.address AS payout_address,
u.login AS user_login,
u.name AS user_name,
r.repo AS repo_name
i.address AS issue_address,
i.issue_id AS issue_id,
i.issue_number AS issue_number,
i.title AS issue_title,
i.repo_id AS repo_id,
p.pr_id AS pr_id,
p.user_id AS user_id,
p.pr_number AS pr_number,
u.address AS payout_address,
u.login AS user_login,
u.name AS user_name,
r.login AS owner_name,
r.repo AS repo_name
FROM issues i
INNER JOIN pull_requests p
ON p.parents LIKE '%' || i.commit_id || '%'
@ -131,3 +138,19 @@ FROM issues i
INNER JOIN repositories r
ON r.repo_id = i.repo_id
WHERE r.user_id = :owner_id;
-- :name issues-list :? :*
-- :doc lists all issues
SELECT
i.address AS issue_address,
i.issue_id AS issue_id,
i.issue_number AS issue_number,
i.title AS issue_title,
i.repo_id AS repo_id,
r.login AS owner_name,
r.repo AS repo_name
FROM issues i
INNER JOIN repositories r
ON r.repo_id = i.repo_id
WHERE r.user_id = :owner_id
AND i.commit_id IS NULL;

View File

@ -0,0 +1,15 @@
(ns commiteth.db.bounties
(:require [commiteth.db.core :refer [*db*] :as db]
[clojure.java.jdbc :as jdbc]
[clojure.set :refer [rename-keys]]))
(defn list-fixed-issues
[owner-id]
(jdbc/with-db-connection [con-db *db*]
(db/bounties-list con-db {:owner_id owner-id})))
(defn list-not-fixed-issues
[owner-id]
(jdbc/with-db-connection [con-db *db*]
(db/issues-list con-db {:owner_id owner-id})))

View File

@ -5,11 +5,12 @@
(defn create
"Creates issue"
[repo-id issue-id issue-number address]
[repo-id issue-id issue-number issue-title address]
(jdbc/with-db-connection [con-db *db*]
(db/create-issue! con-db {:repo_id repo-id
:issue_id issue-id
:issue_number issue-number
:title issue-title
:address address})))
(defn close

View File

@ -91,9 +91,9 @@
(repos/delete-hook user repo hook-id (auth-params token)))
(defn post-comment
[user repo issue-id]
[user repo issue-id issue-address]
(issues/create-comment user repo issue-id
"a comment with an image link to the web service" (self-auth-params)))
(str "a comment with an image link to the web service. Issue address is " issue-address) (self-auth-params)))
(defn get-commit
[user repo commit-id]

View File

@ -7,6 +7,7 @@
[buddy.auth :refer [authenticated?]]
[commiteth.db.users :as users]
[commiteth.db.repositories :as repositories]
[commiteth.db.bounties :as bounties]
[commiteth.github.core :as github]))
(defn access-error [_ _]
@ -36,7 +37,7 @@
:auth-rules authenticated?
:body-params [user-id :- String, address :- String]
:summary "Update user address"
(let [result (users/update-user-address user-id address)]
(let [result (users/update-user-address (Integer/parseInt user-id) address)]
(if (= 1 result)
(ok)
(internal-server-error))))
@ -52,6 +53,14 @@
:auth-rules authenticated?
:current-user user
(ok (repositories/get-enabled (:id user))))
(GET "/bounties" []
:auth-rules authenticated?
:current-user user
(ok (bounties/list-fixed-issues (:id user))))
(GET "/issues" []
:auth-rules authenticated?
:current-user user
(ok (bounties/list-not-fixed-issues (:id user))))
(POST "/repository/toggle" {:keys [params]}
:auth-rules authenticated?
:current-user user

View File

@ -36,15 +36,17 @@
login :login
name :name} :user
id :id
pr-number :number
merge-commit-sha :merge_commit_sha} :pull_request}]
(future
(->>
(github/get-commit owner repo-name merge-commit-sha)
(get-commit-parents)
(hash-map :parents)
(merge {:repo_id repo-id
:pr_id id
:user_id user-id})
(merge {:repo_id repo-id
:pr_id id
:pr_number pr-number
:user_id user-id})
(pull-requests/create))
(users/create-user user-id login name nil nil)))
@ -66,15 +68,17 @@
[issue]
(when-let [action (:action issue)]
(when (labeled-as-bounty? action issue)
(github/post-comment
(get-in issue [:repository :owner :login])
(get-in issue [:repository :name])
(get-in issue [:issue :number]))
(let [repo-id (get-in issue [:repository :id])
issue (:issue issue)
issue-id (:id issue)
issue-number (:number issue)]
(issues/create repo-id issue-id issue-number (gen-address))))
(let [repository (:repository issue)
{repo-id :id
{owner-login :login} :owner
repo-name :name} repository
issue (:issue issue)
{issue-id :id
issue-number :number
issue-title :title} issue
issue-address (gen-address)]
(github/post-comment owner-login repo-name issue-number issue-address)
(issues/create repo-id issue-id issue-number issue-title issue-address)))
(when (and
(= "closed" action)
(has-bounty-label? issue))

View File

@ -5,4 +5,6 @@
:user nil
:user-profile nil
:repos []
:enabled-repos {}})
:enabled-repos {}
:bounties []
:issues []})

View File

@ -32,7 +32,35 @@
{:db (assoc db :user user)
:dispatch-n [[:load-user-profile]
[:load-user-repos]
[:load-enabled-repos]]}))
[:load-enabled-repos]
[:load-bounties]
[:load-issues]]}))
(reg-event-fx
:load-bounties
(fn [{:keys [db]} [_]]
{:db db
:http {:method GET
:url "/api/bounties"
:on-success #(dispatch [:set-bounties %])}}))
(reg-event-db
:set-bounties
(fn [db [_ bounties]]
(assoc db :bounties bounties)))
(reg-event-fx
:load-issues
(fn [{:keys [db]} [_]]
{:db db
:http {:method GET
:url "/api/issues"
:on-success #(dispatch [:set-issues %])}}))
(reg-event-db
:set-issues
(fn [db [_ issues]]
(assoc db :issues issues)))
(reg-event-fx
:load-user-profile
@ -89,4 +117,4 @@
:http {:method POST
:url "/api/user/address"
:on-success #(println %)
:params {:user_id user-id :address address}}}))
:params {:user-id user-id :address address}}}))

View File

@ -1,7 +1,73 @@
(ns commiteth.home.page
(:require [re-frame.core :as rf]))
(def github-url "https://github.com/")
(defn issue-url
[user repo issue-number]
(str github-url user "/" repo "/issues/" issue-number))
(defn pull-url
[user repo pull-number]
(str github-url user "/" repo "/pull/" pull-number))
(defn user-url
[user]
(str github-url user))
(defn get-amount
[address]
(.-length address))
(defn bounty-row [{issue-id :issue_id
issue-number :issue_number
pr-number :pr_number
user :user_login
owner :owner_name
repo :repo_name
issue-title :issue_title
address :payout_address
issue-address :issue_address}]
^{:key issue-id}
[:li.list-group-item
[:div
[:a {:href (issue-url owner repo issue-number)} issue-title]]
[:div
[:a {:href (pull-url owner repo pr-number)} "fixed"]
" by "
[:a {:href (user-url user)} user]]
[:div "Payout address: " address]
[:div "Amount: " (get-amount issue-address) " ETH"]])
(defn bounties-list []
(let [bounties (rf/subscribe [:bounties])]
(fn []
[:ul.list-group
(map bounty-row @bounties)])))
(defn issue-row [{issue-id :issue_id
issue-number :issue_number
owner :owner_name
repo :repo_name
issue-title :issue_title
issue-address :issue_address}]
^{:key issue-id}
[:li.list-group-item
[:div
[:a {:href (issue-url owner repo issue-number)} issue-title]]
[:div "Amount: " (get-amount issue-address) " ETH"]])
(defn issues-list []
(let [issues (rf/subscribe [:issues])]
(fn []
[:ul.list-group
(map issue-row @issues)])))
(defn home-page []
(fn []
[:div
[:h4 "Hi"]]))
[:h3 "List of issues fixed by PRs awaiting to be signed "]
[bounties-list]
[:h3 "List of all issues"]
[issues-list]]))

View File

@ -16,6 +16,16 @@
(fn [db _]
(:repos db)))
(reg-sub
:bounties
(fn [db _]
(:bounties db)))
(reg-sub
:issues
(fn [db _]
(:issues db)))
(reg-sub
:get-in
(fn [db [_ path]]