gen-release-notes.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. // METADATA // {"ai-commented":{"service":"claude"}}
  2. /*
  3. * Copyright (C) 2024 Puter Technologies Inc.
  4. *
  5. * This file is part of Puter.
  6. *
  7. * Puter is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published
  9. * by the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  19. */
  20. import { simpleGit } from 'simple-git';
  21. // GitHub repository URL for generating commit links in release notes
  22. const REPO_URL = 'https://github.com/HeyPuter/puter';
  23. const params = {
  24. from: 'v2.4.1',
  25. // from: 'v2.4.0',
  26. to: 'v2.4.2',
  27. date: '2024-07-22',
  28. };
  29. const git = simpleGit();
  30. const log = await git.log({ from: params.from });
  31. const commits = log.all;
  32. // Array of all commits from git log between specified versions
  33. const CC_REGEX = /^([a-z0-9]+)(\([a-z0-9]+\))?:\s(.*)/;
  34. const parse_conventional_commit = message => {
  35. const parts = CC_REGEX.exec(message);
  36. if ( ! parts ) return null;
  37. let [match, type, scope, summary] = parts;
  38. if ( ! match ) return null;
  39. if ( scope ) scope = scope.slice(1, -1);
  40. return { type, scope, summary };
  41. };
  42. const types = {
  43. feat: {
  44. label: 'Features'
  45. },
  46. i18n: {
  47. label: 'Translations'
  48. },
  49. fix: {
  50. label: 'Bug Fixes'
  51. },
  52. };
  53. const scopes = {
  54. puter: {
  55. label: 'Puter'
  56. },
  57. phoenix: {
  58. label: 'Phoenix Shell'
  59. },
  60. git: {
  61. label: 'Puter Git'
  62. },
  63. backend: {
  64. label: 'Backend'
  65. },
  66. gui: {
  67. label: 'GUI'
  68. },
  69. tools: {
  70. ignore: true,
  71. },
  72. security: {
  73. label: 'Security',
  74. },
  75. };
  76. const scope_aliases = {
  77. main: 'puter',
  78. ui: 'gui',
  79. parsely: 'phoenix',
  80. };
  81. const complicated_cases = [
  82. /**
  83. * Handles special cases for commit message transformations
  84. * @type {Array<function>}
  85. */
  86. function fix_i18n ({ commit, meta }) {
  87. if ( meta.type === 'fix' && meta.scope === 'i18n' ) {
  88. meta.type = 'i18n';
  89. meta.scope = undefined;
  90. }
  91. }
  92. ];
  93. const retro_prefixes_0 = {
  94. i18n: [
  95. '883601142873f10d69c84874499065a7d29af054',
  96. '17145d0be6a9a1445947cc0c4bec8f16a475144c',
  97. 'e61039faf409b0ad85c7513b0123f3f2e92ebe32',
  98. 'bffa192805216fc17045cd8d629f34784dca7f3f',
  99. 'fe5be7f3cf7f336730137293ba86a637e8d8591d',
  100. '78a0acea6980b6d491da4874edbd98e17c0d9577',
  101. 'a96abb5793528d0dc56d75f95d771e1dcf5960d1',
  102. 'f5a8ee1c6ab950d62c90b6257791f026a508b4e4',
  103. '47ec74f0aa6adb3952e6460909029a4acb0c3039',
  104. '473b6512c697854e3f3badae1eb7b87742954da5',
  105. '8440f566b91c9eb4f01addcb850061e3fbe3afc7',
  106. '92abc9947f811f94f17a5ee5a4b73ee2b210900a',
  107. 'cff488f4f4378ca6c7568a585a665f2a3b87b89c',
  108. '3b8af7cc5c1be8ed67be827360bbfe0f0b5027e9',
  109. '84e31eff2f58584d8fab7dd10606f2f6ced933a2',
  110. '81781f80afc07cd1e6278906cdc68c8092fbfedf',
  111. '56820cf6ee56ff810a6b495a281ccbb2e7f9d8fb',
  112. '69a80ab3d2c94ee43d96021c3bcbdab04a4b5dc6',
  113. '8e297cd7e30757073e2f96593c363a273b639466',
  114. '151527825f1eb4b060aaf97feb7d18af4fcddbf2',
  115. '8bece96f6224a060d5b408e08c58865fadb8b79c',
  116. '333d6e3b651e460caca04a896cbc8c175555b79b',
  117. '8a3d0430f39f872b8a460c344cce652c340b700b',
  118. 'b9e73b7288aebb14e6bbf1915743e9157fc950b1',
  119. 'c2d3d69dbe33f36fcae13bcbc8e2a31a86025af9',
  120. '382fb24dbb1737a8a54ed2491f80b2e2276cde61',
  121. ],
  122. fix: [
  123. '535475b3c36a37e3319ed067a24fb671790dcda3',
  124. '45f131f8eaf94cf3951ca7ffeb6f311590233b8a',
  125. '02e1b1e8f5f8e22d7ab39ebff99f7dd8e08a4221',
  126. ],
  127. doc: [
  128. '338004474f078a00608af1d0ebf8a7f9534bad28',
  129. '6c4c73a9e85ff8eb5e7663dcce11f4d1f824032b',
  130. 'c19c18bfcf163b37e3d173b8fa50393dfb9f540f',
  131. ],
  132. feat: [
  133. '8e7306c23be01ee6c31cdb4c99f2fb1f71a2247f',
  134. ],
  135. meta: [
  136. 'b3c1b128e2d8519bc816cdcd3220c8f40e05bb01',
  137. '452b7495b1736df90bc748dbf818407488875754',
  138. ],
  139. };
  140. const message_changes = {
  141. '1f7f094282fae915a2436701cfb756444cd3f781': 'feat: add new file templates',
  142. '64e4299ac0a4c9e1de7a9d089e2d7529a9530818': 'doc: docker instructions for Windows',
  143. 'f897e844989083b0b369ba0ce4d2c5a9f3db5ad8': 'fix: #432',
  144. };
  145. const retro_prefixes = {};
  146. for ( const prefix in retro_prefixes_0 ) {
  147. for ( const commit_hash of retro_prefixes_0[prefix] ) {
  148. console.log('PREFIX', commit_hash, prefix);
  149. retro_prefixes[commit_hash] = prefix;
  150. }
  151. }
  152. const data = {};
  153. const ensure_scope = name => {
  154. if ( data[name] ) return;
  155. const o = data[name] = {};
  156. for ( const k in types ) o[k] = [];
  157. };
  158. for ( const commit of commits ) {
  159. if ( message_changes.hasOwnProperty(commit.hash) ) {
  160. commit.message = message_changes[commit.hash];
  161. }
  162. if ( retro_prefixes.hasOwnProperty(commit.hash) ) {
  163. commit.message = retro_prefixes[commit.hash] + ': ' +
  164. commit.message;
  165. }
  166. const meta = parse_conventional_commit(commit.message);
  167. if ( ! meta ) continue;
  168. for ( const transformer of complicated_cases ) {
  169. transformer({ commit, meta });
  170. }
  171. let scope = meta.scope ?? 'puter';
  172. while ( scope in scope_aliases ) {
  173. scope = scope_aliases[scope];
  174. }
  175. if ( ! scopes[scope] ) {
  176. console.log(commit);
  177. throw new Error(`missing scope: ${scope}`);
  178. }
  179. if ( scopes[scope].ignore ) continue;
  180. ensure_scope(scope);
  181. if ( types.hasOwnProperty(meta.type) ) {
  182. data[scope][meta.type].push({ meta, commit });
  183. }
  184. }
  185. let s = '';
  186. s += `## ${params.to} (${params.date})\n\n`;
  187. for ( const scope_name in data ) {
  188. const scope = data[scope_name];
  189. s += `### ${scopes[scope_name].label}\n\n`;
  190. for ( const type_name in types ) {
  191. const type = types[type_name];
  192. const items = scope[type_name];
  193. if ( items.length == 0 ) continue;
  194. s += `\n#### ${type.label}\n\n`;
  195. for ( const { meta, commit } of items ) {
  196. const shorthash = commit.hash.slice(0,7)
  197. s += `- ${meta.summary} ([${shorthash}](${REPO_URL}/commit/${commit.hash}))\n`;
  198. }
  199. }
  200. }
  201. console.log(s);