Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: stackbuilders/pull_panel
base: 27d32052e9
...
head fork: stackbuilders/pull_panel
compare: cljs_and_refactoring
  • 3 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 29, 2012
@jsl jsl WIP 002054d
Commits on May 02, 2012
@jsl jsl Running again 5f34ed1
@jsl jsl Making a mess 913a60a
View
2  .gitignore
@@ -4,3 +4,5 @@ pom.xml
/classes/
*~
.lein-deps-sum
+.lein-plugins
+.lein-cljsbuild-*
View
17 project.clj
@@ -1,7 +1,20 @@
(defproject pull-panel "0.1.0-SNAPSHOT"
:description "Quick view of github pull requests across projects"
:dependencies [[org.clojure/clojure "1.3.0"]
- [noir "1.2.1"]
- [clj-http "0.2.7"]]
+ [noir "1.2.2"]
+ [clj-http "0.3.5"]
+ [postgresql/postgresql "9.1-901-1.jdbc4"]
+ [org.clojure/java.jdbc "0.2.0"]]
+ :plugins [[lein-cljsbuild "0.1.8"]]
+ :cljsbuild {
+ :builds [{
+ ; The path to the top-level ClojureScript source directory:
+ :source-path "src-cljs"
+ ; The standard ClojureScript compiler options:
+ ; (See the ClojureScript compiler documentation for details.)
+ :compiler {
+ :optimizations :whitespace
+ :output-to "resources/public/js/main.js"
+ :pretty-print true}}]}
:main pull-panel.server)
View
12,623 resources/public/js/main.js
12,623 additions, 0 deletions not shown
View
11 src-cljs/pull_panel/main.cljs
@@ -0,0 +1,11 @@
+(ns pull_panel.main)
+
+(def jquery (js* "$"))
+
+(jquery
+ (fn []
+ (-> (jquery "div.meat")
+ (.html "This is a test!!!!")
+ (.append "<div>Look here!</div>"))))
+
+; (js/alert "Hello from ClojureScript!")
View
35 src/pull_panel/db.clj
@@ -0,0 +1,35 @@
+(ns pull-panel.db
+ (:require [clojure.java.jdbc :as sql]))
+
+(defn database-url []
+ (get (System/getenv) "DATABASE_URL"))
+
+(defn all []
+ (sql/with-connection (database-url)
+ (sql/with-query-results results
+ ["SELECT * FROM watches ORDER BY id DESC"]
+ (into [] results))))
+
+(defn delete [id]
+ (sql/with-connection (database-url)
+ (sql/delete-rows :watches ["id=?" id])))
+
+(defn create [username owner repo]
+ (sql/with-connection (database-url)
+ (sql/insert-values :watches [:username :owner :repo] [username owner repo])))
+
+(defrecord User [id name])
+
+(defrecord Watch [id owner repo])
+
+(defn create-watches-schema []
+ (sql/with-connection (database-url)
+ (sql/create-table :users
+ [:user_id :serial "PRIMARY KEY"]
+ [:username :varchar "NOT NULL"]
+ [:created_at :timestamp "NOT NULL" "DEFAULT CURRENT_TIMESTAMP"])
+ (sql/create-table :watches
+ [:watch_id :serial "PRIMARY KEY"]
+ [:owner :varchar "NOT NULL"]
+ [:repo :varchar "NOT NULL"]
+ [:created_at :timestamp "NOT NULL" "DEFAULT CURRENT_TIMESTAMP"])))
View
44 src/pull_panel/github.clj
@@ -0,0 +1,44 @@
+(ns pull-panel.github
+ (:require [clj-http.client :as client]
+ [clj-json.core :as json]))
+
+(defn fetch-login [token]
+ ((clj-json.core/parse-string
+ ((client/get (str "https://api.github.com/users?access_token=" token)
+ {:accept :json :throw-exceptions false}) :body)) "login"))
+
+(defn client-id []
+ (get (System/getenv) "GITHUB_CLIENT_ID"))
+
+(defn secret []
+ (get (System/getenv) "GITHUB_SECRET"))
+
+(defn fetch-access-token [code]
+ "Fetch an access code from Github (used from callback url)"
+ (((client/post "https://github.com/login/oauth/access_token"
+ { :form-params
+ {
+ :client_id (client-id)
+ :client_secret (secret)
+ :code code
+ }
+ :accept :json
+ }) :body) "access_token"))
+
+(defn auth-url []
+ (str "https://github.com/login/oauth/authorize?"
+ "client_id=" (client-id) "&"
+ "redirect_uri=https://pullpanel.herokuapp.com/auth/github-callback&"
+ "scope=repo"))
+
+(defn github-url []
+ (get (System/getenv) "GITHUB_URL" "https://api.github.com/"))
+
+(defn pull-url [watch token]
+ (str (github-url) (watch :owner) "/" (watch :id) "/pulls?access_token=" token))
+
+(defn pulls-for [watch token]
+ [(watch :owner) (watch :repo) (json/parse-string ((client/get (pull-url watch token) {:accept :json :throw-exceptions false}) :body))])
+
+(defn all-pulls [watches token]
+ (map #(pulls-for % token) watches))
View
39 src/pull_panel/helpers/application.clj
@@ -0,0 +1,39 @@
+(ns pull-panel.helpers.application
+ (:use [hiccup.core :only [html]])
+ (:require [hiccup.page-helpers :as page-helpers]
+ [hiccup.form-helpers :as form]))
+
+(defn pull-list [pulls]
+ (page-helpers/ordered-list (map #(page-helpers/link-to (% "html_url") (% "body")) pulls)))
+
+(defn format-pull-structure [pulls]
+ (if (map? pulls)
+ pulls
+ (if (empty? pulls)
+ " No open pulls"
+ (pull-list pulls))))
+
+(defn linked-repo [watch pulls]
+ [:p
+ [:a {:href (str "https://github.com/" org "/" repo)} org "/" repo " "]
+ [:a {:href "#" :data-id 44 } "(Unwatch)"]
+ [:span.pulls (format-pull-structure pulls)]])
+
+(defn repo-html-list [repos token all-pulls all-watches]
+ (if (empty? repos)
+ [:p "Add some repos and we'll show you Pull Requests."]
+ (page-helpers/unordered-list
+ (map #(linked-repo (% 0) (% 1) (% 2) token) all-pulls))))
+
+(defn new-repo-form []
+ (form/form-to [:post "/repos"]
+ [:p
+ (form/label "user" "User / Organization")
+ (form/text-field "user")]
+
+ [:p
+ (form/label "repo" "Repository")
+ (form/text-field "repo")
+ ]
+ (form/submit-button "Submit")))
+
View
4 src/pull_panel/views/common.clj
@@ -1,7 +1,7 @@
(ns pull-panel.views.common
(:use [noir.core :only [defpartial]]
[hiccup.page-helpers :only [include-css include-js html5]])
- (:require [noir.session :as session] ))
+ (:require [noir.session :as session]))
(defpartial site-layout [& content]
(html5
@@ -12,8 +12,10 @@
(include-css "css/application.css")
(include-css "css/bootstrap-responsive.css")
(include-js "js/jquery-1.7.1.min.js")
+ (include-js "js/main.js")
(include-js "js/bootstrap.js")]
[:body
+ [:div.meat]
[:div.navbar.navbar-fixed-top
[:div.navbar-inner
[:div.container
View
111 src/pull_panel/views/welcome.clj
@@ -1,95 +1,33 @@
(ns pull-panel.views.welcome
- (:require [pull-panel.views.common :as common])
- (:use [noir.core :only [defpage]]
- [hiccup.core :only [html]])
+ (:use [noir.core :only [defpage]])
(:require [noir.response :as resp]
- [clj-http.client :as client]
[noir.session :as session]
- [clj-json.core :as json]
- [clojure.set :as set]
- [hiccup.form-helpers :as form]
- [hiccup.page-helpers :as page-helpers]))
-
-(defpage "/repos/delete" {:keys [user repo]}
- (session/put! :repos (remove #{[user repo]} (session/get :repos)))
- (session/flash-put! (str "Deleted repo " user "/" repo) )
+ [pull-panel.github :as github]
+ [pull-panel.db :as db]
+ [pull-panel.views.common :as common]
+ [pull-panel.helpers.application :as helper]))
+
+(defpage [:delete "/repos"] {:keys [id]}
+ (db/delete id)
+ (session/flash-put! (str "Deleted repo " id))
(resp/redirect "/"))
-(defn pull-list [pulls]
- (page-helpers/ordered-list (map #(page-helpers/link-to (% "html_url") (% "body")) pulls)))
-
-(defn format-pull-structure [pulls]
- (if (map? pulls)
- pulls
- (if (empty? pulls)
- " No open pulls"
- (pull-list pulls))))
-
-(defn linked-repo [org repo pulls token]
- [:p
- [:a {:href (str "https://github.com/" org "/" repo)} org "/" repo " "]
- [:a {:href (str "/repos/delete?user=" org "&repo=" repo "&token=" token) } "(Unwatch)"]
- [:span.pulls (format-pull-structure pulls) ]
-])
-
-(defn pulls-for [user repo token]
- (let [pull-url (str "https://api.github.com/repos/" user "/" repo "/pulls?access_token=" token)]
- [user repo (json/parse-string ((client/get pull-url {:accept :json :throw-exceptions false}) :body))]))
-
-(defn all-pulls [repos token]
- (map #(pulls-for (first %) (last %) token) repos))
-
-(defn new-repo-form []
- "Form for adding a new repo to polled collection"
- (form/form-to [:post "/repos"]
- [:p
- (form/label "user" "User / Organization")
- (form/text-field "user")]
-
- [:p
- (form/label "repo" "Repository")
- (form/text-field "repo")
- ]
- (form/submit-button "Submit")))
-
-(defn repo-html-list [repos token]
- (if (empty? repos)
- [:p "Add some repos and we'll show you Pull Requests."]
- (page-helpers/unordered-list
- (map #(linked-repo (% 0) (% 1) (% 2) (session/get :token))
- (all-pulls
- (session/get :repos)
- (session/get :token))))))
-
(defpage "/" []
(common/site-layout
[:h1 "Pull Panel"]
[:hr]
- (if (session/get :token)
- [:span.repos
- (repo-html-list (session/get :repos) (session/get :token))
- [:hr]
- [:h2 "Add a new repo"]
- (new-repo-form)]
- [:p "You must log in to use Pull Panel."])))
+ [:span.repos
+ (helper/repo-html-list (db/all) (session/get :token) (github/all-pulls (db/all) (session/get :token)) (db/all))
+ [:hr]
+ [:h2 "Add a new repo"]
+ (helper/new-repo-form)]))
(defpage "/auth/github" []
- (resp/redirect
- (str "https://github.com/login/oauth/authorize?"
- "client_id=" (get (System/getenv) "GITHUB_CLIENT_ID") "&"
- "redirect_uri=https://pullpanel.herokuapp.com/auth/github-callback&"
- "scope=repo")))
-
-(defn delete-repo-form [user repo]
- "Form to delete a repo"
- (form/form-to [:delete "/repos"]
- (form/hidden-field "user" user)
- (form/hidden-field "repo" repo)
- (form/submit-button "Unwatch")))
+ (resp/redirect github/auth-url))
(defpage [:post "/repos"] {:keys [user repo]}
- (session/put! :repos (set/union (session/get :repos) #{[user repo]}))
- (session/flash-put! (str "Added repo " user "/" repo) )
+ (db/create (session/get :login) user repo)
+ (session/flash-put! (str "Added repo " user "/" repo))
(resp/redirect "/"))
(defpage "/logout" []
@@ -98,17 +36,12 @@
(resp/redirect "/"))
(defpage "/set-token" {:keys [token]}
- "Hacky for testing: set the API token given to your app for local testing"
(session/put! :token token)
- (session/flash-put! (str "Set token to " token) )
+ (session/flash-put! (str "Set token to " token))
(resp/redirect "/"))
(defpage "/auth/github-callback" {:keys [code]}
- (let [res (client/post "https://github.com/login/oauth/access_token"
- {:form-params {:client_id (get (System/getenv) "GITHUB_CLIENT_ID")
- :client_secret (get (System/getenv) "GITHUB_SECRET")
- :code code }
- :accept :json})]
- ((session/put! :token ((json/parse-string (res :body)) "access_token"))
- (session/flash-put! (str "Github user session created" ))
- (resp/redirect "/"))))
+ (session/put! :token (github/fetch-access-token code))
+ (session/put! :login (github/fetch-login (session/get :token)))
+ (session/flash-put! (str "Github user session created for " (session/get :login)))
+ (resp/redirect "/"))
View
6 test/pull_panel/test/models/watch.clj
@@ -0,0 +1,6 @@
+(ns pull-panel.test.models.watch
+ (:use [clojure.test])
+ (:use [pull-panel.models.watch :as watch]))
+
+(deftest create-test
+ (is (= (watch/create "user" "owner" "repo"))))

No commit comments for this range

Something went wrong with that request. Please try again.