From 38c06e2c3ae3f12c853c93565df032619b134237 Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Tue, 9 Jan 2024 21:49:04 -0500 Subject: [PATCH] tweak pr script to ignore forks and prioritize merged ones --- bin/bb-github-pr-for-commit | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/bin/bb-github-pr-for-commit b/bin/bb-github-pr-for-commit index 67714ba..2941ed1 100755 --- a/bin/bb-github-pr-for-commit +++ b/bin/bb-github-pr-for-commit @@ -21,10 +21,15 @@ (cli/error "Failed to fetch github information" (pr-str {:error (ex-message e)}))))) (defn- fetch-response [commit options] - (let [{:keys [body]} (fetch-response* commit options)] - (if-let [url (-> body (json/parse-string true) first :html_url)] + (let [{:keys [body]} (fetch-response* commit options) + repos (json/parse-string body true)] + (if-let [url (if (= 1 (count repos)) + (-> repos first :html_url) + (let [repos' (remove #(get-in % [:base :repo :fork]) repos)] + (prn :URLS (map :html_url repos')) + (->> repos' (filter :merged_at) first :html_url)))] (do (misc/open-url url) - url) + url) (cli/error "No github PR found for this commit")))) (defn -main [{:keys [options arguments summary]}]