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

Add command for fetching the latest release info from a github repo #772

Merged
merged 5 commits into from Nov 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/yetibot/api/github.clj
Expand Up @@ -116,6 +116,18 @@
(with-url endpoint
(r/code-frequency org-name repo auth)))

(defn latest-releases [org-name repo]
(with-url endpoint
(r/specific-release org-name repo "latest")))

(defn release-by-tag [org-name repo tag]
(with-url endpoint
(r/specific-release-by-tag org-name repo tag)))

(defn releases [org-name repo]
(with-url endpoint
(r/releases org-name repo)))

(defn sum-weekly
"Takes the weekly stats for an author and sums them into:
{:a 0 :d 0 :c 0}
Expand Down
48 changes: 47 additions & 1 deletion src/yetibot/commands/github.clj
Expand Up @@ -13,6 +13,7 @@
[robert.bruce :refer [try-try-again] :as rb]))

(def date-formatter (f/formatters :date))
(def date-hour-formatter (f/formatter "MMM d, yyyy 'at' hh:mm"))

(defn feed
"gh feed <org-name> # list recent activity for <org-name>"
Expand Down Expand Up @@ -136,6 +137,48 @@
(f/unparse date-formatter datetime))))
(str n " is not a number"))))

(defn format-release
"Displays information about a release"
[release org-name repo]
(if (nil? (:status release))
(let [tag (:tag_name release)
author (get-in release [:author :login])
published-at (-> "YYYY-MM-dd'T'HH:mm:ssZ"
(f/formatter)
(f/parse (:published_at release)))
body (:body release)]
(format "Release version, tagged: %s from %s/%s, was published on %s by %s\n %s" tag org-name repo
(f/unparse date-hour-formatter published-at) author body))
(format "No release version info found for %s/%s" org-name repo)))

(defn show-latest-release-info-cmd
"gh releases show <org>/<repo-name> # retrieve info about the latest release on a Github repository"
{:yb/cat #{:util :info}}
[{[_ org-name repo] :match}]
(let [release (gh/latest-releases org-name repo)]
(format-release release org-name repo)))
kaffein marked this conversation as resolved.
Show resolved Hide resolved

(defn show-release-info-by-tag-cmd
"gh releases show <org>/<repo-name> <tag> # retrieve info about a specific release tag on a Github repository"
{:yb/cat #{:util :info}}
[{[_ org-name repo tag] :match}]
(let [release (gh/release-by-tag org-name repo tag)]
(format-release release org-name repo)))

(defn list-releases-info-cmd
"gh releases <org>/<repo-name> # list releases for a Github repository"
{:yb/cat #{:util :info}}
[{[_ org-name repo] :match}]
(if-let [releases (gh/releases org-name repo)]
(for [release releases]
(let [tag (:tag_name release)
author (get-in release [:author :login])
published-at (-> "YYYY-MM-dd'T'HH:mm:ssZ"
(f/formatter)
(f/parse (:published_at release)))]
(format "Release version tagged: %s, from %s/%s, was published on %s by %s" tag org-name repo
(f/unparse date-hour-formatter published-at) author)))
(format "No releases found on %s/%s" org-name repo)))

(when (gh/configured?)
(cmd-hook ["gh" #"^gh|github$"]
Expand All @@ -154,4 +197,7 @@
#"stats\s+(\S+)\/(\S+)" stats-cmd
#"contributors\s+(\S+)\/(\S+)\s+since\s+(\d+)\s+(minutes*|hours*|days*|weeks*|months*)" contributors-since-cmd
#"tags\s+(\S+)\/(\S+)" tags
#"branches\s+(\S+)\/(\S+)" branches))
#"branches\s+(\S+)\/(\S+)" branches
#"releases\s+show\s+(\S+)\/(\S+)\s+(\S+)" show-release-info-by-tag-cmd
#"releases\s+show\s+(\S+)\/(\S+)" show-latest-release-info-cmd
#"releases\s+(\S+)\/(\S+)" list-releases-info-cmd))