gen-release-notes.js 6.2 KB

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