intershell 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (357) hide show
  1. package/README.md +301 -0
  2. package/dist/commands/ci/act.d.ts +13 -0
  3. package/dist/commands/ci/act.d.ts.map +1 -0
  4. package/dist/commands/ci/act.js +89 -0
  5. package/dist/commands/ci/act.js.map +1 -0
  6. package/dist/commands/ci/attach-affected.d.ts +12 -0
  7. package/dist/commands/ci/attach-affected.d.ts.map +1 -0
  8. package/dist/commands/ci/attach-affected.js +83 -0
  9. package/dist/commands/ci/attach-affected.js.map +1 -0
  10. package/dist/commands/ci/attach-service-ports.d.ts +10 -0
  11. package/dist/commands/ci/attach-service-ports.d.ts.map +1 -0
  12. package/dist/commands/ci/attach-service-ports.js +25 -0
  13. package/dist/commands/ci/attach-service-ports.js.map +1 -0
  14. package/dist/commands/commit-check.d.ts +13 -0
  15. package/dist/commands/commit-check.d.ts.map +1 -0
  16. package/dist/commands/commit-check.js +110 -0
  17. package/dist/commands/commit-check.js.map +1 -0
  18. package/dist/commands/commit.d.ts +16 -0
  19. package/dist/commands/commit.d.ts.map +1 -0
  20. package/dist/commands/commit.js +91 -0
  21. package/dist/commands/commit.js.map +1 -0
  22. package/dist/commands/dev/check.d.ts +13 -0
  23. package/dist/commands/dev/check.d.ts.map +1 -0
  24. package/dist/commands/dev/check.js +91 -0
  25. package/dist/commands/dev/check.js.map +1 -0
  26. package/dist/commands/dev/cleanup.d.ts +10 -0
  27. package/dist/commands/dev/cleanup.d.ts.map +1 -0
  28. package/dist/commands/dev/cleanup.js +28 -0
  29. package/dist/commands/dev/cleanup.js.map +1 -0
  30. package/dist/commands/dev/rm.d.ts +12 -0
  31. package/dist/commands/dev/rm.d.ts.map +1 -0
  32. package/dist/commands/dev/rm.js +49 -0
  33. package/dist/commands/dev/rm.js.map +1 -0
  34. package/dist/commands/dev/setup.d.ts +10 -0
  35. package/dist/commands/dev/setup.d.ts.map +1 -0
  36. package/dist/commands/dev/setup.js +40 -0
  37. package/dist/commands/dev/setup.js.map +1 -0
  38. package/dist/commands/local/cleanup.d.ts +12 -0
  39. package/dist/commands/local/cleanup.d.ts.map +1 -0
  40. package/dist/commands/local/cleanup.js +62 -0
  41. package/dist/commands/local/cleanup.js.map +1 -0
  42. package/dist/commands/local/setup.d.ts +11 -0
  43. package/dist/commands/local/setup.d.ts.map +1 -0
  44. package/dist/commands/local/setup.js +55 -0
  45. package/dist/commands/local/setup.js.map +1 -0
  46. package/dist/commands/local/vscode.d.ts +17 -0
  47. package/dist/commands/local/vscode.d.ts.map +1 -0
  48. package/dist/commands/local/vscode.js +94 -0
  49. package/dist/commands/local/vscode.js.map +1 -0
  50. package/dist/commands/update-package-json.d.ts +12 -0
  51. package/dist/commands/update-package-json.d.ts.map +1 -0
  52. package/dist/commands/update-package-json.js +82 -0
  53. package/dist/commands/update-package-json.js.map +1 -0
  54. package/dist/commands/version/apply.d.ts +16 -0
  55. package/dist/commands/version/apply.d.ts.map +1 -0
  56. package/dist/commands/version/apply.js +120 -0
  57. package/dist/commands/version/apply.js.map +1 -0
  58. package/dist/commands/version/ci.d.ts +12 -0
  59. package/dist/commands/version/ci.d.ts.map +1 -0
  60. package/dist/commands/version/ci.js +67 -0
  61. package/dist/commands/version/ci.js.map +1 -0
  62. package/dist/commands/version/prepare.d.ts +19 -0
  63. package/dist/commands/version/prepare.d.ts.map +1 -0
  64. package/dist/commands/version/prepare.js +153 -0
  65. package/dist/commands/version/prepare.js.map +1 -0
  66. package/dist/core/colorify.d.ts +21 -0
  67. package/dist/core/colorify.d.ts.map +1 -0
  68. package/dist/core/colorify.js +56 -0
  69. package/dist/core/colorify.js.map +1 -0
  70. package/dist/core/index.d.ts +4 -0
  71. package/dist/core/index.d.ts.map +1 -0
  72. package/dist/core/index.js +3 -0
  73. package/dist/core/index.js.map +1 -0
  74. package/dist/core/types.d.ts +181 -0
  75. package/dist/core/types.d.ts.map +1 -0
  76. package/dist/core/types.js +5 -0
  77. package/dist/core/types.js.map +1 -0
  78. package/dist/core/wrapshell.d.ts +19 -0
  79. package/dist/core/wrapshell.d.ts.map +1 -0
  80. package/dist/core/wrapshell.js +323 -0
  81. package/dist/core/wrapshell.js.map +1 -0
  82. package/dist/entities/affected/affected.d.ts +4 -0
  83. package/dist/entities/affected/affected.d.ts.map +1 -0
  84. package/dist/entities/affected/affected.js +20 -0
  85. package/dist/entities/affected/affected.js.map +1 -0
  86. package/dist/entities/affected/affected.test.d.ts +2 -0
  87. package/dist/entities/affected/affected.test.d.ts.map +1 -0
  88. package/dist/entities/affected/affected.test.js +305 -0
  89. package/dist/entities/affected/affected.test.js.map +1 -0
  90. package/dist/entities/affected/index.d.ts +2 -0
  91. package/dist/entities/affected/index.d.ts.map +1 -0
  92. package/dist/entities/affected/index.js +2 -0
  93. package/dist/entities/affected/index.js.map +1 -0
  94. package/dist/entities/branch/branch.d.ts +8 -0
  95. package/dist/entities/branch/branch.d.ts.map +1 -0
  96. package/dist/entities/branch/branch.js +74 -0
  97. package/dist/entities/branch/branch.js.map +1 -0
  98. package/dist/entities/branch/branch.test.d.ts +2 -0
  99. package/dist/entities/branch/branch.test.d.ts.map +1 -0
  100. package/dist/entities/branch/branch.test.js +316 -0
  101. package/dist/entities/branch/branch.test.js.map +1 -0
  102. package/dist/entities/branch/branch.types.d.ts +6 -0
  103. package/dist/entities/branch/branch.types.d.ts.map +1 -0
  104. package/dist/entities/branch/branch.types.js +2 -0
  105. package/dist/entities/branch/branch.types.js.map +1 -0
  106. package/dist/entities/branch/index.d.ts +3 -0
  107. package/dist/entities/branch/index.d.ts.map +1 -0
  108. package/dist/entities/branch/index.js +3 -0
  109. package/dist/entities/branch/index.js.map +1 -0
  110. package/dist/entities/commit/commit.d.ts +15 -0
  111. package/dist/entities/commit/commit.d.ts.map +1 -0
  112. package/dist/entities/commit/commit.js +196 -0
  113. package/dist/entities/commit/commit.js.map +1 -0
  114. package/dist/entities/commit/commit.test.d.ts +26 -0
  115. package/dist/entities/commit/commit.test.d.ts.map +1 -0
  116. package/dist/entities/commit/commit.test.js +550 -0
  117. package/dist/entities/commit/commit.test.js.map +1 -0
  118. package/dist/entities/commit/commit.types.d.ts +49 -0
  119. package/dist/entities/commit/commit.types.d.ts.map +1 -0
  120. package/dist/entities/commit/commit.types.js +31 -0
  121. package/dist/entities/commit/commit.types.js.map +1 -0
  122. package/dist/entities/commit/index.d.ts +3 -0
  123. package/dist/entities/commit/index.d.ts.map +1 -0
  124. package/dist/entities/commit/index.js +3 -0
  125. package/dist/entities/commit/index.js.map +1 -0
  126. package/dist/entities/commit/pr.d.ts +11 -0
  127. package/dist/entities/commit/pr.d.ts.map +1 -0
  128. package/dist/entities/commit/pr.js +201 -0
  129. package/dist/entities/commit/pr.js.map +1 -0
  130. package/dist/entities/commit/pr.test.d.ts +2 -0
  131. package/dist/entities/commit/pr.test.d.ts.map +1 -0
  132. package/dist/entities/commit/pr.test.js +782 -0
  133. package/dist/entities/commit/pr.test.js.map +1 -0
  134. package/dist/entities/compose/compose.d.ts +18 -0
  135. package/dist/entities/compose/compose.d.ts.map +1 -0
  136. package/dist/entities/compose/compose.js +197 -0
  137. package/dist/entities/compose/compose.js.map +1 -0
  138. package/dist/entities/compose/compose.test.d.ts +2 -0
  139. package/dist/entities/compose/compose.test.d.ts.map +1 -0
  140. package/dist/entities/compose/compose.test.js +406 -0
  141. package/dist/entities/compose/compose.test.js.map +1 -0
  142. package/dist/entities/compose/compose.types.d.ts +77 -0
  143. package/dist/entities/compose/compose.types.d.ts.map +1 -0
  144. package/dist/entities/compose/compose.types.js +2 -0
  145. package/dist/entities/compose/compose.types.js.map +1 -0
  146. package/dist/entities/compose/index.d.ts +3 -0
  147. package/dist/entities/compose/index.d.ts.map +1 -0
  148. package/dist/entities/compose/index.js +3 -0
  149. package/dist/entities/compose/index.js.map +1 -0
  150. package/dist/entities/entities.shell.d.ts +29 -0
  151. package/dist/entities/entities.shell.d.ts.map +1 -0
  152. package/dist/entities/entities.shell.js +27 -0
  153. package/dist/entities/entities.shell.js.map +1 -0
  154. package/dist/entities/entities.shell.test.d.ts +2 -0
  155. package/dist/entities/entities.shell.test.d.ts.map +1 -0
  156. package/dist/entities/entities.shell.test.js +23 -0
  157. package/dist/entities/entities.shell.test.js.map +1 -0
  158. package/dist/entities/index.d.ts +12 -0
  159. package/dist/entities/index.d.ts.map +1 -0
  160. package/dist/entities/index.js +12 -0
  161. package/dist/entities/index.js.map +1 -0
  162. package/dist/entities/intershell-config/intershell-config.d.ts +11 -0
  163. package/dist/entities/intershell-config/intershell-config.d.ts.map +1 -0
  164. package/dist/entities/intershell-config/intershell-config.default.d.ts +188 -0
  165. package/dist/entities/intershell-config/intershell-config.default.d.ts.map +1 -0
  166. package/dist/entities/intershell-config/intershell-config.default.js +225 -0
  167. package/dist/entities/intershell-config/intershell-config.default.js.map +1 -0
  168. package/dist/entities/intershell-config/intershell-config.js +132 -0
  169. package/dist/entities/intershell-config/intershell-config.js.map +1 -0
  170. package/dist/entities/intershell-config/intershell-config.test.d.ts +2 -0
  171. package/dist/entities/intershell-config/intershell-config.test.d.ts.map +1 -0
  172. package/dist/entities/intershell-config/intershell-config.test.js +102 -0
  173. package/dist/entities/intershell-config/intershell-config.test.js.map +1 -0
  174. package/dist/entities/intershell-config/intershell-config.types.d.ts +103 -0
  175. package/dist/entities/intershell-config/intershell-config.types.d.ts.map +1 -0
  176. package/dist/entities/intershell-config/intershell-config.types.js +2 -0
  177. package/dist/entities/intershell-config/intershell-config.types.js.map +1 -0
  178. package/dist/entities/package/index.d.ts +4 -0
  179. package/dist/entities/package/index.d.ts.map +1 -0
  180. package/dist/entities/package/index.js +4 -0
  181. package/dist/entities/package/index.js.map +1 -0
  182. package/dist/entities/package/package.d.ts +49 -0
  183. package/dist/entities/package/package.d.ts.map +1 -0
  184. package/dist/entities/package/package.js +234 -0
  185. package/dist/entities/package/package.js.map +1 -0
  186. package/dist/entities/package/package.shell.d.ts +48 -0
  187. package/dist/entities/package/package.shell.d.ts.map +1 -0
  188. package/dist/entities/package/package.shell.js +118 -0
  189. package/dist/entities/package/package.shell.js.map +1 -0
  190. package/dist/entities/package/package.test.d.ts +23 -0
  191. package/dist/entities/package/package.test.d.ts.map +1 -0
  192. package/dist/entities/package/package.test.js +637 -0
  193. package/dist/entities/package/package.test.js.map +1 -0
  194. package/dist/entities/package/package.types.d.ts +48 -0
  195. package/dist/entities/package/package.types.d.ts.map +1 -0
  196. package/dist/entities/package/package.types.js +2 -0
  197. package/dist/entities/package/package.types.js.map +1 -0
  198. package/dist/entities/package-changelog/index.d.ts +4 -0
  199. package/dist/entities/package-changelog/index.d.ts.map +1 -0
  200. package/dist/entities/package-changelog/index.js +4 -0
  201. package/dist/entities/package-changelog/index.js.map +1 -0
  202. package/dist/entities/package-changelog/package-changelog.d.ts +20 -0
  203. package/dist/entities/package-changelog/package-changelog.d.ts.map +1 -0
  204. package/dist/entities/package-changelog/package-changelog.js +59 -0
  205. package/dist/entities/package-changelog/package-changelog.js.map +1 -0
  206. package/dist/entities/package-changelog/package-changelog.types.d.ts +25 -0
  207. package/dist/entities/package-changelog/package-changelog.types.d.ts.map +1 -0
  208. package/dist/entities/package-changelog/package-changelog.types.js +2 -0
  209. package/dist/entities/package-changelog/package-changelog.types.js.map +1 -0
  210. package/dist/entities/package-changelog/template.d.ts +20 -0
  211. package/dist/entities/package-changelog/template.d.ts.map +1 -0
  212. package/dist/entities/package-changelog/template.default.d.ts +10 -0
  213. package/dist/entities/package-changelog/template.default.d.ts.map +1 -0
  214. package/dist/entities/package-changelog/template.default.js +85 -0
  215. package/dist/entities/package-changelog/template.default.js.map +1 -0
  216. package/dist/entities/package-changelog/template.js +90 -0
  217. package/dist/entities/package-changelog/template.js.map +1 -0
  218. package/dist/entities/package-commits/dependency-analyzer.d.ts +35 -0
  219. package/dist/entities/package-commits/dependency-analyzer.d.ts.map +1 -0
  220. package/dist/entities/package-commits/dependency-analyzer.js +169 -0
  221. package/dist/entities/package-commits/dependency-analyzer.js.map +1 -0
  222. package/dist/entities/package-commits/dependency-analyzer.test.d.ts +2 -0
  223. package/dist/entities/package-commits/dependency-analyzer.test.d.ts.map +1 -0
  224. package/dist/entities/package-commits/dependency-analyzer.test.js +25 -0
  225. package/dist/entities/package-commits/dependency-analyzer.test.js.map +1 -0
  226. package/dist/entities/package-commits/index.d.ts +3 -0
  227. package/dist/entities/package-commits/index.d.ts.map +1 -0
  228. package/dist/entities/package-commits/index.js +3 -0
  229. package/dist/entities/package-commits/index.js.map +1 -0
  230. package/dist/entities/package-commits/package-commits.d.ts +33 -0
  231. package/dist/entities/package-commits/package-commits.d.ts.map +1 -0
  232. package/dist/entities/package-commits/package-commits.js +149 -0
  233. package/dist/entities/package-commits/package-commits.js.map +1 -0
  234. package/dist/entities/package-commits/package-commits.test.d.ts +2 -0
  235. package/dist/entities/package-commits/package-commits.test.d.ts.map +1 -0
  236. package/dist/entities/package-commits/package-commits.test.js +40 -0
  237. package/dist/entities/package-commits/package-commits.test.js.map +1 -0
  238. package/dist/entities/package-tags/index.d.ts +2 -0
  239. package/dist/entities/package-tags/index.d.ts.map +1 -0
  240. package/dist/entities/package-tags/index.js +2 -0
  241. package/dist/entities/package-tags/index.js.map +1 -0
  242. package/dist/entities/package-tags/package-tags.d.ts +24 -0
  243. package/dist/entities/package-tags/package-tags.d.ts.map +1 -0
  244. package/dist/entities/package-tags/package-tags.js +197 -0
  245. package/dist/entities/package-tags/package-tags.js.map +1 -0
  246. package/dist/entities/package-tags/package-tags.test.d.ts +2 -0
  247. package/dist/entities/package-tags/package-tags.test.d.ts.map +1 -0
  248. package/dist/entities/package-tags/package-tags.test.js +60 -0
  249. package/dist/entities/package-tags/package-tags.test.js.map +1 -0
  250. package/dist/entities/package-version/index.d.ts +3 -0
  251. package/dist/entities/package-version/index.d.ts.map +1 -0
  252. package/dist/entities/package-version/index.js +3 -0
  253. package/dist/entities/package-version/index.js.map +1 -0
  254. package/dist/entities/package-version/package-version.d.ts +16 -0
  255. package/dist/entities/package-version/package-version.d.ts.map +1 -0
  256. package/dist/entities/package-version/package-version.js +166 -0
  257. package/dist/entities/package-version/package-version.js.map +1 -0
  258. package/dist/entities/package-version/package-version.test.d.ts +2 -0
  259. package/dist/entities/package-version/package-version.test.d.ts.map +1 -0
  260. package/dist/entities/package-version/package-version.test.js +113 -0
  261. package/dist/entities/package-version/package-version.test.js.map +1 -0
  262. package/dist/entities/package-version/package-version.types.d.ts +31 -0
  263. package/dist/entities/package-version/package-version.types.d.ts.map +1 -0
  264. package/dist/entities/package-version/package-version.types.js +2 -0
  265. package/dist/entities/package-version/package-version.types.js.map +1 -0
  266. package/dist/entities/tag/index.d.ts +3 -0
  267. package/dist/entities/tag/index.d.ts.map +1 -0
  268. package/dist/entities/tag/index.js +3 -0
  269. package/dist/entities/tag/index.js.map +1 -0
  270. package/dist/entities/tag/tag.d.ts +24 -0
  271. package/dist/entities/tag/tag.d.ts.map +1 -0
  272. package/dist/entities/tag/tag.js +168 -0
  273. package/dist/entities/tag/tag.js.map +1 -0
  274. package/dist/entities/tag/tag.test.d.ts +2 -0
  275. package/dist/entities/tag/tag.test.d.ts.map +1 -0
  276. package/dist/entities/tag/tag.test.js +638 -0
  277. package/dist/entities/tag/tag.test.js.map +1 -0
  278. package/dist/entities/tag/tag.types.d.ts +35 -0
  279. package/dist/entities/tag/tag.types.d.ts.map +1 -0
  280. package/dist/entities/tag/tag.types.js +2 -0
  281. package/dist/entities/tag/tag.types.js.map +1 -0
  282. package/dist/index.d.ts +3 -0
  283. package/dist/index.d.ts.map +1 -0
  284. package/dist/index.js +6 -0
  285. package/dist/index.js.map +1 -0
  286. package/package.json +73 -0
  287. package/src/commands/ci/act.ts +95 -0
  288. package/src/commands/ci/attach-affected.ts +93 -0
  289. package/src/commands/ci/attach-service-ports.ts +31 -0
  290. package/src/commands/commit-check.ts +124 -0
  291. package/src/commands/commit.ts +103 -0
  292. package/src/commands/dev/check.ts +117 -0
  293. package/src/commands/dev/cleanup.ts +34 -0
  294. package/src/commands/dev/rm.ts +66 -0
  295. package/src/commands/dev/setup.ts +48 -0
  296. package/src/commands/local/cleanup.ts +74 -0
  297. package/src/commands/local/setup.ts +68 -0
  298. package/src/commands/local/vscode.ts +118 -0
  299. package/src/commands/update-package-json.ts +104 -0
  300. package/src/commands/version/apply.ts +156 -0
  301. package/src/commands/version/ci.ts +85 -0
  302. package/src/commands/version/prepare.ts +217 -0
  303. package/src/core/colorify.ts +61 -0
  304. package/src/core/index.ts +3 -0
  305. package/src/core/types.ts +262 -0
  306. package/src/core/wrapshell.ts +388 -0
  307. package/src/entities/affected/affected.test.ts +427 -0
  308. package/src/entities/affected/affected.ts +22 -0
  309. package/src/entities/affected/index.ts +1 -0
  310. package/src/entities/branch/branch.test.ts +348 -0
  311. package/src/entities/branch/branch.ts +89 -0
  312. package/src/entities/branch/branch.types.ts +5 -0
  313. package/src/entities/branch/index.ts +2 -0
  314. package/src/entities/commit/commit.test.ts +769 -0
  315. package/src/entities/commit/commit.ts +245 -0
  316. package/src/entities/commit/commit.types.ts +81 -0
  317. package/src/entities/commit/index.ts +2 -0
  318. package/src/entities/commit/pr.test.ts +860 -0
  319. package/src/entities/commit/pr.ts +241 -0
  320. package/src/entities/compose/compose.test.ts +496 -0
  321. package/src/entities/compose/compose.ts +251 -0
  322. package/src/entities/compose/compose.types.ts +88 -0
  323. package/src/entities/compose/index.ts +2 -0
  324. package/src/entities/entities.shell.test.ts +35 -0
  325. package/src/entities/entities.shell.ts +81 -0
  326. package/src/entities/index.ts +11 -0
  327. package/src/entities/intershell-config/intershell-config.default.ts +229 -0
  328. package/src/entities/intershell-config/intershell-config.test.ts +117 -0
  329. package/src/entities/intershell-config/intershell-config.ts +143 -0
  330. package/src/entities/intershell-config/intershell-config.types.ts +118 -0
  331. package/src/entities/package/index.ts +3 -0
  332. package/src/entities/package/package.shell.ts +124 -0
  333. package/src/entities/package/package.test.ts +830 -0
  334. package/src/entities/package/package.ts +267 -0
  335. package/src/entities/package/package.types.ts +49 -0
  336. package/src/entities/package-changelog/index.ts +3 -0
  337. package/src/entities/package-changelog/package-changelog.ts +81 -0
  338. package/src/entities/package-changelog/package-changelog.types.ts +30 -0
  339. package/src/entities/package-changelog/template.default.ts +109 -0
  340. package/src/entities/package-changelog/template.ts +118 -0
  341. package/src/entities/package-commits/dependency-analyzer.test.ts +29 -0
  342. package/src/entities/package-commits/dependency-analyzer.ts +194 -0
  343. package/src/entities/package-commits/index.ts +2 -0
  344. package/src/entities/package-commits/package-commits.test.ts +44 -0
  345. package/src/entities/package-commits/package-commits.ts +191 -0
  346. package/src/entities/package-tags/index.ts +1 -0
  347. package/src/entities/package-tags/package-tags.test.ts +73 -0
  348. package/src/entities/package-tags/package-tags.ts +234 -0
  349. package/src/entities/package-version/index.ts +2 -0
  350. package/src/entities/package-version/package-version.test.ts +141 -0
  351. package/src/entities/package-version/package-version.ts +234 -0
  352. package/src/entities/package-version/package-version.types.ts +35 -0
  353. package/src/entities/tag/index.ts +2 -0
  354. package/src/entities/tag/tag.test.ts +844 -0
  355. package/src/entities/tag/tag.ts +208 -0
  356. package/src/entities/tag/tag.types.ts +37 -0
  357. package/src/index.ts +7 -0
@@ -0,0 +1,348 @@
1
+ import { beforeEach, describe, expect, it, mock } from "bun:test";
2
+ import type { $ } from "bun";
3
+ import type { IConfig } from "../intershell-config/intershell-config.types";
4
+ import { EntityBranch } from "./branch";
5
+ import type { ParsedBranch } from "./branch.types";
6
+
7
+ // Mock the entitiesConfig module
8
+ const mockEntitiesConfig = {
9
+ getConfig: mock(() => ({
10
+ branch: {
11
+ defaultBranch: "main",
12
+ prefixes: ["feature", "bugfix", "hotfix"],
13
+ name: {
14
+ minLength: 3,
15
+ maxLength: 50,
16
+ allowedCharacters: /^[a-zA-Z0-9\-_/]+$/,
17
+ noConsecutiveSeparators: true,
18
+ noLeadingTrailingSeparators: true,
19
+ },
20
+ },
21
+ })),
22
+ };
23
+
24
+ // Mock the config module
25
+ mock.module("../config/config", () => ({
26
+ entitiesConfig: mockEntitiesConfig,
27
+ }));
28
+
29
+ type BranchConfig = IConfig["branch"];
30
+
31
+ describe.skip("EntityBranch", () => {
32
+ let branch: InstanceType<typeof EntityBranch>;
33
+ let mockConfig: BranchConfig;
34
+
35
+ beforeEach(() => {
36
+ mockConfig = {
37
+ defaultBranch: "main",
38
+ prefixes: ["feature", "bugfix", "hotfix"],
39
+ name: {
40
+ minLength: 3,
41
+ maxLength: 50,
42
+ allowedCharacters: /^[a-zA-Z0-9\-_/]+$/,
43
+ noConsecutiveSeparators: true,
44
+ noLeadingTrailingSeparators: true,
45
+ },
46
+ };
47
+
48
+ // Set up the mock config
49
+ mockEntitiesConfig.getConfig.mockReturnValue({
50
+ branch: mockConfig,
51
+ });
52
+
53
+ branch = new EntityBranch();
54
+ });
55
+
56
+ describe("static parseByName", () => {
57
+ const parseTestCases = [
58
+ {
59
+ name: "should parse branch name with prefix and name",
60
+ input: "feature/user-authentication",
61
+ expected: {
62
+ prefix: "feature",
63
+ name: "feature/user-authentication",
64
+ fullName: "feature/user-authentication",
65
+ },
66
+ },
67
+ {
68
+ name: "should parse branch name with multiple slashes",
69
+ input: "feature/auth/user-authentication",
70
+ expected: {
71
+ prefix: "feature",
72
+ name: "feature/auth/user-authentication",
73
+ fullName: "feature/auth/user-authentication",
74
+ },
75
+ },
76
+ {
77
+ name: "should parse branch name with only prefix",
78
+ input: "feature",
79
+ expected: {
80
+ prefix: "feature",
81
+ name: "feature",
82
+ fullName: "feature",
83
+ },
84
+ },
85
+ {
86
+ name: "should parse branch name with no slashes",
87
+ input: "main",
88
+ expected: {
89
+ prefix: undefined,
90
+ name: "main",
91
+ fullName: "main",
92
+ },
93
+ },
94
+ {
95
+ name: "should handle empty string",
96
+ input: "",
97
+ expected: {
98
+ prefix: undefined,
99
+ name: "",
100
+ fullName: "",
101
+ },
102
+ },
103
+ ];
104
+
105
+ parseTestCases.forEach(({ name, input, expected }) => {
106
+ it(name, () => {
107
+ const result = new EntityBranch().parseByName(input);
108
+ expect(result).toEqual(expected);
109
+ });
110
+ });
111
+ });
112
+
113
+ describe("getCurrentBranch", () => {
114
+ // keep the trailing space to test the trim() function
115
+ const mockCurrentBranch = "test-branch ";
116
+
117
+ beforeEach(async () => {
118
+ // Import and mock entitiesShell methods directly
119
+ const { entitiesShell } = await import("../entities.shell");
120
+
121
+ // Mock gitBranchShowCurrent directly
122
+ entitiesShell.gitBranchShowCurrent = mock(
123
+ () =>
124
+ ({
125
+ exitCode: 0,
126
+ text: () => mockCurrentBranch,
127
+ }) as unknown as $.ShellPromise,
128
+ );
129
+ });
130
+
131
+ it("should handle git command and return trimmed output", async () => {
132
+ const result = await branch.getCurrentBranch();
133
+ expect(result).toBe(mockCurrentBranch.trim());
134
+ });
135
+ });
136
+
137
+ describe("validate", () => {
138
+ describe("with string input", () => {
139
+ const stringInputTests = [
140
+ {
141
+ name: "should validate valid branch name",
142
+ input: "feature/user-auth",
143
+ expected: true as const,
144
+ },
145
+ {
146
+ name: "should validate default branch",
147
+ input: "main",
148
+ expected: true as const,
149
+ },
150
+ {
151
+ name: "should validate branch without prefixes when prefixes array is empty",
152
+ input: "any-branch-name",
153
+ setup: () => {
154
+ mockEntitiesConfig.getConfig.mockReturnValue({
155
+ branch: {
156
+ ...mockConfig,
157
+ prefixes: [] as string[],
158
+ },
159
+ } as IConfig);
160
+ return new EntityBranch();
161
+ },
162
+ expected: true as const,
163
+ },
164
+ ];
165
+
166
+ stringInputTests.forEach(({ name, input, setup, expected }) => {
167
+ it(name, () => {
168
+ const testBranch = setup ? setup() : branch;
169
+ const result = testBranch.validate(input);
170
+ expect(result).toBe(expected);
171
+ });
172
+ });
173
+ });
174
+
175
+ describe("with ParsedBranch input", () => {
176
+ const parsedBranchTests = [
177
+ {
178
+ name: "should validate valid parsed branch",
179
+ input: {
180
+ prefix: "feature",
181
+ name: "user-auth",
182
+ fullName: "feature/user-auth",
183
+ } as ParsedBranch,
184
+ expected: true as const,
185
+ },
186
+ {
187
+ name: "should validate default branch when parsed",
188
+ input: {
189
+ prefix: "main",
190
+ name: "",
191
+ fullName: "main",
192
+ } as ParsedBranch,
193
+ expected: true as const,
194
+ },
195
+ ];
196
+
197
+ parsedBranchTests.forEach(({ name, input, expected }) => {
198
+ it(name, () => {
199
+ const result = branch.validate(input);
200
+ expect(result).toBe(expected);
201
+ });
202
+ });
203
+ });
204
+
205
+ describe("validation rules", () => {
206
+ const validationRuleTests = [
207
+ {
208
+ name: "should reject empty branch name",
209
+ input: "",
210
+ expected: "branch name is empty",
211
+ },
212
+ {
213
+ name: "should reject branch name shorter than minLength",
214
+ input: "ab",
215
+ expected: "branch name should be at least 3 characters long",
216
+ },
217
+ {
218
+ name: "should reject branch name longer than maxLength",
219
+ input: "a".repeat(51),
220
+ expected: "branch name should be max 50 characters, received: 51",
221
+ },
222
+ {
223
+ name: "should reject branch name with invalid characters",
224
+ input: "feature/user@auth",
225
+ expected:
226
+ "branch name can only contain letters, numbers, hyphens, underscores, and forward slashes",
227
+ },
228
+ {
229
+ name: "should reject branch name with consecutive separators",
230
+ input: "feature--user-auth",
231
+ expected: "branch name should not have consecutive separators",
232
+ },
233
+ {
234
+ name: "should reject branch name with leading separator",
235
+ input: "-feature/user-auth",
236
+ expected: "branch name should not start or end with separators",
237
+ },
238
+ {
239
+ name: "should reject branch name with trailing separator",
240
+ input: "feature/user-auth-",
241
+ expected: "branch name should not start or end with separators",
242
+ },
243
+ {
244
+ name: "should reject branch name without prefix when prefixes are required",
245
+ input: "user-auth",
246
+ expected: "branch name should have a prefix. valid prefixes: feature, bugfix, hotfix",
247
+ },
248
+ {
249
+ name: "should accept branch name with only prefix",
250
+ input: "feature",
251
+ expected: true as const,
252
+ },
253
+ ];
254
+
255
+ validationRuleTests.forEach(({ name, input, expected }) => {
256
+ it(name, () => {
257
+ const result = branch.validate(input);
258
+ expect(result).toBe(expected);
259
+ });
260
+ });
261
+ });
262
+
263
+ describe("edge cases", () => {
264
+ const edgeCaseTests = [
265
+ {
266
+ name: "should handle branch names with only separators",
267
+ input: "---",
268
+ expected: "branch name should not have consecutive separators",
269
+ },
270
+ {
271
+ name: "should handle branch names with mixed separators",
272
+ input: "feature_-user",
273
+ expected: "branch name should not have consecutive separators",
274
+ },
275
+ {
276
+ name: "should handle very long branch names",
277
+ input: "a".repeat(100),
278
+ expected: "branch name should be max 50 characters, received: 100",
279
+ },
280
+ {
281
+ name: "should handle branch names with special characters",
282
+ input: "feature/user#auth",
283
+ expected:
284
+ "branch name can only contain letters, numbers, hyphens, underscores, and forward slashes",
285
+ },
286
+ ];
287
+
288
+ edgeCaseTests.forEach(({ name, input, expected }) => {
289
+ it(name, () => {
290
+ const result = branch.validate(input);
291
+ expect(result).toBe(expected);
292
+ });
293
+ });
294
+ });
295
+ });
296
+
297
+ describe("constructor and configuration", () => {
298
+ it("should create instance with provided config", () => {
299
+ expect(branch).toBeInstanceOf(EntityBranch);
300
+ });
301
+
302
+ const configTests = [
303
+ {
304
+ name: "should handle config with no length restrictions",
305
+ setup: () => {
306
+ mockEntitiesConfig.getConfig.mockReturnValue({
307
+ branch: {
308
+ ...mockConfig,
309
+ name: {
310
+ ...mockConfig.name,
311
+ minLength: 0,
312
+ maxLength: 0,
313
+ },
314
+ },
315
+ } as IConfig);
316
+ return new EntityBranch();
317
+ },
318
+ input: "a",
319
+ expected: "branch name should have a prefix. valid prefixes: feature, bugfix, hotfix",
320
+ },
321
+ {
322
+ name: "should handle config with no character restrictions",
323
+ setup: () => {
324
+ mockEntitiesConfig.getConfig.mockReturnValue({
325
+ branch: {
326
+ ...mockConfig,
327
+ name: {
328
+ ...mockConfig.name,
329
+ allowedCharacters: /.*/,
330
+ },
331
+ },
332
+ } as IConfig);
333
+ return new EntityBranch();
334
+ },
335
+ input: "feature/user@auth",
336
+ expected: true as const,
337
+ },
338
+ ];
339
+
340
+ configTests.forEach(({ name, setup, input, expected }) => {
341
+ it(name, () => {
342
+ const testBranch = setup();
343
+ const result = testBranch.validate(input);
344
+ expect(result).toBe(expected);
345
+ });
346
+ });
347
+ });
348
+ });
@@ -0,0 +1,89 @@
1
+ import { entitiesShell } from "../entities.shell";
2
+ import { entitiesConfig } from "../intershell-config/intershell-config";
3
+ import type { ParsedBranch } from "./branch.types";
4
+
5
+ export class EntityBranch {
6
+ parseByName(branchName: string): ParsedBranch {
7
+ const config = entitiesConfig.getConfig().branch;
8
+ const validPrefixes = config.prefixes;
9
+
10
+ // Split the branch name by "/" to get all parts
11
+ const parts = branchName.split("/");
12
+
13
+ // Find the first valid prefix in the parts
14
+ let foundPrefixIndex = -1;
15
+ let foundPrefix = "";
16
+
17
+ for (let i = 0; i < parts.length; i++) {
18
+ if (validPrefixes.includes(parts[i])) {
19
+ foundPrefixIndex = i;
20
+ foundPrefix = parts[i];
21
+ break;
22
+ }
23
+ }
24
+
25
+ // If we found a valid prefix, use everything from that point as the name
26
+ if (foundPrefixIndex !== -1) {
27
+ const nameParts = parts.slice(foundPrefixIndex);
28
+ return {
29
+ prefix: foundPrefix,
30
+ name: nameParts.join("/"),
31
+ fullName: branchName,
32
+ };
33
+ }
34
+
35
+ // If no valid prefix found, use the entire name
36
+ return {
37
+ prefix: undefined,
38
+ name: branchName,
39
+ fullName: branchName,
40
+ };
41
+ }
42
+
43
+ async getCurrentBranch(): Promise<string> {
44
+ const result = await entitiesShell.gitBranchShowCurrent();
45
+ return result.text().trim();
46
+ }
47
+
48
+ validate(input: string | ParsedBranch): true | string {
49
+ const branch = typeof input === "string" ? this.parseByName(input) : input;
50
+
51
+ return this.mainValidator(branch);
52
+ }
53
+
54
+ private mainValidator(branch: ParsedBranch): true | string {
55
+ const config = entitiesConfig.getConfig().branch;
56
+
57
+ if (!branch.fullName) return "branch name is empty";
58
+ if (config.name.minLength && branch.fullName.length < config.name.minLength)
59
+ return `branch name should be at least ${config.name.minLength} characters long`;
60
+ if (config.name.maxLength && branch.fullName.length > config.name.maxLength)
61
+ return `branch name should be max ${config.name.maxLength} characters, received: ${branch.fullName.length}`;
62
+ if (config.name.allowedCharacters && !config.name.allowedCharacters.test(branch.fullName))
63
+ return "branch name can only contain letters, numbers, hyphens, underscores, and forward slashes";
64
+ if (config.name.noConsecutiveSeparators && /[-_/]{2,}/.test(branch.fullName))
65
+ return "branch name should not have consecutive separators";
66
+ if (config.name.noLeadingTrailingSeparators && /(^[-_/]|[-_/]$)/.test(branch.fullName))
67
+ return "branch name should not start or end with separators";
68
+
69
+ if (branch.fullName === config.defaultBranch) {
70
+ return true;
71
+ }
72
+
73
+ if (config.prefixes.length === 0) {
74
+ return true;
75
+ }
76
+
77
+ const prefix = branch.prefix ?? "";
78
+ const name = branch.name;
79
+ if (!prefix) {
80
+ return `branch name should have a prefix. valid prefixes: ${config.prefixes.join(", ")}`;
81
+ }
82
+
83
+ if (!name) {
84
+ return "branch name should have a name";
85
+ }
86
+
87
+ return true;
88
+ }
89
+ }
@@ -0,0 +1,5 @@
1
+ export interface ParsedBranch {
2
+ readonly name: string;
3
+ readonly prefix?: string;
4
+ readonly fullName: string;
5
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./branch";
2
+ export * from "./branch.types";