Skip to content

qx_first and latest commit by author email

RichMorin edited this page Dec 31, 2012 · 5 revisions

Ignored

Query Example: first-and-latest-commit-by-author-email

first-and-latest-commit-by-author-email - first and latest commit, by author email

This example comes from the core.clj file in Devin Walter's nifty codeq-playground.

Problem

You need to get date/time values of an author's first and latest commits, based on her email address.

Solution

Ask Codeq for date/time values of all commits where the author is the user, based on her email address. Return the email address, along with the minimum and maximum date/time values:

(defn first-and-latest-commit-by-author-email
  "first and latest commit, by author email"
  [email]
  (d/q '[:find ?email (min ?date) (max ?date)
         :in $ ?email
         :where
         [ ?commit  :commit/committedAt  ?date  ]    ;; get commits and dates
         [ ?commit  :commit/author       ?user  ]    ;; get users for a commit
         [ ?user    :email/address       ?email ] ]  ;; filter by email address
       db email))

The function is used as follows:

(first-and-latest-commit-by-author-email "[email protected]")

Discussion

This function assumes that db is a database connection.

See Also

Clone this wiki locally