Skip to content

Commit

Permalink
fix: Use pulls API instead of Github Search (#81)
Browse files Browse the repository at this point in the history
I ran into the secondary rate limit issue in this Github Actions. From
deeper investigation, it appears the code for fetching PRs has a tighter
rate limit than the past.

From investigation, it appears that switching to the pulls API should
avoid the rate limit on the search API.

This should fix #73.
  • Loading branch information
rymndhng authored Oct 25, 2022
1 parent 5c2a2ea commit 8e3c8b4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/release_on_push_action/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
(:body (github/fetch-commit (assoc context :sha tag))))}))

(defn get-labels [related-prs]
(->> related-prs :items (map :labels) flatten (map :name) set))
(->> related-prs (map :labels) flatten (map :name) set))

(defn bump-version-scheme [context related-data]
(let [labels (get-labels (:related-prs related-data))]
Expand Down
10 changes: 6 additions & 4 deletions src/release_on_push_action/github.clj
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@

;; -- Github PRs API ----------------------------------------------------------
(defn fetch-related-prs
"See https://developer.github.com/v3/pulls/#list-pull-requests"
"See https://docs.github.com/en/rest/commits/commits#list-pull-requests-associated-with-a-commit"
[context]
(parse-response
(curl/get (format "%s/search/issues" (:github/api-url context))
{:headers (headers context)
:query-params {"q" (format "repo:%s type:pr is:closed is:merged SHA:%s" (:repo context) (:sha context))}})))
(curl/get (format "%s/repos/%s/commits/%s/pulls"
(:github/api-url context)
(:repo context)
(:sha context))
{:headers (headers context)})))

;; -- Github Releases API -----------------------------------------------------
(defn fetch-latest-release
Expand Down
4 changes: 2 additions & 2 deletions test/release_on_push_action/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
(deftest ^:integration generate-new-release-data-from-new-project
(let [[ctx related-data] @fixture-project-without-release]
(testing "preconditions"
(is (= 0 (get-in related-data [:related-prs :total_count])))
(is (= 0 (count (get-in related-data [:related-prs]))))
(is (= "Commit 10" (get-in related-data [:commit :commit :message])))
(is (nil? (:latest-release related-data)) "has no latest release"))

Expand Down Expand Up @@ -157,7 +157,7 @@ Hello World
(deftest ^:integration generate-new-release-data-from-existing-release
(let [[ctx related-data] @fixture-project-with-release]
(testing "preconditions"
(is (= 0 (get-in related-data [:related-prs :total_count])))
(is (= 0 (count (get-in related-data [:related-prs]))))
(is (= "Commit 10" (get-in related-data [:commit :commit :message])))
(is (= "v0.1.0" (get-in related-data [:latest-release :tag_name])) "has release v0.1.0"))

Expand Down

0 comments on commit 8e3c8b4

Please sign in to comment.