-
Notifications
You must be signed in to change notification settings - Fork 11
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
chore: add specs to the codebase #74
Changes from 16 commits
70b75ce
16cb5a1
1bb4dfb
5948cc9
f239cd7
51c535e
1dc2564
1cc5e3c
171548f
d6ba18c
b2e4de9
78e0b2a
3c830ca
d17a9e7
8556e21
a1d3a47
c7b7e6b
f2e2eee
87e488b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
(ns github-changelog.config | ||
(:require [clojure.spec.alpha :as s] | ||
[github-changelog.spec :as spec])) | ||
|
||
(s/def ::git-url ::spec/url) | ||
|
||
(s/def ::github ::spec/url) | ||
|
||
(s/def ::github-api ::spec/url) | ||
|
||
(s/def ::jira ::spec/url) | ||
|
||
(s/def ::user ::spec/non-blank-string) | ||
|
||
(s/def ::repo ::spec/non-blank-string) | ||
|
||
(s/def ::dir ::spec/non-blank-string) | ||
|
||
(s/def ::update? boolean?) | ||
|
||
(s/def ::tag-prefix string?) | ||
|
||
(s/def ::token ::spec/non-blank-string) | ||
|
||
(s/def ::config-map | ||
(s/keys :req-un [::user ::repo] | ||
:opt-un [::token ::github ::github-api ::jira ::dir ::update? ::git-url])) | ||
|
||
(def defaults {:github "https://github.com/" | ||
:github-api "https://api.github.com/" | ||
:update? true | ||
:tag-prefix "v"}) | ||
|
||
(comment | ||
(s/exercise ::config-map)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,51 @@ | ||
(ns github-changelog.conventional | ||
(:require [clojure.string :as str] | ||
(:require [clojure.spec.alpha :as s] | ||
[clojure.spec.gen.alpha :as gen] | ||
[clojure.string :as str] | ||
[github-changelog.config :as config] | ||
[github-changelog.core-spec :as core-spec] | ||
[github-changelog.github :as github] | ||
[github-changelog.spec :as spec] | ||
[github-changelog.util :refer [strip-trailing]])) | ||
|
||
; https://help.github.com/articles/closing-issues-via-commit-messages/ | ||
(def close-keywords #{"close" "closes" "closed" "fix" "fixes" "fixed" "resolve" "resolves" "resolved" "related to" "relates to"}) | ||
|
||
(def angular-pattern #"^(\w*)(?:\((.*)\))?\: (.*)$") | ||
|
||
(s/def ::type ::spec/non-blank-string) | ||
(s/def ::scope string?) | ||
(s/def ::subject ::spec/non-blank-string) | ||
|
||
(s/def ::issue (s/tuple ::spec/non-blank-string ::spec/url)) | ||
|
||
(s/def ::issues (s/* ::issue)) | ||
|
||
(defn title-gen [] | ||
(gen/fmap (fn [[type scope subject]] | ||
(if (str/blank? scope) | ||
(format "%s: %s" type subject) | ||
(format "%s(%s): %s" type scope subject))) | ||
(s/gen (s/tuple ::type ::scope ::subject)))) | ||
|
||
(s/def ::title | ||
(s/with-gen | ||
(s/and string? #(re-matches angular-pattern %)) | ||
title-gen)) | ||
|
||
;; (s/def ::revert-pull pos-int?) | ||
|
||
;; (s/def ::revert-pr | ||
;; (s/keys :req-un [::revert-pull ::pull-request])) | ||
|
||
(s/def ::pull-request ::github/pull) | ||
|
||
(s/def ::change (s/keys :req-un [::type ::scope ::subject ::pull-request ::issues])) | ||
(s/def ::changes (s/* ::change)) | ||
|
||
(s/def ::tag-with-changes | ||
(s/merge ::core-spec/tag-with-pulls (s/keys :req-un [::changes]))) | ||
|
||
(defn fixes-pattern | ||
([pattern] (fixes-pattern pattern close-keywords)) | ||
([pattern closing-words] | ||
|
@@ -13,8 +54,6 @@ | |
(str/join \| closing-words) | ||
pattern)))) | ||
|
||
(def angular-pattern #"^(\w*)(?:\((.*)\))?\: (.*)$") | ||
|
||
(defn collect-issues [pull pattern link-fn] | ||
(->> (:body pull) | ||
(str) | ||
|
@@ -49,14 +88,14 @@ | |
|
||
(defn parse-pull [config {:keys [title] :as pull}] | ||
(if-let [pull-id (parse-revert config pull)] | ||
{:revert-pull pull-id | ||
{:revert-pull pull-id | ||
:pull-request pull} | ||
(if-let [[_ type scope subject] (re-find angular-pattern title)] | ||
{:type type | ||
:scope scope | ||
:subject subject | ||
(when-let [[_ type scope subject] (re-find angular-pattern title)] | ||
{:type type | ||
:scope scope | ||
:subject subject | ||
:pull-request pull | ||
:issues (parse-issues config pull)}))) | ||
:issues (parse-issues config pull)}))) | ||
|
||
(defn reverted-ids [pulls] | ||
(->> (map :revert-pull pulls) | ||
|
@@ -70,9 +109,19 @@ | |
pulls | ||
(conj pulls pull)))) | ||
|
||
(defn parse-changes [config {:keys [pulls] :as tag}] | ||
(defn ^:no-gen parse-changes [config {:keys [pulls] :as tag}] | ||
(->> (map (partial parse-pull config) pulls) | ||
(remove nil?) | ||
raszi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
(reduce filter-reverted []) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you rewrite There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also comp in the next line then There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also though that but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, I didn't realise |
||
(remove :revert-pull) | ||
(assoc tag :changes))) | ||
|
||
(s/fdef parse-changes | ||
:args (s/cat :config ::config/config-map :tag ::core-spec/tag-with-pulls) | ||
:ret (s/* ::tag-with-changes)) | ||
|
||
(comment | ||
(s/exercise-fn `parse-changes) | ||
(s/exercise ::issue) | ||
(s/exercise ::issues) | ||
(s/exercise ::title)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
(ns github-changelog.core-spec | ||
(:require [clojure.spec.alpha :as s] | ||
[github-changelog.git :as git] | ||
[github-changelog.github :as github] | ||
[github-changelog.semver :as semver])) | ||
|
||
(s/def ::commits (s/* ::git/commit)) | ||
|
||
(s/def ::tag | ||
(s/merge ::git/tag (s/keys :req-un [::semver/version ::commits]))) | ||
|
||
(s/def ::pulls (s/* ::github/pull)) | ||
|
||
(s/def ::tag-with-pulls | ||
(s/merge ::tag (s/keys :req-un [::pulls]))) | ||
|
||
(comment | ||
(s/exercise ::tag) | ||
(s/exercise ::tag-with-pulls)) |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there still a need for the comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure, but I have not tested.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's safe to remove