@lbdudc/linea-git 0.0.0-stage → 0.1.1

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 (152) hide show
  1. package/README.md +47 -2
  2. package/dist/access.d.ts +18 -0
  3. package/dist/access.js +18 -0
  4. package/dist/access.js.map +1 -0
  5. package/dist/auth.d.ts +11 -0
  6. package/dist/auth.js +16 -0
  7. package/dist/auth.js.map +1 -0
  8. package/dist/changelog/generate.d.ts +18 -0
  9. package/dist/changelog/generate.js +166 -0
  10. package/dist/changelog/generate.js.map +1 -0
  11. package/dist/changelog/index.d.ts +5 -0
  12. package/dist/changelog/index.js +3 -0
  13. package/dist/changelog/index.js.map +1 -0
  14. package/dist/changelog/parse.d.ts +43 -0
  15. package/dist/changelog/parse.js +91 -0
  16. package/dist/changelog/parse.js.map +1 -0
  17. package/dist/changelog/types.d.ts +85 -0
  18. package/dist/changelog/types.js +2 -0
  19. package/dist/changelog/types.js.map +1 -0
  20. package/dist/checkout/credential.d.ts +14 -0
  21. package/dist/checkout/credential.js +29 -0
  22. package/dist/checkout/credential.js.map +1 -0
  23. package/dist/checkout/git.d.ts +78 -0
  24. package/dist/checkout/git.js +191 -0
  25. package/dist/checkout/git.js.map +1 -0
  26. package/dist/checkout/index.d.ts +3 -0
  27. package/dist/checkout/index.js +4 -0
  28. package/dist/checkout/index.js.map +1 -0
  29. package/dist/checkout/sync.d.ts +156 -0
  30. package/dist/checkout/sync.js +211 -0
  31. package/dist/checkout/sync.js.map +1 -0
  32. package/dist/closing.d.ts +1 -0
  33. package/dist/closing.js +14 -0
  34. package/dist/closing.js.map +1 -0
  35. package/dist/config.d.ts +53 -0
  36. package/dist/config.js +40 -0
  37. package/dist/config.js.map +1 -0
  38. package/dist/deletion.d.ts +19 -0
  39. package/dist/deletion.js +27 -0
  40. package/dist/deletion.js.map +1 -0
  41. package/dist/errors.d.ts +26 -0
  42. package/dist/errors.js +47 -0
  43. package/dist/errors.js.map +1 -0
  44. package/dist/factory.d.ts +20 -0
  45. package/dist/factory.js +46 -0
  46. package/dist/factory.js.map +1 -0
  47. package/dist/github/client.d.ts +44 -0
  48. package/dist/github/client.js +145 -0
  49. package/dist/github/client.js.map +1 -0
  50. package/dist/github/config.d.ts +24 -0
  51. package/dist/github/config.js +11 -0
  52. package/dist/github/config.js.map +1 -0
  53. package/dist/github/provider.d.ts +510 -0
  54. package/dist/github/provider.js +1009 -0
  55. package/dist/github/provider.js.map +1 -0
  56. package/dist/gitlab/client.d.ts +50 -0
  57. package/dist/gitlab/client.js +228 -0
  58. package/dist/gitlab/client.js.map +1 -0
  59. package/dist/gitlab/provider.d.ts +487 -0
  60. package/dist/gitlab/provider.js +719 -0
  61. package/dist/gitlab/provider.js.map +1 -0
  62. package/dist/host.d.ts +27 -0
  63. package/dist/host.js +45 -0
  64. package/dist/host.js.map +1 -0
  65. package/dist/index.d.ts +46 -0
  66. package/dist/index.js +31 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/local/diff.d.ts +3 -0
  69. package/dist/local/diff.js +43 -0
  70. package/dist/local/diff.js.map +1 -0
  71. package/dist/local/git.d.ts +24 -0
  72. package/dist/local/git.js +51 -0
  73. package/dist/local/git.js.map +1 -0
  74. package/dist/local/health.d.ts +36 -0
  75. package/dist/local/health.js +57 -0
  76. package/dist/local/health.js.map +1 -0
  77. package/dist/local/hooks.d.ts +2 -0
  78. package/dist/local/hooks.js +44 -0
  79. package/dist/local/hooks.js.map +1 -0
  80. package/dist/local/http.d.ts +35 -0
  81. package/dist/local/http.js +160 -0
  82. package/dist/local/http.js.map +1 -0
  83. package/dist/local/provider.d.ts +571 -0
  84. package/dist/local/provider.js +1237 -0
  85. package/dist/local/provider.js.map +1 -0
  86. package/dist/local/store.d.ts +136 -0
  87. package/dist/local/store.js +171 -0
  88. package/dist/local/store.js.map +1 -0
  89. package/dist/packages/github-source.d.ts +69 -0
  90. package/dist/packages/github-source.js +133 -0
  91. package/dist/packages/github-source.js.map +1 -0
  92. package/dist/packages/gitlab-source.d.ts +59 -0
  93. package/dist/packages/gitlab-source.js +214 -0
  94. package/dist/packages/gitlab-source.js.map +1 -0
  95. package/dist/packages/index.d.ts +30 -0
  96. package/dist/packages/index.js +45 -0
  97. package/dist/packages/index.js.map +1 -0
  98. package/dist/packages/provider-source.d.ts +34 -0
  99. package/dist/packages/provider-source.js +57 -0
  100. package/dist/packages/provider-source.js.map +1 -0
  101. package/dist/packages/repository-files.d.ts +12 -0
  102. package/dist/packages/repository-files.js +16 -0
  103. package/dist/packages/repository-files.js.map +1 -0
  104. package/dist/provider.d.ts +888 -0
  105. package/dist/provider.js +29 -0
  106. package/dist/provider.js.map +1 -0
  107. package/dist/read-cache.d.ts +5 -0
  108. package/dist/read-cache.js +101 -0
  109. package/dist/read-cache.js.map +1 -0
  110. package/dist/registry/catalog.d.ts +55 -0
  111. package/dist/registry/catalog.js +143 -0
  112. package/dist/registry/catalog.js.map +1 -0
  113. package/dist/registry/kinds.d.ts +21 -0
  114. package/dist/registry/kinds.js +43 -0
  115. package/dist/registry/kinds.js.map +1 -0
  116. package/dist/registry/packages.d.ts +165 -0
  117. package/dist/registry/packages.js +290 -0
  118. package/dist/registry/packages.js.map +1 -0
  119. package/dist/registry/publish.d.ts +35 -0
  120. package/dist/registry/publish.js +155 -0
  121. package/dist/registry/publish.js.map +1 -0
  122. package/dist/registry/release.d.ts +63 -0
  123. package/dist/registry/release.js +79 -0
  124. package/dist/registry/release.js.map +1 -0
  125. package/dist/restoration.d.ts +14 -0
  126. package/dist/restoration.js +33 -0
  127. package/dist/restoration.js.map +1 -0
  128. package/dist/templates.d.ts +8 -0
  129. package/dist/templates.js +39 -0
  130. package/dist/templates.js.map +1 -0
  131. package/dist/testing/contract.d.ts +43 -0
  132. package/dist/testing/contract.js +713 -0
  133. package/dist/testing/contract.js.map +1 -0
  134. package/dist/testing/diff.d.ts +1 -0
  135. package/dist/testing/diff.js +65 -0
  136. package/dist/testing/diff.js.map +1 -0
  137. package/dist/testing/git-http.d.ts +12 -0
  138. package/dist/testing/git-http.js +308 -0
  139. package/dist/testing/git-http.js.map +1 -0
  140. package/dist/testing/github-double.d.ts +151 -0
  141. package/dist/testing/github-double.js +1129 -0
  142. package/dist/testing/github-double.js.map +1 -0
  143. package/dist/testing/gitlab-double.d.ts +161 -0
  144. package/dist/testing/gitlab-double.js +1554 -0
  145. package/dist/testing/gitlab-double.js.map +1 -0
  146. package/dist/testing/index.d.ts +7 -0
  147. package/dist/testing/index.js +8 -0
  148. package/dist/testing/index.js.map +1 -0
  149. package/dist/version.d.ts +2 -0
  150. package/dist/version.js +12 -0
  151. package/dist/version.js.map +1 -0
  152. package/package.json +66 -4
@@ -0,0 +1,155 @@
1
+ import fs from 'node:fs';
2
+ import { forgetPackageTags } from '../packages/gitlab-source.js';
3
+ import path from 'node:path';
4
+ import { PackageVersionExistsError } from '../errors.js';
5
+ import { entryFor } from './catalog.js';
6
+ import { KIND_DEFINITIONS } from './kinds.js';
7
+ import { assertPublishable, createPackageRelease, preflight, printable, publishedVersions } from './release.js';
8
+ /**
9
+ * Publishes the metamodels and modules of a folder to the git host, one repository each, so that LINEA reads them from there.
10
+ *
11
+ * `<dir>` holds `metamodels/<name>/` and `modules/<name>/`. They end up as
12
+ * GitLab <group>/metamodels/<name> topic linea-metamodel <group>/modules/<name> topic linea-module
13
+ * GitHub <owner>/<name> topic linea-metamodel <owner>/<name> topic linea-module
14
+ * with every file of the folder on `main` and the tag `v<version>` of its manifest. On GitLab the two subgroups are created when
15
+ * missing. GitHub has no groups inside an owner, so every package is a sibling there and a reference like
16
+ * `../../metamodels/datamodel` is written `../datamodel` (the names of metamodels and modules must therefore differ).
17
+ *
18
+ * It can be run again: repositories that exist are updated. A version is only published if it is valid semver, not already tagged
19
+ * (`PackageVersionExistsError`: raise the version in the manifest) and higher than the last one tagged (`PackageVersionInvalidError`),
20
+ * checked before anything of that package is written (a dry run makes the same checks). Packages before the failing one stay published,
21
+ * so use `only` to publish one at a time. Publishing tags it and creates the release of the tag with the changelog since the previous version; a version
22
+ * that does not match what the commits imply (feat → minor, fix → patch, breaking → major) is published anyway, with a warning.
23
+ * The warning and `suggestedBump` only see the commits already in the repository (edits made there, e.g. from the LINEA editor): the
24
+ * change in the folder being published is a single commit `Publish <name> <version>`, listed under «Other changes» in the release.
25
+ */
26
+ const SKIPPED = new Set(['.git', 'node_modules', '.DS_Store']);
27
+ const filesOf = (folder, prefix = '') => fs.readdirSync(folder, { withFileTypes: true }).flatMap((entry) => {
28
+ if (SKIPPED.has(entry.name))
29
+ return [];
30
+ const full = path.join(folder, entry.name);
31
+ return entry.isDirectory() ? filesOf(full, `${prefix}${entry.name}/`) : [{ path: `${prefix}${entry.name}`, content: fs.readFileSync(full) }];
32
+ });
33
+ /** Where a package refers to another by `../../metamodels/x` (a sibling folder of a sibling folder), a host without groups needs `../x`. */
34
+ const flatten = (reference) => reference.replace(/^\.\.\/\.\.\/(?:metamodels|modules)\//, '../');
35
+ /** The files of a package, with the references of its manifest as the host writes them. */
36
+ const filesFor = (kind, folder, flat) => filesOf(folder).map((file) => {
37
+ if (file.path !== KIND_DEFINITIONS[kind].manifest || !flat)
38
+ return file;
39
+ const manifest = JSON.parse(file.content.toString('utf8'));
40
+ const map = (record) => Object.fromEntries(Object.entries(record ?? {}).map(([reference, range]) => [flatten(reference), range]));
41
+ const rewritten = kind === 'module'
42
+ ? { ...manifest, requires: { ...manifest.requires, modules: map(manifest.requires?.modules), metamodels: map(manifest.requires?.metamodels) } }
43
+ : { ...manifest, requires: map(manifest.requires) };
44
+ return { ...file, content: Buffer.from(`${JSON.stringify(rewritten, null, 2)}\n`) };
45
+ });
46
+ export const publishFolder = async ({ provider, token, dir, root, kinds = ['metamodel', 'module'], only, dryRun = false, skipPublished = false, catalog, log = () => { } }) => {
47
+ const flat = !provider.nestsNamespaces;
48
+ const published = [];
49
+ let rootNamespace = null;
50
+ if (!dryRun) {
51
+ rootNamespace = await provider.findNamespace({ token, fullPath: root });
52
+ if (!rootNamespace)
53
+ throw new Error(`${root} does not exist on ${provider.kind}: ${flat ? 'the owner of the repositories' : 'the group to publish under'} has to be there already.`);
54
+ }
55
+ for (const kind of kinds) {
56
+ const definition = KIND_DEFINITIONS[kind];
57
+ const folder = path.join(dir, definition.dir);
58
+ if (!fs.existsSync(folder))
59
+ continue;
60
+ let namespaceId;
61
+ let namespacePath = flat ? root : `${root}/${definition.dir}`;
62
+ if (rootNamespace) {
63
+ if (flat) {
64
+ namespaceId = rootNamespace.id;
65
+ }
66
+ else {
67
+ let sub = await provider.findNamespace({ token, fullPath: namespacePath });
68
+ if (!sub) {
69
+ log(`+ group ${namespacePath}`);
70
+ sub = await provider.createNamespace({ token, name: definition.dir, parentId: rootNamespace.id });
71
+ }
72
+ namespaceId = sub.id;
73
+ namespacePath = sub.fullPath;
74
+ }
75
+ }
76
+ for (const name of fs.readdirSync(folder).sort()) {
77
+ if (only !== undefined && name !== only)
78
+ continue;
79
+ const packageDir = path.join(folder, name);
80
+ const manifestPath = path.join(packageDir, definition.manifest);
81
+ if (!fs.statSync(packageDir).isDirectory() || !fs.existsSync(manifestPath))
82
+ continue;
83
+ const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8'));
84
+ const repositoryPath = `${namespacePath}/${name}`;
85
+ if (dryRun) {
86
+ // the same checks as the real run, against the tags of the repository when it is there already
87
+ const existing = await provider.findRepository({ token, path: repositoryPath });
88
+ const tags = existing ? await provider.listTags({ token, id: existing.id }) : [];
89
+ try {
90
+ assertPublishable({ version: manifest.version, published: publishedVersions(tags), file: definition.manifest });
91
+ }
92
+ catch (error) {
93
+ if (!skipPublished || !(error instanceof PackageVersionExistsError))
94
+ throw error;
95
+ published.push({ kind, name, version: manifest.version, path: repositoryPath, status: 'already-published' });
96
+ continue;
97
+ }
98
+ log(`- ${repositoryPath} v${manifest.version} (${filesFor(kind, packageDir, flat).length} files)`);
99
+ published.push({ kind, name, version: manifest.version, path: repositoryPath, status: 'dry-run' });
100
+ continue;
101
+ }
102
+ let repository = await provider.findRepository({ token, path: repositoryPath });
103
+ if (!repository) {
104
+ repository = await provider.createRepository({ token, name, namespaceId, topics: [definition.topic], defaultBranch: 'main' });
105
+ }
106
+ else {
107
+ await provider.addTopic({ token, id: repository.id, topic: definition.topic });
108
+ }
109
+ if (catalog)
110
+ await catalog.add({ entry: entryFor({ kind, provider, path: repository.path, name, description: manifest.description }) });
111
+ const tag = `v${manifest.version}`;
112
+ // an invalid, already published or lower version is refused here, before the files are touched
113
+ let checked;
114
+ try {
115
+ checked = await preflight({ provider, token, id: repository.id, version: manifest.version, file: definition.manifest });
116
+ }
117
+ catch (error) {
118
+ if (!skipPublished || !(error instanceof PackageVersionExistsError))
119
+ throw error;
120
+ published.push({ kind, name, version: manifest.version, path: repository.path, status: 'already-published' });
121
+ continue;
122
+ }
123
+ const { suggestedBump, warnings } = checked;
124
+ for (const warning of warnings)
125
+ log(` warning: ${printable(warning)}`);
126
+ const files = filesFor(kind, packageDir, flat);
127
+ log(`- ${repository.path} v${manifest.version} (${files.length} files)`);
128
+ const existing = new Set(await provider.listFiles({ token, id: repository.id, ref: 'main' }));
129
+ await provider.commit({
130
+ token,
131
+ id: repository.id,
132
+ branch: 'main',
133
+ message: `Publish ${name} ${manifest.version}`,
134
+ track: false,
135
+ actions: files.map((file) => ({
136
+ action: existing.has(file.path) ? 'update' : 'create',
137
+ path: file.path,
138
+ content: file.content.toString('base64'),
139
+ encoding: 'base64'
140
+ }))
141
+ });
142
+ await provider.createTag({ token, id: repository.id, tag, ref: 'main', message: `Release ${manifest.version}` });
143
+ forgetPackageTags(`${provider.kind}:${repository.path}`);
144
+ const { release, warning } = await createPackageRelease({ provider, token, id: repository.id, tag, name });
145
+ if (warning) {
146
+ warnings.push(warning);
147
+ log(` warning: ${printable(warning)}`);
148
+ }
149
+ log(` published ${tag}${release ? ' with its release' : ''}`);
150
+ published.push({ kind, name, version: manifest.version, path: repository.path, status: 'published', suggestedBump, warnings });
151
+ }
152
+ }
153
+ return published;
154
+ };
155
+ //# sourceMappingURL=publish.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publish.js","sourceRoot":"","sources":["../../src/registry/publish.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAA;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAChE,OAAO,IAAI,MAAM,WAAW,CAAA;AAG5B,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACvC,OAAO,EAAE,gBAAgB,EAAoB,MAAM,YAAY,CAAA;AAC/D,OAAO,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,SAAS,EAAE,SAAS,EAAE,iBAAiB,EAAkB,MAAM,cAAc,CAAA;AAE/H;;;;;;;;;;;;;;;;;GAiBG;AAEH,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,cAAc,EAAE,WAAW,CAAC,CAAC,CAAA;AAO9D,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,MAAM,GAAG,EAAE,EAAmB,EAAE,CAC/D,EAAE,CAAC,WAAW,CAAC,MAAM,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;IAChE,IAAI,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAA;IACtC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,CAAA;IAC1C,OAAO,KAAK,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,GAAG,MAAM,GAAG,KAAK,CAAC,IAAI,EAAE,EAAE,OAAO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AAI,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;oBACxC,QAAQ,EAAE,QAAiB;iBAC5B,CAAC,CAAC;aACJ,CAAC,CAAA;YACF,MAAM,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,WAAW,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAA;YAChH,iBAAiB,CAAC,GAAG,QAAQ,CAAC,IAAI,IAAI,UAAU,CAAC,IAAI,EAAE,CAAC,CAAA;YACxD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,MAAM,oBAAoB,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,EAAE,UAAU,CAAC,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAA;YAC1G,IAAI,OAAO,EAAE,CAAC;gBACZ,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBACtB,GAAG,CAAC,gBAAgB,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC,CAAA;YAC3C,CAAC;YACD,GAAG,CAAC,iBAAiB,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;YAChE,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,CAAA;QAChI,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAA;AAClB,CAAC,CAAA","sourcesContent":["import fs from 'node:fs'\nimport { forgetPackageTags } from '../packages/gitlab-source.js'\nimport path from 'node:path'\nimport type { PackageCatalog } from '@lbdudc/linea-core'\nimport type { GitProvider, Id, Namespace } from '../provider.js'\nimport { PackageVersionExistsError } from '../errors.js'\nimport { entryFor } from './catalog.js'\nimport { KIND_DEFINITIONS, type PackageKind } from './kinds.js'\nimport { assertPublishable, createPackageRelease, preflight, printable, publishedVersions, type BumpLevel } from './release.js'\n\n/**\n * Publishes the metamodels and modules of a folder to the git host, one repository each, so that LINEA reads them from there.\n *\n * `<dir>` holds `metamodels/<name>/` and `modules/<name>/`. They end up as\n * GitLab <group>/metamodels/<name> topic linea-metamodel <group>/modules/<name> topic linea-module\n * GitHub <owner>/<name> topic linea-metamodel <owner>/<name> topic linea-module\n * with every file of the folder on `main` and the tag `v<version>` of its manifest. On GitLab the two subgroups are created when\n * missing. GitHub has no groups inside an owner, so every package is a sibling there and a reference like\n * `../../metamodels/datamodel` is written `../datamodel` (the names of metamodels and modules must therefore differ).\n *\n * It can be run again: repositories that exist are updated. A version is only published if it is valid semver, not already tagged\n * (`PackageVersionExistsError`: raise the version in the manifest) and higher than the last one tagged (`PackageVersionInvalidError`),\n * checked before anything of that package is written (a dry run makes the same checks). Packages before the failing one stay published,\n * so use `only` to publish one at a time. Publishing tags it and creates the release of the tag with the changelog since the previous version; a version\n * that does not match what the commits imply (feat → minor, fix → patch, breaking → major) is published anyway, with a warning.\n * The warning and `suggestedBump` only see the commits already in the repository (edits made there, e.g. from the LINEA editor): the\n * change in the folder being published is a single commit `Publish <name> <version>`, listed under «Other changes» in the release.\n */\n\nconst SKIPPED = new Set(['.git', 'node_modules', '.DS_Store'])\n\ninterface FileToPublish {\n path: string\n content: Buffer\n}\n\nconst filesOf = (folder: string, prefix = ''): FileToPublish[] =>\n fs.readdirSync(folder, { withFileTypes: true }).flatMap((entry) => {\n if (SKIPPED.has(entry.name)) return []\n const full = path.join(folder, entry.name)\n return entry.isDirectory() ? filesOf(full, `${prefix}${entry.name}/`) : [{ path: `${prefix}${entry.name}`, content: fs.readFileSync(full) }]\n })\n\n/** Where a package refers to another by `../../metamodels/x` (a sibling folder of a sibling folder), a host without groups needs `../x`. */\nconst flatten = (reference: string): string => reference.replace(/^\\.\\.\\/\\.\\.\\/(?:metamodels|modules)\\//, '../')\n\n/** The files of a package, with the references of its manifest as the host writes them. */\nconst filesFor = (kind: PackageKind, folder: string, flat: boolean): FileToPublish[] =>\n filesOf(folder).map((file) => {\n if (file.path !== KIND_DEFINITIONS[kind].manifest || !flat) return file\n const manifest = JSON.parse(file.content.toString('utf8'))\n const map = (record: Record<string, string> | undefined): Record<string, string> =>\n Object.fromEntries(Object.entries(record ?? {}).map(([reference, range]) => [flatten(reference), range]))\n const rewritten = kind === 'module'\n ? { ...manifest, requires: { ...manifest.requires, modules: map(manifest.requires?.modules), metamodels: map(manifest.requires?.metamodels) } }\n : { ...manifest, requires: map(manifest.requires) }\n return { ...file, content: Buffer.from(`${JSON.stringify(rewritten, null, 2)}\\n`) }\n })\n\nexport interface PublishedPackage {\n kind: PackageKind\n name: string\n version: string\n /** Where it is, as the host shows it. */\n path: string\n status: 'published' | 'already-published' | 'dry-run'\n /** What the commits since the last published version imply (only when it was published and there was a version before). */\n suggestedBump?: BumpLevel | null\n /** Things worth knowing that did not stop it: the version does not match the commits, the release could not be made. */\n warnings?: string[]\n}\n\nexport interface PublishFolderOptions {\n provider: GitProvider\n token: string\n /** The folder with `metamodels/` and `modules/`. */\n dir: string\n /** GitLab: the path of an existing group to publish under. GitHub: the user or organisation that owns the repositories. */\n root: string\n /** Only these kinds (both by default, metamodels first). */\n kinds?: PackageKind[]\n /** Only the package with this name. */\n only?: string\n dryRun?: boolean\n /** A version that is already published is reported (`already-published`) and left alone, instead of refused with `PackageVersionExistsError`. */\n skipPublished?: boolean\n /** Every package it publishes (or finds already published) is registered here, with the description of its manifest. */\n catalog?: PackageCatalog\n log?: (line: string) => void\n}\n\nexport const publishFolder = async ({ provider, token, dir, root, kinds = ['metamodel', 'module'], only, dryRun = false, skipPublished = false, catalog, log = () => {} }: PublishFolderOptions): Promise<PublishedPackage[]> => {\n const flat = !provider.nestsNamespaces\n const published: PublishedPackage[] = []\n\n let rootNamespace: Namespace | null = null\n if (!dryRun) {\n rootNamespace = await provider.findNamespace({ token, fullPath: root })\n if (!rootNamespace) throw new Error(`${root} does not exist on ${provider.kind}: ${flat ? 'the owner of the repositories' : 'the group to publish under'} has to be there already.`)\n }\n\n for (const kind of kinds) {\n const definition = KIND_DEFINITIONS[kind]\n const folder = path.join(dir, definition.dir)\n if (!fs.existsSync(folder)) continue\n\n let namespaceId: Id | undefined\n let namespacePath = flat ? root : `${root}/${definition.dir}`\n if (rootNamespace) {\n if (flat) {\n namespaceId = rootNamespace.id\n } else {\n let sub = await provider.findNamespace({ token, fullPath: namespacePath })\n if (!sub) {\n log(`+ group ${namespacePath}`)\n sub = await provider.createNamespace({ token, name: definition.dir, parentId: rootNamespace.id })\n }\n namespaceId = sub.id\n namespacePath = sub.fullPath\n }\n }\n\n for (const name of fs.readdirSync(folder).sort()) {\n if (only !== undefined && name !== only) continue\n const packageDir = path.join(folder, name)\n const manifestPath = path.join(packageDir, definition.manifest)\n if (!fs.statSync(packageDir).isDirectory() || !fs.existsSync(manifestPath)) continue\n const manifest = JSON.parse(fs.readFileSync(manifestPath, 'utf8')) as { version: string, description?: string }\n const repositoryPath = `${namespacePath}/${name}`\n if (dryRun) {\n // the same checks as the real run, against the tags of the repository when it is there already\n const existing = await provider.findRepository({ token, path: repositoryPath })\n const tags = existing ? await provider.listTags({ token, id: existing.id }) : []\n try {\n assertPublishable({ version: manifest.version, published: publishedVersions(tags), file: definition.manifest })\n } catch (error) {\n if (!skipPublished || !(error instanceof PackageVersionExistsError)) throw error\n published.push({ kind, name, version: manifest.version, path: repositoryPath, status: 'already-published' })\n continue\n }\n log(`- ${repositoryPath} v${manifest.version} (${filesFor(kind, packageDir, flat).length} files)`)\n published.push({ kind, name, version: manifest.version, path: repositoryPath, status: 'dry-run' })\n continue\n }\n\n let repository = await provider.findRepository({ token, path: repositoryPath })\n if (!repository) {\n repository = await provider.createRepository({ token, name, namespaceId, topics: [definition.topic], defaultBranch: 'main' })\n } else {\n await provider.addTopic({ token, id: repository.id, topic: definition.topic })\n }\n\n if (catalog) await catalog.add({ entry: entryFor({ kind, provider, path: repository.path, name, description: manifest.description }) })\n\n const tag = `v${manifest.version}`\n\n // an invalid, already published or lower version is refused here, before the files are touched\n let checked: Awaited<ReturnType<typeof preflight>>\n try {\n checked = await preflight({ provider, token, id: repository.id, version: manifest.version, file: definition.manifest })\n } catch (error) {\n if (!skipPublished || !(error instanceof PackageVersionExistsError)) throw error\n published.push({ kind, name, version: manifest.version, path: repository.path, status: 'already-published' })\n continue\n }\n const { suggestedBump, warnings } = checked\n for (const warning of warnings) log(` warning: ${printable(warning)}`)\n\n const files = filesFor(kind, packageDir, flat)\n log(`- ${repository.path} v${manifest.version} (${files.length} files)`)\n const existing = new Set(await provider.listFiles({ token, id: repository.id, ref: 'main' }))\n await provider.commit({\n token,\n id: repository.id,\n branch: 'main',\n message: `Publish ${name} ${manifest.version}`,\n track: false,\n actions: files.map((file) => ({\n action: existing.has(file.path) ? 'update' as const : 'create' as const,\n path: file.path,\n content: file.content.toString('base64'),\n encoding: 'base64' as const\n }))\n })\n await provider.createTag({ token, id: repository.id, tag, ref: 'main', message: `Release ${manifest.version}` })\n forgetPackageTags(`${provider.kind}:${repository.path}`)\n const { release, warning } = await createPackageRelease({ provider, token, id: repository.id, tag, name })\n if (warning) {\n warnings.push(warning)\n log(` warning: ${printable(warning)}`)\n }\n log(` published ${tag}${release ? ' with its release' : ''}`)\n published.push({ kind, name, version: manifest.version, path: repository.path, status: 'published', suggestedBump, warnings })\n }\n }\n return published\n}\n"]}
@@ -0,0 +1,63 @@
1
+ import { type Changelog } from '../changelog/index.js';
2
+ import type { GitProvider, Id, Release } from '../provider.js';
3
+ /**
4
+ * What publishing a version of a package involves besides the tag: checking that the version may be published, suggesting the bump the
5
+ * commits imply, and the release (with its changelog) that goes with the tag. Shared by `publishPackage` and `publishFolder`, so
6
+ * modules and metamodels, on GitLab and on GitHub, are published the same way.
7
+ */
8
+ export type BumpLevel = 'major' | 'minor' | 'patch';
9
+ /** Text that goes to a terminal or a log: control characters (ANSI escapes among them) are dropped. */
10
+ export declare const printable: (text: string) => string;
11
+ /** The versions a package has tagged (`vX.Y.Z`, with or without the `v`, prereleases too), highest first. */
12
+ export declare const publishedVersions: (tags: {
13
+ name: string;
14
+ }[]) => string[];
15
+ /** The name of the tag of a version, as the repository spells it. */
16
+ export declare const tagOf: (tags: {
17
+ name: string;
18
+ }[], version: string) => string;
19
+ /** Whether `version` is written the way a manifest has to: valid semver, as it is, without a `v` or spaces. */
20
+ export declare const isStrictSemver: (version: unknown) => version is string;
21
+ /**
22
+ * Throws if `version` cannot be published on top of `published` (the versions already tagged): `PackageVersionInvalidError` when it
23
+ * is not semver or not greater than the highest one, `PackageVersionExistsError` when it is one of them.
24
+ */
25
+ export declare const assertPublishable: ({ version, published, file }: {
26
+ version: unknown;
27
+ published: string[];
28
+ file: string;
29
+ }) => string;
30
+ /** The bump the commits of a changelog imply: a breaking change is major, a feature minor, a fix (or an improvement) patch; none if there is nothing of those. */
31
+ export declare const suggestBump: (commits: Pick<Changelog["commits"][number], "type" | "breaking">[]) => BumpLevel | null;
32
+ /** A warning (never an error) when the version of the manifest is not the bump the commits imply. */
33
+ export declare const bumpWarning: ({ latest, version, suggested }: {
34
+ latest: string | undefined;
35
+ version: string;
36
+ suggested: BumpLevel | null;
37
+ }) => string | null;
38
+ export interface Preflight {
39
+ version: string;
40
+ /** The bump the commits since the last published version imply (null: first publication, or nothing that implies one). */
41
+ suggestedBump: BumpLevel | null;
42
+ warnings: string[];
43
+ }
44
+ /** Validates `version` against the tags of the repository and compares it with what the commits on `ref` imply. Throws if it cannot be published. */
45
+ export declare const preflight: ({ provider, token, id, version, file, ref }: {
46
+ provider: GitProvider;
47
+ token: string;
48
+ id: Id;
49
+ version: unknown;
50
+ file: string;
51
+ ref?: string;
52
+ }) => Promise<Preflight>;
53
+ /** Creates the release of a tag that was just created, with the changelog from the previous published version. Returns it, or the reason it could not be made. */
54
+ export declare const createPackageRelease: ({ provider, token, id, tag, name }: {
55
+ provider: GitProvider;
56
+ token: string;
57
+ id: Id;
58
+ tag: string;
59
+ name: string;
60
+ }) => Promise<{
61
+ release: Release | null;
62
+ warning: string | null;
63
+ }>;
@@ -0,0 +1,79 @@
1
+ import semver from 'semver';
2
+ import { generateChangelog } from '../changelog/index.js';
3
+ import { PackageVersionExistsError, PackageVersionInvalidError } from '../errors.js';
4
+ /** Text that goes to a terminal or a log: control characters (ANSI escapes among them) are dropped. */
5
+ export const printable = (text) => text.replace(/[\u0000-\u001f\u007f-\u009f]+/g, ' ').trim();
6
+ /** The versions a package has tagged (`vX.Y.Z`, with or without the `v`, prereleases too), highest first. */
7
+ export const publishedVersions = (tags) => semver.rsort(tags.map((tag) => semver.valid(tag.name.replace(/^v/, ''))).filter((version) => version !== null));
8
+ /** The name of the tag of a version, as the repository spells it. */
9
+ export const tagOf = (tags, version) => tags.find((tag) => tag.name === `v${version}` || tag.name === version)?.name ?? `v${version}`;
10
+ /** Whether `version` is written the way a manifest has to: valid semver, as it is, without a `v` or spaces. */
11
+ export const isStrictSemver = (version) => typeof version === 'string' && semver.valid(version) === version;
12
+ /**
13
+ * Throws if `version` cannot be published on top of `published` (the versions already tagged): `PackageVersionInvalidError` when it
14
+ * is not semver or not greater than the highest one, `PackageVersionExistsError` when it is one of them.
15
+ */
16
+ export const assertPublishable = ({ version, published, file }) => {
17
+ if (!isStrictSemver(version)) {
18
+ throw new PackageVersionInvalidError(`${JSON.stringify(version)} is not a valid semver version (X.Y.Z): fix the version in ${file}`);
19
+ }
20
+ const valid = version;
21
+ if (published.some((other) => semver.eq(other, valid))) {
22
+ throw new PackageVersionExistsError(`v${valid} is already published: raise the version in ${file} (or publish with a bump)`);
23
+ }
24
+ const latest = published[0];
25
+ if (latest !== undefined && semver.lt(valid, latest)) {
26
+ throw new PackageVersionInvalidError(`${valid} is lower than v${latest}, the last version published: raise the version in ${file} above it`);
27
+ }
28
+ return valid;
29
+ };
30
+ /** The bump the commits of a changelog imply: a breaking change is major, a feature minor, a fix (or an improvement) patch; none if there is nothing of those. */
31
+ export const suggestBump = (commits) => {
32
+ if (commits.some((commit) => commit.breaking))
33
+ return 'major';
34
+ if (commits.some((commit) => commit.type === 'feat'))
35
+ return 'minor';
36
+ if (commits.some((commit) => commit.type === 'fix' || commit.type === 'perf'))
37
+ return 'patch';
38
+ return null;
39
+ };
40
+ /** A warning (never an error) when the version of the manifest is not the bump the commits imply. */
41
+ export const bumpWarning = ({ latest, version, suggested }) => {
42
+ if (latest === undefined || suggested === null)
43
+ return null;
44
+ const actual = semver.diff(latest, version);
45
+ const level = actual === 'major' || actual === 'premajor' ? 'major' : actual === 'minor' || actual === 'preminor' ? 'minor' : actual ? 'patch' : null;
46
+ if (level === suggested)
47
+ return null;
48
+ return `${version} is a ${level} bump over ${latest}, but the commits since then imply a ${suggested} one`;
49
+ };
50
+ /** Validates `version` against the tags of the repository and compares it with what the commits on `ref` imply. Throws if it cannot be published. */
51
+ export const preflight = async ({ provider, token, id, version, file, ref = 'main' }) => {
52
+ const tags = await provider.listTags({ token, id });
53
+ const published = publishedVersions(tags);
54
+ const valid = assertPublishable({ version, published, file });
55
+ const latest = published[0];
56
+ const warnings = [];
57
+ let suggestedBump = null;
58
+ if (latest !== undefined) {
59
+ const changes = await generateChangelog({ provider, token, id, from: tagOf(tags, latest), to: ref });
60
+ suggestedBump = suggestBump(changes.commits);
61
+ const warning = bumpWarning({ latest, version: valid, suggested: suggestedBump });
62
+ if (warning)
63
+ warnings.push(warning);
64
+ }
65
+ return { version: valid, suggestedBump, warnings };
66
+ };
67
+ /** Creates the release of a tag that was just created, with the changelog from the previous published version. Returns it, or the reason it could not be made. */
68
+ export const createPackageRelease = async ({ provider, token, id, tag, name }) => {
69
+ try {
70
+ const changes = await generateChangelog({ provider, token, id, to: tag, title: `${name} ${tag}` });
71
+ const release = await provider.createRelease({ token, id, tag, name: `${name} ${tag}`, description: changes.markdown });
72
+ return { release, warning: null };
73
+ }
74
+ catch (error) {
75
+ // the tag is what publishes a version; a release that fails is reported, not a reason to leave the caller without knowing the tag exists
76
+ return { release: null, warning: `${tag} was published but its release could not be created: ${printable(error.message)}` };
77
+ }
78
+ };
79
+ //# sourceMappingURL=release.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"release.js","sourceRoot":"","sources":["../../src/registry/release.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,iBAAiB,EAAkB,MAAM,uBAAuB,CAAA;AACzE,OAAO,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AAYpF,uGAAuG;AACvG,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,gCAAgC,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAA;AAE7G,6GAA6G;AAC7G,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAwB,EAAY,EAAE,CACtE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,OAAO,EAAqB,EAAE,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,CAAA;AAEpI,qEAAqE;AACrE,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAwB,EAAE,OAAe,EAAU,EAAE,CACzE,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,IAAI,OAAO,EAAE,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO,CAAC,EAAE,IAAI,IAAI,IAAI,OAAO,EAAE,CAAA;AAE/F,+GAA+G;AAC/G,MAAM,CAAC,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,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,IAAI,GAAG,EAAE,EAAE,WAAW,EAAE,OAAO,CAAC,QAAQ,EAAE,CAAC,CAAA;QACvH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IACnC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,yIAAyI;QACzI,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,GAAG,wDAAwD,SAAS,CAAE,KAAe,CAAC,OAAO,CAAC,EAAE,EAAE,CAAA;IACxI,CAAC;AACH,CAAC,CAAA","sourcesContent":["import semver from 'semver'\nimport { generateChangelog, type Changelog } from '../changelog/index.js'\nimport { PackageVersionExistsError, PackageVersionInvalidError } from '../errors.js'\nimport type { GitProvider, Id, Release } from '../provider.js'\n\n/**\n * What publishing a version of a package involves besides the tag: checking that the version may be published, suggesting the bump the\n * commits imply, and the release (with its changelog) that goes with the tag. Shared by `publishPackage` and `publishFolder`, so\n * modules and metamodels, on GitLab and on GitHub, are published the same way.\n */\n\nexport type BumpLevel = 'major' | 'minor' | 'patch'\n\n\n/** Text that goes to a terminal or a log: control characters (ANSI escapes among them) are dropped. */\nexport const printable = (text: string): string => text.replace(/[\\u0000-\\u001f\\u007f-\\u009f]+/g, ' ').trim()\n\n/** The versions a package has tagged (`vX.Y.Z`, with or without the `v`, prereleases too), highest first. */\nexport const publishedVersions = (tags: { name: string }[]): string[] =>\n semver.rsort(tags.map((tag) => semver.valid(tag.name.replace(/^v/, ''))).filter((version): version is string => version !== null))\n\n/** The name of the tag of a version, as the repository spells it. */\nexport const tagOf = (tags: { name: string }[], version: string): string =>\n tags.find((tag) => tag.name === `v${version}` || tag.name === version)?.name ?? `v${version}`\n\n/** Whether `version` is written the way a manifest has to: valid semver, as it is, without a `v` or spaces. */\nexport const isStrictSemver = (version: unknown): version is string => typeof version === 'string' && semver.valid(version) === version\n\n/**\n * Throws if `version` cannot be published on top of `published` (the versions already tagged): `PackageVersionInvalidError` when it\n * is not semver or not greater than the highest one, `PackageVersionExistsError` when it is one of them.\n */\nexport const assertPublishable = ({ version, published, file }: { version: unknown, published: string[], file: string }): string => {\n if (!isStrictSemver(version)) {\n throw new PackageVersionInvalidError(`${JSON.stringify(version)} is not a valid semver version (X.Y.Z): fix the version in ${file}`)\n }\n const valid = version\n if (published.some((other) => semver.eq(other, valid))) {\n throw new PackageVersionExistsError(`v${valid} is already published: raise the version in ${file} (or publish with a bump)`)\n }\n const latest = published[0]\n if (latest !== undefined && semver.lt(valid, latest)) {\n throw new PackageVersionInvalidError(`${valid} is lower than v${latest}, the last version published: raise the version in ${file} above it`)\n }\n return valid\n}\n\n/** The bump the commits of a changelog imply: a breaking change is major, a feature minor, a fix (or an improvement) patch; none if there is nothing of those. */\nexport const suggestBump = (commits: Pick<Changelog['commits'][number], 'type' | 'breaking'>[]): BumpLevel | null => {\n if (commits.some((commit) => commit.breaking)) return 'major'\n if (commits.some((commit) => commit.type === 'feat')) return 'minor'\n if (commits.some((commit) => commit.type === 'fix' || commit.type === 'perf')) return 'patch'\n return null\n}\n\n/** A warning (never an error) when the version of the manifest is not the bump the commits imply. */\nexport const bumpWarning = ({ latest, version, suggested }: { latest: string | undefined, version: string, suggested: BumpLevel | null }): string | null => {\n if (latest === undefined || suggested === null) return null\n const actual = semver.diff(latest, version)\n const level: BumpLevel | null = actual === 'major' || actual === 'premajor' ? 'major' : actual === 'minor' || actual === 'preminor' ? 'minor' : actual ? 'patch' : null\n if (level === suggested) return null\n return `${version} is a ${level} bump over ${latest}, but the commits since then imply a ${suggested} one`\n}\n\nexport interface Preflight {\n version: string\n /** The bump the commits since the last published version imply (null: first publication, or nothing that implies one). */\n suggestedBump: BumpLevel | null\n warnings: string[]\n}\n\n/** Validates `version` against the tags of the repository and compares it with what the commits on `ref` imply. Throws if it cannot be published. */\nexport const preflight = async ({ provider, token, id, version, file, ref = 'main' }: { provider: GitProvider, token: string, id: Id, version: unknown, file: string, ref?: string }): Promise<Preflight> => {\n const tags = await provider.listTags({ token, id })\n const published = publishedVersions(tags)\n const valid = assertPublishable({ version, published, file })\n const latest = published[0]\n const warnings: string[] = []\n let suggestedBump: BumpLevel | null = null\n if (latest !== undefined) {\n const changes = await generateChangelog({ provider, token, id, from: tagOf(tags, latest), to: ref })\n suggestedBump = suggestBump(changes.commits)\n const warning = bumpWarning({ latest, version: valid, suggested: suggestedBump })\n if (warning) warnings.push(warning)\n }\n return { version: valid, suggestedBump, warnings }\n}\n\n/** Creates the release of a tag that was just created, with the changelog from the previous published version. Returns it, or the reason it could not be made. */\nexport const createPackageRelease = async ({ provider, token, id, tag, name }: { provider: GitProvider, token: string, id: Id, tag: string, name: string }): Promise<{ release: Release | null, warning: string | null }> => {\n try {\n const changes = await generateChangelog({ provider, token, id, to: tag, title: `${name} ${tag}` })\n const release = await provider.createRelease({ token, id, tag, name: `${name} ${tag}`, description: changes.markdown })\n return { release, warning: null }\n } catch (error) {\n // the tag is what publishes a version; a release that fails is reported, not a reason to leave the caller without knowing the tag exists\n return { release: null, warning: `${tag} was published but its release could not be created: ${printable((error as Error).message)}` }\n }\n}\n"]}
@@ -0,0 +1,14 @@
1
+ import { type LineRestorationPlan } from '@lbdudc/linea-core';
2
+ import type { GitProvider, PendingDeletion } from './provider.js';
3
+ export declare const restoreLineOnHost: ({ provider, token, line, products, restoreProductIds }: {
4
+ provider: GitProvider;
5
+ token: string;
6
+ line: PendingDeletion;
7
+ products: PendingDeletion[];
8
+ restoreProductIds?: string[];
9
+ }) => Promise<LineRestorationPlan>;
10
+ export declare const restoreProductOnHost: ({ provider, token, product }: {
11
+ provider: GitProvider;
12
+ token: string;
13
+ product: PendingDeletion;
14
+ }) => Promise<void>;
@@ -0,0 +1,33 @@
1
+ import { planLineRestoration, planProductRestoration } from '@lbdudc/linea-core';
2
+ const run = async ({ provider, token, steps }) => {
3
+ for (const { action, kind, id } of steps) {
4
+ if (action === 'delete') {
5
+ if (kind === 'repository')
6
+ await provider.deleteRepository({ token, id });
7
+ else
8
+ await provider.deleteNamespace({ token, id });
9
+ }
10
+ else if (kind === 'repository')
11
+ await provider.restoreRepository({ token, id });
12
+ else
13
+ await provider.restoreNamespace({ token, id });
14
+ }
15
+ };
16
+ const itemOf = ({ id, namespaceId, repositoryScheduled, namespaceScheduled }) => ({
17
+ repositoryId: id,
18
+ namespaceId: namespaceId,
19
+ repositoryScheduled,
20
+ namespaceScheduled,
21
+ });
22
+ export const restoreLineOnHost = async ({ provider, token, line, products, restoreProductIds }) => {
23
+ const plan = planLineRestoration({
24
+ line: itemOf(line),
25
+ products: products.map((product) => ({ id: String(product.id), ...itemOf(product) })),
26
+ ...(restoreProductIds ? { restoreProductIds } : {}),
27
+ host: provider.capabilities().deletion,
28
+ });
29
+ await run({ provider, token, steps: plan.steps });
30
+ return plan;
31
+ };
32
+ export const restoreProductOnHost = ({ provider, token, product }) => (run({ provider, token, steps: planProductRestoration({ product: itemOf(product) }) }));
33
+ //# sourceMappingURL=restoration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restoration.js","sourceRoot":"","sources":["../src/restoration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,sBAAsB,EAAkD,MAAM,oBAAoB,CAAA;AAGhI,MAAM,GAAG,GAAG,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAsE,EAAiB,EAAE;IAClI,KAAK,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,KAAK,EAAE,CAAC;QACzC,IAAI,MAAM,KAAK,QAAQ,EAAE,CAAC;YACxB,IAAI,IAAI,KAAK,YAAY;gBAAE,MAAM,QAAQ,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAA;;gBACpE,MAAM,QAAQ,CAAC,eAAe,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CAAC,CAAA;QACpD,CAAC;aAAM,IAAI,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AAiB,EAAE,CAAC,CACvJ,GAAG,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,sBAAsB,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,CAAC,CACtF,CAAA","sourcesContent":["import { planLineRestoration, planProductRestoration, type LineRestorationPlan, type RestorationStep } from '@lbdudc/linea-core'\nimport type { GitProvider, PendingDeletion } from './provider.js'\n\nconst run = async ({ provider, token, steps }: { provider: GitProvider, token: string, steps: RestorationStep[] }): Promise<void> => {\n for (const { action, kind, id } of steps) {\n if (action === 'delete') {\n if (kind === 'repository') await provider.deleteRepository({ token, id })\n else await provider.deleteNamespace({ token, id })\n } else if (kind === 'repository') await provider.restoreRepository({ token, id })\n else await provider.restoreNamespace({ token, id })\n }\n}\n\nconst itemOf = ({ id, namespaceId, repositoryScheduled, namespaceScheduled }: PendingDeletion) => ({\n repositoryId: id,\n namespaceId: namespaceId as string | number,\n repositoryScheduled,\n namespaceScheduled,\n})\n\nexport const restoreLineOnHost = async ({ provider, token, line, products, restoreProductIds }: {\n provider: GitProvider\n token: string\n line: PendingDeletion\n products: PendingDeletion[]\n restoreProductIds?: string[]\n}): Promise<LineRestorationPlan> => {\n const plan = planLineRestoration({\n line: itemOf(line),\n products: products.map((product) => ({ id: String(product.id), ...itemOf(product) })),\n ...(restoreProductIds ? { restoreProductIds } : {}),\n host: provider.capabilities().deletion,\n })\n await run({ provider, token, steps: plan.steps })\n return plan\n}\n\nexport const restoreProductOnHost = ({ provider, token, product }: { provider: GitProvider, token: string, product: PendingDeletion }): Promise<void> => (\n run({ provider, token, steps: planProductRestoration({ product: itemOf(product) }) })\n)\n"]}
@@ -0,0 +1,8 @@
1
+ import type { GitProvider, Id, Template, TemplateKind } from './provider.js';
2
+ export declare const readRepositoryTemplates: (provider: GitProvider, { token, id, kind, ref, host }: {
3
+ token: string;
4
+ id: Id;
5
+ kind: TemplateKind;
6
+ ref: string;
7
+ host: "gitlab" | "github";
8
+ }) => Promise<Template[]>;
@@ -0,0 +1,39 @@
1
+ const LAYOUTS = {
2
+ gitlab: {
3
+ directories: { issue: ['.gitlab/issue_templates/'], mergeRequest: ['.gitlab/merge_request_templates/'] },
4
+ files: { issue: [], mergeRequest: [] }
5
+ },
6
+ github: {
7
+ directories: { issue: ['.github/ISSUE_TEMPLATE/'], mergeRequest: ['.github/PULL_REQUEST_TEMPLATE/'] },
8
+ files: { issue: ['.github/issue_template.md'], mergeRequest: ['.github/pull_request_template.md', '.github/PULL_REQUEST_TEMPLATE.md', 'docs/pull_request_template.md', 'pull_request_template.md'] }
9
+ }
10
+ };
11
+ const FRONT_MATTER = /^---\r?\n([\s\S]*?)\r?\n---\r?\n?/;
12
+ const stripFrontMatter = (text) => {
13
+ const match = FRONT_MATTER.exec(text);
14
+ if (!match)
15
+ return { name: null, content: text };
16
+ const name = /^name:\s*['"]?(.+?)['"]?\s*$/m.exec(match[1] ?? '')?.[1] ?? null;
17
+ return { name, content: text.slice(match[0].length) };
18
+ };
19
+ const baseName = (file) => (file.split('/').pop() ?? file).replace(/\.md$/i, '');
20
+ export const readRepositoryTemplates = async (provider, { token, id, kind, ref, host }) => {
21
+ const layout = LAYOUTS[host];
22
+ const paths = await provider.listFiles({ token, id, ref });
23
+ const lower = new Map(paths.map((file) => [file.toLowerCase(), file]));
24
+ const wanted = [
25
+ ...layout.files[kind].flatMap((file) => (lower.has(file.toLowerCase()) ? [lower.get(file.toLowerCase())] : [])),
26
+ ...paths.filter((file) => layout.directories[kind].some((directory) => file.startsWith(directory)) && /\.md$/i.test(file) && file.split('/').length === layout.directories[kind][0].split('/').length)
27
+ ];
28
+ const templates = [];
29
+ for (const file of [...new Set(wanted)]) {
30
+ const bytes = await provider.readFile({ token, id, path: file, ref });
31
+ if (!bytes)
32
+ continue;
33
+ const { name, content } = stripFrontMatter(bytes.toString('utf8'));
34
+ const isDirectory = layout.directories[kind].some((directory) => file.startsWith(directory));
35
+ templates.push({ name: name ?? (isDirectory ? baseName(file) : 'Default'), content });
36
+ }
37
+ return templates.sort((a, b) => a.name.localeCompare(b.name));
38
+ };
39
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAIA,MAAM,OAAO,GAAwC;IACnD,MAAM,EAAE;QACN,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,0BAA0B,CAAC,EAAE,YAAY,EAAE,CAAC,kCAAkC,CAAC,EAAE;QACxG,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,YAAY,EAAE,EAAE,EAAE;KACvC;IACD,MAAM,EAAE;QACN,WAAW,EAAE,EAAE,KAAK,EAAE,CAAC,yBAAyB,CAAC,EAAE,YAAY,EAAE,CAAC,gCAAgC,CAAC,EAAE;QACrG,KAAK,EAAE,EAAE,KAAK,EAAE,CAAC,2BAA2B,CAAC,EAAE,YAAY,EAAE,CAAC,kCAAkC,EAAE,kCAAkC,EAAE,+BAA+B,EAAE,0BAA0B,CAAC,EAAE;KACrM;CACF,CAAA;AAED,MAAM,YAAY,GAAG,mCAAmC,CAAA;AAExD,MAAM,gBAAgB,GAAG,CAAC,IAAY,EAA4C,EAAE;IAClF,MAAM,KAAK,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACrC,IAAI,CAAC,KAAK;QAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAA;IAChD,MAAM,IAAI,GAAG,+BAA+B,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAA;IAC9E,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAA;AACvD,CAAC,CAAA;AAED,MAAM,QAAQ,GA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AAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,CAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC;KACxM,CAAA;IACD,MAAM,SAAS,GAAe,EAAE,CAAA;IAChC,KAAK,MAAM,IAAI,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;QACxC,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,CAAA;QACrE,IAAI,CAAC,KAAK;YAAE,SAAQ;QACpB,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;QAClE,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC,CAAA;QAC5F,SAAS,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;IACvF,CAAC;IACD,OAAO,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAA;AAC/D,CAAC,CAAA","sourcesContent":["import type { GitProvider, Id, Template, TemplateKind } from './provider.js'\n\ntype Layout = { directories: Record<TemplateKind, string[]>, files: Record<TemplateKind, string[]> }\n\nconst LAYOUTS: Record<'gitlab' | 'github', Layout> = {\n gitlab: {\n directories: { issue: ['.gitlab/issue_templates/'], mergeRequest: ['.gitlab/merge_request_templates/'] },\n files: { issue: [], mergeRequest: [] }\n },\n github: {\n directories: { issue: ['.github/ISSUE_TEMPLATE/'], mergeRequest: ['.github/PULL_REQUEST_TEMPLATE/'] },\n files: { issue: ['.github/issue_template.md'], mergeRequest: ['.github/pull_request_template.md', '.github/PULL_REQUEST_TEMPLATE.md', 'docs/pull_request_template.md', 'pull_request_template.md'] }\n }\n}\n\nconst FRONT_MATTER = /^---\\r?\\n([\\s\\S]*?)\\r?\\n---\\r?\\n?/\n\nconst stripFrontMatter = (text: string): { name: string | null, content: string } => {\n const match = FRONT_MATTER.exec(text)\n if (!match) return { name: null, content: text }\n const name = /^name:\\s*['\"]?(.+?)['\"]?\\s*$/m.exec(match[1] ?? '')?.[1] ?? null\n return { name, content: text.slice(match[0].length) }\n}\n\nconst baseName = (file: string): string => (file.split('/').pop() ?? file).replace(/\\.md$/i, '')\n\nexport const readRepositoryTemplates = async (\n provider: GitProvider,\n { token, id, kind, ref, host }: { token: string, id: Id, kind: TemplateKind, ref: string, host: 'gitlab' | 'github' }\n): Promise<Template[]> => {\n const layout = LAYOUTS[host]\n const paths = await provider.listFiles({ token, id, ref })\n const lower = new Map(paths.map((file) => [file.toLowerCase(), file]))\n const wanted = [\n ...layout.files[kind].flatMap((file) => (lower.has(file.toLowerCase()) ? [lower.get(file.toLowerCase()) as string] : [])),\n ...paths.filter((file) => layout.directories[kind].some((directory) => file.startsWith(directory)) && /\\.md$/i.test(file) && file.split('/').length === layout.directories[kind][0]!.split('/').length)\n ]\n const templates: Template[] = []\n for (const file of [...new Set(wanted)]) {\n const bytes = await provider.readFile({ token, id, path: file, ref })\n if (!bytes) continue\n const { name, content } = stripFrontMatter(bytes.toString('utf8'))\n const isDirectory = layout.directories[kind].some((directory) => file.startsWith(directory))\n templates.push({ name: name ?? (isDirectory ? baseName(file) : 'Default'), content })\n }\n return templates.sort((a, b) => a.name.localeCompare(b.name))\n}\n"]}
@@ -0,0 +1,43 @@
1
+ import { type GitProvider } from '../provider.js';
2
+ type Id = string | number;
3
+ export interface GitProviderContractOptions {
4
+ name: string;
5
+ makeProvider: () => GitProvider;
6
+ addMember: (args: {
7
+ repository: {
8
+ id: Id;
9
+ };
10
+ username: string;
11
+ accessLevel: number;
12
+ }) => void | Promise<void>;
13
+ signWebhook: (args: {
14
+ body: unknown;
15
+ secret: string;
16
+ }) => {
17
+ headers: Record<string, string>;
18
+ rawBody: string;
19
+ };
20
+ pushEvent: (args: {
21
+ repositoryId: Id;
22
+ branch: string;
23
+ }) => {
24
+ headers: Record<string, string>;
25
+ body: unknown;
26
+ };
27
+ /** Makes a milestone the host knows (a host where they are free text needs none). */
28
+ addMilestone?: (args: {
29
+ repository: {
30
+ id: Id;
31
+ };
32
+ title: string;
33
+ }) => void | Promise<void>;
34
+ }
35
+ /**
36
+ * What every `GitProvider` has to do, whatever host is behind it. A host passes `makeProvider` (a new provider on a clean host each call)
37
+ * and the contract runs against it: if a new provider (GitHub...) passes this, the services work on it, because the services only use
38
+ * what is checked here.
39
+ *
40
+ * `status` of an error is what the services look at (404: not there, 400/409: a change made from a stale revision).
41
+ */
42
+ export declare const describeGitProviderContract: ({ name, makeProvider, addMember, signWebhook, pushEvent, addMilestone }: GitProviderContractOptions) => void;
43
+ export {};