Get rid of parents and merge_commit_sha

This commit is contained in:
kagel 2016-08-31 00:45:25 +03:00
parent f9d983076c
commit fdfaafc2c1
5 changed files with 47 additions and 33 deletions

View File

@ -0,0 +1,10 @@
ALTER TABLE pull_requests
ADD COLUMN parents VARCHAR(4099);
-- noinspection SqlResolve
ALTER TABLE pull_requests
DROP COLUMN commit_id;
-- noinspection SqlResolve
ALTER TABLE pull_requests
DROP COLUMN issue_number;

View File

@ -0,0 +1,9 @@
-- noinspection SqlResolve
ALTER TABLE public.pull_requests
DROP parents;
ALTER TABLE public.pull_requests
ADD COLUMN commit_id VARCHAR(40);
ALTER TABLE public.pull_requests
ADD COLUMN issue_number INTEGER;

View File

@ -101,13 +101,12 @@ RETURNING repo_id, issue_id, issue_number, title, address, commit_id;
-- :name create-pull-request! :! :n
-- :doc creates pull request
INSERT INTO pull_requests (repo_id, pr_id, pr_number, user_id, parents)
INSERT INTO pull_requests (repo_id, pr_id, pr_number, user_id)
SELECT
:repo_id,
:pr_id,
:pr_number,
:user_id,
:parents
:user_id
WHERE NOT exists(SELECT 1
FROM pull_requests
WHERE repo_id = :repo_id AND pr_id = :pr_id);
@ -132,7 +131,7 @@ SELECT
r.repo AS repo_name
FROM issues i
INNER JOIN pull_requests p
ON p.parents LIKE '%' || i.commit_id || '%'
ON (p.commit_id = i.commit_id OR coalesce(p.issue_number, -1) = i.issue_number)
AND p.repo_id = i.repo_id
INNER JOIN users u
ON u.id = p.user_id

View File

@ -15,6 +15,6 @@
(defn close
"Updates issue with commit_id"
[issue-id commit-id]
[commit-id issue-id]
(jdbc/with-db-connection [con-db *db*]
(db/close-issue! con-db {:issue_id issue-id :commit_id commit-id})))

View File

@ -10,45 +10,41 @@
(def label-name "bounty")
(defn find-issue-closed-event
[events]
(first (filter #(= "closed" (:event %)) events)))
(defn find-issue-event
[events type]
(first (filter #(= type (:event %)) events)))
(defn find-commit-id
[user repo issue-number event-type]
(->
(github/get-issue-events user repo issue-number)
(find-issue-event event-type)
(:commit_id)))
(defn handle-issue-closed
[{{{user :login} :owner repo :name} :repository
{issue-id :id issue-number :number} :issue}]
(future
(->>
(github/get-issue-events user repo issue-number)
(find-issue-closed-event)
(:commit_id)
(issues/close issue-id))))
(defn get-commit-parents
[commit]
(->> commit :parents (map :sha) (join ",")))
(when-let [commit-id (find-commit-id user repo issue-number "closed")]
(issues/close commit-id issue-id))))
(defn handle-pull-request-closed
[{{{owner :login} :owner
repo-name :name
repo-id :id} :repository
repo :name
repo-id :id} :repository
{{user-id :id
login :login
name :name} :user
id :id
pr-number :number
merge-commit-sha :merge_commit_sha} :pull_request}]
name :name} :user
id :id
pr-number :number} :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
:pr_number pr-number
:user_id user-id})
(pull-requests/create))
(users/create-user user-id login name nil nil)))
(when-let [commit-id (find-commit-id owner repo pr-number "merged")]
(pull-requests/create {:repo_id repo-id
:pr_id id
:pr_number pr-number
:user_id user-id
:commit_id commit-id})
(users/create-user user-id login name nil nil))))
(defn labeled-as-bounty?
[action issue]