Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Raynes/tentacles
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: master
Choose a base ref
...
head repository: circleci/tentacles
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
Can’t automatically merge. Don’t worry, you can still create the pull request.
  • 17 commits
  • 5 files changed
  • 9 contributors

Commits on Aug 18, 2015

  1. Fix a bug in safe-parse

    - Don't try to add metadata to things that don't support it.
    - When returning an API response that is a seq, add metadata to the response, not each item in the response.
    arohner authored and circlecai committed Aug 18, 2015
    Copy the full SHA
    44e6890 View commit details

Commits on Sep 11, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    bostonaholic Matthew Boston
    Copy the full SHA
    ca5192c View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    bostonaholic Matthew Boston
    Copy the full SHA
    5b2e734 View commit details

Commits on Sep 14, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    bostonaholic Matthew Boston
    Copy the full SHA
    be3ccb0 View commit details

Commits on Sep 18, 2018

  1. Verified

    This commit was signed with the committer’s verified signature.
    bostonaholic Matthew Boston
    Copy the full SHA
    1679632 View commit details

Commits on Oct 31, 2019

  1. added circleci config

    smaant committed Oct 31, 2019
    Copy the full SHA
    230103a View commit details
  2. fixed tests

    smaant committed Oct 31, 2019
    Copy the full SHA
    66883d1 View commit details
  3. Copy the full SHA
    09cff4c View commit details

Commits on Nov 1, 2019

  1. Merge pull request #7 from circleci/circle-config

    Added CircleCI config
    smaant authored Nov 1, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    54329d4 View commit details
  2. Copy the full SHA
    eba73b0 View commit details
  3. Merge pull request #8 from circleci/CIRCLE-21513-timeout-2

    CIRCLE-21513 added ability to configure http timeouts
    smaant authored Nov 1, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    b73d7fa View commit details

Commits on Jan 13, 2023

  1. [SECOPS-2716] Add CODEOWNERS file

    No action required. This PR will be merged by @circleci/security-operations.
    circleci-bot committed Jan 13, 2023
    Copy the full SHA
    476ab89 View commit details

Commits on Jan 16, 2023

  1. Merge pull request #9 from circleci/backplane-bot/add-secops-codeowners

    [SECOPS-2716] Add CODEOWNERS file
    bear authored Jan 16, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3b5806b View commit details

Commits on Feb 2, 2024

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    2b2c9ce View commit details

Commits on Feb 5, 2024

  1. Merge pull request #10 from circleci/SECENG_update-default-codeowners

    Replace Security-Operations with Default-Security-Operations
    ryan-wren authored Feb 5, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    c0d09ed View commit details

Commits on Mar 27, 2024

  1. Update CODEOWNERS

    vallieres authored Mar 27, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    72e759a View commit details

Commits on Mar 28, 2024

  1. Merge pull request #11 from circleci/SECENG_update-co

    Update CODEOWNERS
    geoffnichols authored Mar 28, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    07ece1f View commit details
Showing with 117 additions and 15 deletions.
  1. +48 −0 .circleci/config.yml
  2. +4 −0 CODEOWNERS
  3. +18 −2 project.clj
  4. +24 −9 src/tentacles/core.clj
  5. +23 −4 test/tentacles/core_test.clj
48 changes: 48 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
version: 2.1

workflows:
test-and-deploy:
jobs:
- test:
context: org-global

- deploy:
context: org-global
requires:
- test
filters:
branches:
only:
- master

jobs:
test:
docker:
- image: clojure:lein-2.8.1

steps:
- checkout
- restore_cache:
keys:
- v1-jars-{{ checksum "project.clj" }}
- v1-jars-
- run:
name: Run the tests
command: lein test2junit
- save_cache:
key: v1-jars-{{ checksum "project.clj" }}
paths:
- ~/.m2
- store_test_results:
path: ./test2junit/xml

deploy:
docker:
- image: clojure:lein-2.8.1
steps:
- checkout
- restore_cache:
keys:
- v1-jars-{{ checksum "project.clj" }}
- v1-jars-
- run: lein deploy
4 changes: 4 additions & 0 deletions CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Placeholder CODEOWNERS file as this repo did not have one
# Please make a PR adding the correct owner or request that this repo be archived
* @circleci/maintainers-monolith @circleci/backplane
# one or both?
20 changes: 18 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
(defproject tentacles "0.4.0"
(def project-version (if-let [build-num (System/getenv "CIRCLE_BUILD_NUM")]
(str "0.2." build-num)
"0.2.0-SNAPSHOT"))

(defproject circleci/tentacles project-version
:description "A library for working with the Github API."
:url "https://github.com/Raynes/tentacles"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}

:dependencies [[org.clojure/clojure "1.5.1"]
[clj-http "1.0.1"]
[cheshire "5.4.0"]
[com.cemerick/url "0.1.1"]
[org.clojure/data.codec "0.1.0"]
[environ "1.0.0"]])
[environ "1.0.0"]]

:profiles {:dev {:plugins [[test2junit "1.4.2"]]}}

:repositories [["releases" {:url "https://clojars.org/repo"
:username :env/clojars_username
:password :env/clojars_password
:sign-releases false}]
["snapshots" {:url "https://clojars.org/repo"
:username :env/clojars_username
:password :env/clojars_password
:sign-releases false}]])
33 changes: 24 additions & 9 deletions src/tentacles/core.clj
Original file line number Diff line number Diff line change
@@ -5,13 +5,14 @@
[cemerick.url :as url]))

(def ^:dynamic url "https://api.github.com/")
(def ^:dynamic defaults {})
(def ^:dynamic defaults {:follow-redirects true
:throw-exceptions false})

(defn query-map
"Merge defaults, turn keywords into strings, and replace hyphens with underscores."
[entries]
(into {}
(for [[k v] (concat defaults entries)]
(for [[k v] entries]
[(.replace (name k) "-" "_") v])))

(defn parse-json
@@ -44,6 +45,11 @@
[obj]
(:api-meta (meta obj)))

(defn meta?
"True if metadata can be added to the object"
[x]
(instance? clojure.lang.IObj x))

(defn safe-parse
"Takes a response and checks for certain status codes. If 204, return nil.
If 400, 401, 204, 422, 403, 404 or 500, return the original response with the body parsed
@@ -61,10 +67,9 @@
metadata (extract-useful-meta headers)]
(if-not (.contains content-type "raw")
(let [parsed (parse-json body)]
(if (map? parsed)
(if (meta? parsed)
(with-meta parsed {:links links :api-meta metadata})
(with-meta (map #(with-meta % metadata) parsed)
{:links links :api-meta metadata})))
parsed))
body))))

(defn update-req
@@ -86,8 +91,9 @@
(defn make-request [method end-point positional
{:keys [auth throw-exceptions follow-redirects accept
oauth-token etag if-modified-since user-agent
otp]
:or {follow-redirects true throw-exceptions false}
otp conn-timeout socket-timeout conn-request-timeout]
:or {follow-redirects (:follow-redirects defaults)
throw-exceptions (:throw-exceptions defaults)}
:as query}]
(let [req (merge-with merge
{:url (format-url end-point positional)
@@ -106,9 +112,18 @@
(when otp
{:headers {"X-GitHub-OTP" otp}})
(when if-modified-since
{:headers {"if-Modified-Since" if-modified-since}}))
{:headers {"if-Modified-Since" if-modified-since}})
(when conn-timeout
{:conn-timeout conn-timeout})
(when socket-timeout
{:socket-timeout socket-timeout})
(when conn-request-timeout
{:conn-request-timeout conn-request-timeout}))
raw-query (:raw query)
proper-query (query-map (dissoc query :auth :oauth-token :all-pages :accept :user-agent :otp))
proper-query (query-map (dissoc (merge defaults query)
:auth :oauth-token :all-pages :accept :user-agent
:otp :throw-exceptions :follow-redirects
:conn-timeout :socket-timeout :conn-request-timeout))
req (if (#{:post :put :delete} method)
(assoc req :body (json/generate-string (or raw-query proper-query)))
(assoc req :query-params proper-query))]
27 changes: 23 additions & 4 deletions test/tentacles/core_test.clj
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

(deftest request-contains-user-agent
(let [request (core/make-request :get "test" nil {:user-agent "Mozilla"})]
(do (is (empty? (:query-params request)))
(do (is (empty? (:query-params request)))
(is (contains? (:headers request) "User-Agent"))
(is (= (get (:headers request) "User-Agent") "Mozilla")))))

@@ -14,11 +14,30 @@

(deftest rate-limit-details-are-propagated
(is (= 60 (:call-limit (core/api-meta
(core/safe-parse {:status 200 :headers {"x-ratelimit-limit" "60"
"content-type" ""}}))))))
(core/safe-parse {:status 200
:headers {"x-ratelimit-limit" "60"
"content-type" ""}
:body "{\"x\":1}"}))))))

(deftest poll-limit-details-are-propagated
(is (= 61 (:poll-interval (core/api-meta
(core/safe-parse {:status 200
:headers {"x-poll-interval" "61"
"content-type" ""}}))))))
"content-type" ""}
:body "{\"x\":1}"}))))))

(deftest timeouts-are-propagated
(testing "timeouts are propagated"
(is (= {:conn-timeout 1000
:socket-timeout 2000
:conn-request-timeout 3000}
(select-keys (core/make-request :get "test" nil {:conn-timeout 1000
:socket-timeout 2000
:conn-request-timeout 3000})
[:conn-timeout :socket-timeout :conn-request-timeout]))))

(testing "timeouts aren't imposed by default"
(is (= {}
(select-keys (core/make-request :get "test" nil {})
[:conn-timeout :socket-timeout :conn-request-timeout])))))