|
6 | 6 | [k16.kmono.core.thread :as core.thread] |
7 | 7 | [k16.kmono.git :as git] |
8 | 8 | [k16.kmono.git.commit :as git.commit] |
| 9 | + [k16.kmono.git.files :as git.files] |
9 | 10 | [k16.kmono.git.tags :as git.tags] |
10 | 11 | [k16.kmono.version.semver :as semver])) |
11 | 12 |
|
|
68 | 69 | (transient {})) |
69 | 70 | persistent!))) |
70 | 71 |
|
| 72 | +(defn- file-ignored? |
| 73 | + "Returns true if the file path matches any of the ignore patterns." |
| 74 | + [patterns file-path] |
| 75 | + (boolean (some #(re-find (re-pattern %) file-path) patterns))) |
| 76 | + |
| 77 | +(defn- has-meaningful-changes? |
| 78 | + "Returns true if the package has changed files that don't all match ignore patterns. |
| 79 | + Files are matched against patterns using paths relative to the package root." |
| 80 | + [project-root pkg ref ignore-changes] |
| 81 | + (let [files (git.files/find-changed-files-since |
| 82 | + project-root {:ref ref |
| 83 | + :subdir (:relative-path pkg)}) |
| 84 | + pkg-prefix (str (:relative-path pkg) "/") |
| 85 | + relative-files (map #(str/replace-first % pkg-prefix "") files)] |
| 86 | + (boolean (seq (remove #(file-ignored? ignore-changes %) relative-files))))) |
| 87 | + |
71 | 88 | (defn- -resolve-package-changes-since |
72 | | - [project-root packages rev-fn] |
| 89 | + [project-root packages rev-fn {:keys [ignore-changes]}] |
73 | 90 | (git/with-repo [_ project-root] |
74 | 91 | (into {} |
75 | 92 | (core.thread/batch |
76 | 93 | (fn find-commits [[pkg-name pkg]] |
77 | | - (let [commits (git.commit/find-commits-since |
78 | | - project-root {:ref (rev-fn pkg) |
| 94 | + (let [ref (rev-fn pkg) |
| 95 | + commits (git.commit/find-commits-since |
| 96 | + project-root {:ref ref |
79 | 97 | :subdir (:relative-path pkg)}) |
| 98 | + commits (if (and (seq ignore-changes) (seq commits) ref) |
| 99 | + (if (has-meaningful-changes? project-root pkg ref ignore-changes) |
| 100 | + commits |
| 101 | + []) |
| 102 | + commits) |
80 | 103 | pkg (assoc pkg :commits (vec commits))] |
81 | 104 | [pkg-name pkg])) |
82 | 105 | 32) |
|
90 | 113 | and version. See `k16.kmono.version/resolve-package-versions` for a |
91 | 114 | description on how this tag is expected to be formatted. |
92 | 115 |
|
93 | | - Any commits found will be appended to the packages `:commits` key." |
| 116 | + Any commits found will be appended to the packages `:commits` key. |
| 117 | +
|
| 118 | + An optional `opts` map may be provided with `:ignore-changes` - a sequence |
| 119 | + of regexp patterns. When all changed files in a package match these patterns, |
| 120 | + the package is treated as unchanged." |
94 | 121 | {:malli/schema [:-> :string core.schema/?PackageMap core.schema/?PackageMap]} |
95 | | - [project-root packages] |
96 | | - (-resolve-package-changes-since project-root |
97 | | - packages |
98 | | - (fn [pkg] |
99 | | - (when (:version pkg) |
100 | | - (create-package-version-tag pkg))))) |
| 122 | + ([project-root packages] |
| 123 | + (resolve-package-changes project-root nil packages)) |
| 124 | + ([project-root opts packages] |
| 125 | + (-resolve-package-changes-since project-root |
| 126 | + packages |
| 127 | + (fn [pkg] |
| 128 | + (when (:version pkg) |
| 129 | + (create-package-version-tag pkg))) |
| 130 | + opts))) |
101 | 131 |
|
102 | 132 | (defn resolve-package-changes-since |
103 | 133 | "For each package try find all commits that modified files in the package |
104 | 134 | subdirectory since the given rev. |
105 | 135 |
|
106 | | - Any commits found will be appended to the packages `:commits` key." |
| 136 | + Any commits found will be appended to the packages `:commits` key. |
| 137 | +
|
| 138 | + An optional `opts` map may be provided with `:ignore-changes` - a sequence |
| 139 | + of regexp patterns. When all changed files in a package match these patterns, |
| 140 | + the package is treated as unchanged." |
107 | 141 | {:malli/schema [:-> :string :string core.schema/?PackageMap core.schema/?PackageMap]} |
108 | | - [project-root rev packages] |
109 | | - (-resolve-package-changes-since project-root |
110 | | - packages |
111 | | - (constantly rev))) |
| 142 | + ([project-root rev packages] |
| 143 | + (resolve-package-changes-since project-root rev nil packages)) |
| 144 | + ([project-root rev opts packages] |
| 145 | + (-resolve-package-changes-since project-root |
| 146 | + packages |
| 147 | + (constantly rev) |
| 148 | + opts))) |
112 | 149 |
|
113 | 150 | (defn package-changed? |
114 | 151 | "A filter function designed to be used with `k16.kmono.core.graph/filter-by`. |
|
0 commit comments