Skip to content

Commit

Permalink
[patch] ✨ Add primitive functions (#4)
Browse files Browse the repository at this point in the history
* ✨ Add primitive functions

Signed-off-by: Rintaro Okamura <[email protected]>

* ⚡ Add static

Signed-off-by: Rintaro Okamura <[email protected]>

* 🔥 Remove static flags

Signed-off-by: Rintaro Okamura <[email protected]>
  • Loading branch information
rinx authored Jan 10, 2020
1 parent 6f3eb19 commit 466aaff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
12 changes: 9 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ increments version by git log message contexts.

[semver workflow of this repository](https://github.com/rinx/gitwerk/blob/master/.github/workflows/semver.yml) is an example of this subcommand.

```
```bash
## when the latest tag is v0.0.1
$ git commit -m "[patch] increment patch version"
## the commit comment contains "[patch]"
Expand Down Expand Up @@ -64,7 +64,7 @@ $ gitwerk semver-auto

prints incremented version.

```
```bash
## when the latest tag is v0.0.1

$ gitwerk semver patch
Expand All @@ -81,7 +81,7 @@ v1.0.0

gitwerk supports to run user-defined scripts written in clojure (powered by [borkdude/sci](https://github.com/borkdude/sci)).

```
```bash
## can read stdin
$ echo '(semver ctx ["patch"])' | gitwerk sci
v0.0.2
Expand All @@ -107,6 +107,12 @@ Version not updated
$ git commit --allow-empty -m "[patch] version updated"
$ gitwerk sci examples/example2.clj
Version updated: v0.0.3 -> v0.0.4

## http get/post using clj-http-lite.client
$ echo '(-> (http/get "https://api.github.com/repos/rinx/gitwerk/issues") pprint)' | gitwerk sci

## parse json and convert to clj map
$ echo '(-> (http/get "https://api.github.com/repos/rinx/gitwerk/issues") :body (json/read-value) pprint)' | gitwerk sci
```

## License
Expand Down
12 changes: 10 additions & 2 deletions src/gitwerk/command/sci.clj
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@
(:require
[clojure.spec.alpha :as spec]
[clojure.pprint :as pprint]
[clojure.edn :as edn]
[sci.core :as sci]
[gitwerk.internal.io :as internal.io]))
[clj-http.lite.client :as http]
[gitwerk.internal.io :as internal.io]
[gitwerk.internal.json :as json]))

(def clj-primitives
{'println println
'pprint pprint/pprint})
'pprint pprint/pprint
'json/read-value json/read-value
'edn/read-string edn/read-string
'env #(or (System/getenv %) "")
'http/get http/get
'http/post http/post})

(defn run-fn [sci-opts]
(fn [ctx args]
Expand Down

0 comments on commit 466aaff

Please sign in to comment.