Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Score cli #1

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
3 changes: 2 additions & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"] [cheshire "5.6.3"]] )
:dependencies [[org.clojure/clojure "1.8.0"] [cheshire "5.6.3"]]
:main hacktoboy.core)
30 changes: 26 additions & 4 deletions src/hacktoboy/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,30 @@
(let [s (user key)]
(subs s 0 (- (.length s) (.length "{/privacy}")))))

;;Get Url Events of Barista Public Members
(defn members-url-events [org-name]
(map (partial get-value "events_url") (parse->clojure (str base-url "/orgs/" org-name "/members"))))
(defn members-url-events
([org-name]
"Get Url Events of Public Members for org-name"
(map (partial get-value "events_url") (parse->clojure (str base-url "/orgs/" org-name "/members"))))
([org-name token]
"Get Url Events for all Member for org-ame. Requires token and be member"
(map (partial get-value "events_url") (parse->clojure (str base-url "/orgs/" org-name "/members?access_token=" token)))))

(members-url-events "BaristaVentures")
(defn count-user-pr [user-events]
"Count User Pull Request Events"
(reduce (fn [final-prs pr]
(let [{type "type" date "created_at" {name "name"} "repo" {login "login"} "actor"} pr]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this let could be avoided if you do some destructuring at function signature

(if (and (= type "PullRequestEvent") (.startsWith date "2016-10"))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

October is hardcoded, what if you make the date an argument?

(if (empty? final-prs)
{:user login :score 1 :last date}
(assoc final-prs :score (inc (:score final-prs))))
final-prs)))
'()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if you apply a PullRequestEvent+Date filter first?
That way the reduce will get only PullRequests within the date range, making the internal function simpler

user-events))

;;Get Members Score
(defn -main [& args]
(println "User - Score")
(apply println (map (fn [m] (str "\n" (:user m) " - " (:score m)))
(sort-by :score > (filter (fn [x] (> (count x) 0))
(map count-user-pr
(map parse->clojure (apply members-url-events args))))))))