@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,211 @@
1
+ import { hostDescriptor } from '../host.js';
2
+ import fs from 'node:fs';
3
+ import path from 'node:path';
4
+ import { findContext, readOrigin, writeOrigin, excludeFromGit } from '@lbdudc/linea-core/workspace';
5
+ import { KIND_DEFINITIONS } from '../registry/kinds.js';
6
+ import { GitCommandError, changedCount, cloneUrlOf, configureCredentials, credentialOptions, git, gitAsync, gitOk, gitOkAsync, isAuthFailure, isRepo, repoState, slug, withoutCredentials } from './git.js';
7
+ // a product the platform has not generated yet is a repository with a README: it has no spec, but its origin says what it is
8
+ const isProductRepo = (dir) => isRepo(dir) && (fs.existsSync(path.join(dir, '.linea', 'spec.json')) || readOrigin(dir)?.kind === 'product');
9
+ /** The git checkouts of an SPL: itself, and the products cloned into it. */
10
+ export function checkoutsOfLine(lineDir) {
11
+ const found = [];
12
+ if (isRepo(lineDir))
13
+ found.push({ name: path.basename(lineDir), kind: 'spl', dir: lineDir });
14
+ let entries = [];
15
+ try {
16
+ entries = fs.readdirSync(lineDir, { withFileTypes: true });
17
+ }
18
+ catch {
19
+ /* gone */
20
+ }
21
+ for (const e of entries.filter((d) => d.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {
22
+ const dir = path.join(lineDir, e.name);
23
+ if (isProductRepo(dir))
24
+ found.push({ name: e.name, kind: 'product', dir, lineDir });
25
+ }
26
+ return found;
27
+ }
28
+ /** The SPLs of a workspace that are git checkouts. */
29
+ export function splCheckouts(root) {
30
+ let entries = [];
31
+ try {
32
+ entries = fs.readdirSync(root, { withFileTypes: true });
33
+ }
34
+ catch {
35
+ /* none */
36
+ }
37
+ return entries
38
+ .filter((e) => e.isDirectory() && isRepo(path.join(root, e.name)) && findContext(path.join(root, e.name)).line?.dir === path.join(root, e.name))
39
+ .map((e) => ({ name: e.name, kind: 'spl', dir: path.join(root, e.name) }));
40
+ }
41
+ /**
42
+ * What a command acts on, from where you stand: the product you are in; else the SPL and its products; else the SPLs of the
43
+ * workspace (`fallbackRoot` when the folder is in none).
44
+ */
45
+ export function checkoutsAt(cwd, fallbackRoot) {
46
+ const folder = findContext(cwd);
47
+ if (folder.product && isRepo(folder.product.dir)) {
48
+ return [{ name: folder.product.name, kind: 'product', dir: folder.product.dir, ...(folder.line ? { lineDir: folder.line.dir } : {}) }];
49
+ }
50
+ if (folder.line)
51
+ return checkoutsOfLine(folder.line.dir);
52
+ return splCheckouts(folder.workspace ?? fallbackRoot);
53
+ }
54
+ // ---------------------------------------------------------------- clone
55
+ /** Clones a repository and leaves it ready for `git pull/push` with the helper; says which branch it started on (the default one). */
56
+ export async function cloneRepository({ url, dest, helper, onProgress }) {
57
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
58
+ await gitOkAsync(undefined, [...credentialOptions(url, helper), 'clone', '--progress', url, dest], { ...(onProgress ? { onProgress } : {}) });
59
+ configureCredentials(dest, url, helper);
60
+ return git(dest, ['symbolic-ref', '--short', 'HEAD']).stdout.trim() || 'main';
61
+ }
62
+ /** Clones a repository of the host as the SPL it is, and writes where it came from. */
63
+ export async function cloneLine({ dir, base, line, helper, onProgress }) {
64
+ const defaultBranch = await cloneRepository({ url: cloneUrlOf(line.webUrl), dest: dir, helper, ...(onProgress ? { onProgress } : {}) });
65
+ writeOrigin(dir, { ...base, kind: 'spl', name: line.name, projectId: line.repoId, webUrl: line.webUrl, defaultBranch });
66
+ }
67
+ /** Clones a product of an SPL into the SPL's folder, as a repository of its own that the SPL's git leaves alone. */
68
+ export async function cloneProduct({ lineDir, base, product, helper, onProgress }) {
69
+ const dir = path.join(lineDir, product.name);
70
+ const defaultBranch = await cloneRepository({ url: cloneUrlOf(product.repo.webUrl), dest: dir, helper, ...(onProgress ? { onProgress } : {}) });
71
+ writeOrigin(dir, { ...base, kind: 'product', name: product.name, productId: product._id, projectId: product.repo.id, webUrl: product.repo.webUrl, defaultBranch });
72
+ excludeFromGit(lineDir, `/${product.name}/`);
73
+ return dir;
74
+ }
75
+ /** `git pull --ff-only` in a checkout. A failure is a result, not an error: the next checkout is still worth updating. */
76
+ export async function pullCheckout({ dir, helper, onProgress }) {
77
+ const before = repoState(dir);
78
+ const changesAndBehind = Boolean(changedCount(before) && before.behind);
79
+ const url = readOrigin(dir)?.webUrl ?? '';
80
+ const res = await gitAsync(dir, [...credentialOptions(url, helper), 'pull', '--ff-only', '--progress'], { ...(onProgress ? { onProgress } : {}) });
81
+ if (res.status !== 0) {
82
+ const said = withoutCredentials((res.stderr || res.stdout).trim());
83
+ return { outcome: 'failed', commits: 0, changesAndBehind, said, denied: isAuthFailure(said) };
84
+ }
85
+ return { outcome: before.behind ? 'updated' : 'current', commits: before.behind, changesAndBehind };
86
+ }
87
+ /** Asks the host what is new, without changing anything here (`git fetch`). */
88
+ export async function fetchCheckout({ dir, helper }) {
89
+ await gitAsync(dir, [...credentialOptions(readOrigin(dir)?.webUrl ?? '', helper), 'fetch', '--quiet']);
90
+ }
91
+ /** The branch name of changes sent for review: who, what, and when. */
92
+ export const reviewBranch = (user, message, now = new Date()) => `linea/${slug(user, 20)}/${slug(message, 30)}-${now.toISOString().replace(/[-:T]/g, '').slice(0, 12)}`;
93
+ /**
94
+ * Commits what changed in a checkout and sends it: to a branch of its own with a merge/pull request (the default), or to the branch
95
+ * it is on (`direct`). Without `changeRequest` (a copy made without the host's help) the branch is sent and nothing is opened.
96
+ * Throws a `GitCommandError` when git could not do something; a request that could not be opened is in the result.
97
+ */
98
+ export async function pushCheckout({ dir, message, direct, user, helper, onProgress, changeRequest }) {
99
+ const before = repoState(dir);
100
+ const origin = readOrigin(dir);
101
+ const defaultBranch = origin?.defaultBranch ?? 'main';
102
+ let branch = before.branch;
103
+ if (!direct && branch === defaultBranch) {
104
+ branch = reviewBranch(user, message);
105
+ gitOk(dir, ['checkout', '-b', branch]);
106
+ }
107
+ if (changedCount(before)) {
108
+ gitOk(dir, ['add', '-A']);
109
+ gitOk(dir, ['commit', '--quiet', '-m', message]);
110
+ }
111
+ await gitOkAsync(dir, [...credentialOptions(origin?.webUrl ?? '', helper), 'push', '--progress', '-u', 'origin', `HEAD:refs/heads/${branch}`], { ...(onProgress ? { onProgress } : {}) });
112
+ const toDefault = Boolean(direct) || branch === defaultBranch;
113
+ if (toDefault || !origin || !changeRequest)
114
+ return { branch, toDefault };
115
+ try {
116
+ const request = await changeRequest.provider.createOrRenameChangeRequest({
117
+ token: changeRequest.token, id: origin.projectId, title: message, sourceBranch: branch, targetBranch: defaultBranch
118
+ });
119
+ return { branch, toDefault, changeRequest: { url: request.webUrl } };
120
+ }
121
+ catch (e) {
122
+ return { branch, toDefault, changeRequest: { error: e.message } };
123
+ }
124
+ }
125
+ /** Whether a checkout has something to send: changes, or commits the host does not have. */
126
+ export const hasUnsent = (state) => Boolean(changedCount(state) || state.ahead);
127
+ // ---------------------------------------------------------------- adopt
128
+ const copyTree = (from, to, skip) => {
129
+ let copied = 0;
130
+ for (const entry of fs.readdirSync(from, { withFileTypes: true })) {
131
+ if (skip(entry.name))
132
+ continue;
133
+ const source = path.join(from, entry.name);
134
+ const target = path.join(to, entry.name);
135
+ if (entry.isDirectory()) {
136
+ fs.mkdirSync(target, { recursive: true });
137
+ copied += copyTree(source, target, (n) => n === 'node_modules' || n === '.git');
138
+ }
139
+ else if (entry.isFile()) {
140
+ fs.mkdirSync(path.dirname(target), { recursive: true });
141
+ fs.copyFileSync(source, target);
142
+ copied++;
143
+ }
144
+ }
145
+ return copied;
146
+ };
147
+ /**
148
+ * Local files that are not part of an SPL when it is uploaded: a repository's own, caches, installed packages, and products (they
149
+ * are repositories of their own).
150
+ */
151
+ const notUploaded = (lineDir, name) => name === '.git' || name === '.linea' || name === 'node_modules' || fs.existsSync(path.join(lineDir, name, '.linea', 'spec.json'));
152
+ /**
153
+ * A folder made here becomes the checkout of a repository the host just made for it (with the scaffold of an SPL): what is here goes
154
+ * on top of the scaffold, is committed and sent to the default branch, and the folder takes the repository over. Returns how many files
155
+ * were sent and the default branch.
156
+ */
157
+ export async function adoptFolder({ dir, url, name, helper, onProgress }) {
158
+ const staging = fs.mkdtempSync(path.join(path.dirname(dir), `.${name}-link-`));
159
+ try {
160
+ const defaultBranch = await cloneRepository({ url, dest: staging, helper, ...(onProgress ? { onProgress: (l) => onProgress('getting', l) } : {}) });
161
+ const copied = copyTree(dir, staging, (n) => notUploaded(dir, n));
162
+ gitOk(staging, ['add', '-A']);
163
+ if (git(staging, ['status', '--porcelain']).stdout.trim()) {
164
+ gitOk(staging, ['commit', '--quiet', '-m', `Upload ${name} from the command line`]);
165
+ await gitOkAsync(staging, [...credentialOptions(url, helper), 'push', '--progress', 'origin', `HEAD:refs/heads/${defaultBranch}`], { ...(onProgress ? { onProgress: (l) => onProgress('uploading', l) } : {}) });
166
+ }
167
+ // the folder becomes the checkout: it takes the repository; its files are the ones just committed, plus what the scaffold had
168
+ // that was not here (the README the host makes), which are brought into the folder
169
+ fs.renameSync(path.join(staging, '.git'), path.join(dir, '.git'));
170
+ gitOk(dir, ['checkout', '--quiet', '--', '.']);
171
+ configureCredentials(dir, url, helper);
172
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
173
+ if (entry.isDirectory() && fs.existsSync(path.join(dir, entry.name, '.linea', 'spec.json')))
174
+ excludeFromGit(dir, `/${entry.name}/`);
175
+ }
176
+ return { copied, defaultBranch };
177
+ }
178
+ finally {
179
+ fs.rmSync(staging, { recursive: true, force: true });
180
+ }
181
+ }
182
+ // ---------------------------------------------------------------- packages
183
+ /**
184
+ * Gets a module or metamodel of the git host into a workspace to change it: a clone that remembers where it came from, and where
185
+ * `publish` puts it back (the group on GitLab, the owner on GitHub). `repoPath` is `group/project` as the host knows it. Throws when
186
+ * the host does not know it, or it is not a package of that kind.
187
+ */
188
+ export async function clonePackage({ provider, token, kind, repoPath, workdir, dest, helper, onProgress }) {
189
+ const definition = KIND_DEFINITIONS[kind];
190
+ const repository = await provider.findRepository({ token, path: repoPath });
191
+ if (!repository)
192
+ throw new Error(`No repository ${repoPath} on ${hostDescriptor(provider.kind).label} (or you cannot see it).`);
193
+ if (!repository.topics.includes(definition.topic)) {
194
+ throw new Error(`${repoPath} is not a ${kind} (its topics are ${repository.topics.join(', ') || 'none'}; a ${kind} has "${definition.topic}").`);
195
+ }
196
+ const dir = dest ?? path.join(workdir, definition.dir, repository.name);
197
+ if (isRepo(dir) && readOrigin(dir))
198
+ return { status: 'present', name: repository.name, dir };
199
+ if (fs.existsSync(dir) && fs.readdirSync(dir).length)
200
+ throw new Error(`${dir} exists and is not empty.`);
201
+ await cloneRepository({ url: cloneUrlOf(repository.webUrl), dest: dir, helper, ...(onProgress ? { onProgress } : {}) });
202
+ // where to publish it again: GitLab keeps them under <group>/modules and <group>/metamodels, GitHub as repositories of an owner
203
+ const parts = repository.path.split('/');
204
+ const publishRoot = provider.kind === 'github' ? parts[0] : parts.at(-2) === definition.dir ? parts.slice(0, -2).join('/') : undefined;
205
+ writeOrigin(dir, {
206
+ kind, name: repository.name, provider: provider.kind === 'github' ? 'github' : 'gitlab', projectId: repository.id, webUrl: repository.webUrl,
207
+ defaultBranch: repository.defaultBranch ?? 'main', ...(publishRoot ? { publishRoot } : {})
208
+ });
209
+ return { status: 'cloned', name: repository.name, dir, ...(publishRoot ? { publishRoot } : {}) };
210
+ }
211
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","s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,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,SAAS,EAAE,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM;QAC5I,aAAa,EAAE,UAAU,CAAC,aAAa,IAAI,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC3F,CAAC,CAAA;IACF,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAA;AAClG,CAAC","sourcesContent":["import { hostDescriptor } from '../host.js'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { findContext, readOrigin, writeOrigin, excludeFromGit, type Origin } from '@lbdudc/linea-core/workspace'\nimport type { GitProvider } from '../provider.js'\nimport { KIND_DEFINITIONS, type PackageKind } from '../registry/kinds.js'\nimport {\n GitCommandError, changedCount, cloneUrlOf, configureCredentials, credentialOptions, git, gitAsync, gitOk, gitOkAsync, isAuthFailure, isRepo, repoState,\n slug, withoutCredentials, type RepoState\n} from './git.js'\n\n/**\n * Checkouts: an SPL cloned from the host, and the products cloned inside it, as the repositories they are. What `get`, `status` and\n * `push` of a program are made of; the program says it in words. Every call takes `helper`, what git runs as its credential helper\n * (see `credentialOptions`), because what that is depends on the program.\n */\n\ntype Progress = (line: string) => void\n\n// ---------------------------------------------------------------- what is where\n\nexport interface Checkout {\n name: string\n kind: 'spl' | 'product'\n dir: string\n /** for a product: the SPL it sits in */\n lineDir?: string\n}\n\n// a product the platform has not generated yet is a repository with a README: it has no spec, but its origin says what it is\nconst isProductRepo = (dir: string): boolean => isRepo(dir) && (fs.existsSync(path.join(dir, '.linea', 'spec.json')) || readOrigin(dir)?.kind === 'product')\n\n/** The git checkouts of an SPL: itself, and the products cloned into it. */\nexport function checkoutsOfLine (lineDir: string): Checkout[] {\n const found: Checkout[] = []\n if (isRepo(lineDir)) found.push({ name: path.basename(lineDir), kind: 'spl', dir: lineDir })\n let entries: fs.Dirent[] = []\n try {\n entries = fs.readdirSync(lineDir, { withFileTypes: true })\n } catch {\n /* gone */\n }\n for (const e of entries.filter((d) => d.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {\n const dir = path.join(lineDir, e.name)\n if (isProductRepo(dir)) found.push({ name: e.name, kind: 'product', dir, lineDir })\n }\n return found\n}\n\n/** The SPLs of a workspace that are git checkouts. */\nexport function splCheckouts (root: string): Checkout[] {\n let entries: fs.Dirent[] = []\n try {\n entries = fs.readdirSync(root, { withFileTypes: true })\n } catch {\n /* none */\n }\n return entries\n .filter((e) => e.isDirectory() && isRepo(path.join(root, e.name)) && findContext(path.join(root, e.name)).line?.dir === path.join(root, e.name))\n .map((e) => ({ name: e.name, kind: 'spl' as const, dir: path.join(root, e.name) }))\n}\n\n/**\n * What a command acts on, from where you stand: the product you are in; else the SPL and its products; else the SPLs of the\n * workspace (`fallbackRoot` when the folder is in none).\n */\nexport function checkoutsAt (cwd: string, fallbackRoot: string): Checkout[] {\n const folder = findContext(cwd)\n if (folder.product && isRepo(folder.product.dir)) {\n return [{ name: folder.product.name, kind: 'product', dir: folder.product.dir, ...(folder.line ? { lineDir: folder.line.dir } : {}) }]\n }\n if (folder.line) return checkoutsOfLine(folder.line.dir)\n return splCheckouts(folder.workspace ?? fallbackRoot)\n}\n\n// ---------------------------------------------------------------- clone\n\n/** Clones a repository and leaves it ready for `git pull/push` with the helper; says which branch it started on (the default one). */\nexport async function cloneRepository ({ url, dest, helper, onProgress }: { url: string, dest: string, helper: string, onProgress?: Progress }): Promise<string> {\n fs.mkdirSync(path.dirname(dest), { recursive: true })\n await gitOkAsync(undefined, [...credentialOptions(url, helper), 'clone', '--progress', url, dest], { ...(onProgress ? { onProgress } : {}) })\n configureCredentials(dest, url, helper)\n return git(dest, ['symbolic-ref', '--short', 'HEAD']).stdout.trim() || 'main'\n}\n\n/** What a clone remembers about where it came from, besides the repository itself. */\nexport type OriginBase = Pick<Origin, 'server' | 'provider' | 'lineId' | 'webUi'>\n\n/** Clones a repository of the host as the SPL it is, and writes where it came from. */\nexport async function cloneLine ({ dir, base, line, helper, onProgress }: {\n dir: string\n base: OriginBase\n line: { name: string, webUrl: string, repoId: number | string }\n helper: string\n onProgress?: Progress\n}): Promise<void> {\n const defaultBranch = await cloneRepository({ url: cloneUrlOf(line.webUrl), dest: dir, helper, ...(onProgress ? { onProgress } : {}) })\n writeOrigin(dir, { ...base, kind: 'spl', name: line.name, projectId: line.repoId, webUrl: line.webUrl, defaultBranch })\n}\n\n/** Clones a product of an SPL into the SPL's folder, as a repository of its own that the SPL's git leaves alone. */\nexport async function cloneProduct ({ lineDir, base, product, helper, onProgress }: {\n lineDir: string\n base: OriginBase\n product: { _id: string, name: string, repo: { id: number | string, webUrl: string } }\n helper: string\n onProgress?: Progress\n}): Promise<string> {\n const dir = path.join(lineDir, product.name)\n const defaultBranch = await cloneRepository({ url: cloneUrlOf(product.repo.webUrl), dest: dir, helper, ...(onProgress ? { onProgress } : {}) })\n writeOrigin(dir, { ...base, kind: 'product', name: product.name, productId: product._id, projectId: product.repo.id, webUrl: product.repo.webUrl, defaultBranch })\n excludeFromGit(lineDir, `/${product.name}/`)\n return dir\n}\n\n// ---------------------------------------------------------------- pull\n\nexport interface PullResult {\n /** `updated`: new commits came; `current`: nothing new; `failed`: see `said` */\n outcome: 'updated' | 'current' | 'failed'\n /** how many commits came */\n commits: number\n /** it has changes of its own and the host moved: they have to be committed before they can be joined */\n changesAndBehind: boolean\n /** what git said when it failed, without credentials */\n said?: string\n /** the failure was the host refusing access */\n denied?: boolean\n}\n\n/** `git pull --ff-only` in a checkout. A failure is a result, not an error: the next checkout is still worth updating. */\nexport async function pullCheckout ({ dir, helper, onProgress }: { dir: string, helper: string, onProgress?: Progress }): Promise<PullResult> {\n const before = repoState(dir)\n const changesAndBehind = Boolean(changedCount(before) && before.behind)\n const url = readOrigin(dir)?.webUrl ?? ''\n const res = await gitAsync(dir, [...credentialOptions(url, helper), 'pull', '--ff-only', '--progress'], { ...(onProgress ? { onProgress } : {}) })\n if (res.status !== 0) {\n const said = withoutCredentials((res.stderr || res.stdout).trim())\n return { outcome: 'failed', commits: 0, changesAndBehind, said, denied: isAuthFailure(said) }\n }\n return { outcome: before.behind ? 'updated' : 'current', commits: before.behind, changesAndBehind }\n}\n\n/** Asks the host what is new, without changing anything here (`git fetch`). */\nexport async function fetchCheckout ({ dir, helper }: { dir: string, helper: string }): Promise<void> {\n await gitAsync(dir, [...credentialOptions(readOrigin(dir)?.webUrl ?? '', helper), 'fetch', '--quiet'])\n}\n\n// ---------------------------------------------------------------- push\n\nexport interface PushResult {\n /** the branch that was sent */\n branch: string\n /** it went to the default branch itself: there is nothing to merge */\n toDefault: boolean\n /** the merge/pull request opened for it, or why it could not be */\n changeRequest?: { url: string } | { error: string }\n}\n\n/** The branch name of changes sent for review: who, what, and when. */\nexport const reviewBranch = (user: string, message: string, now = new Date()): string =>\n `linea/${slug(user, 20)}/${slug(message, 30)}-${now.toISOString().replace(/[-:T]/g, '').slice(0, 12)}`\n\n/**\n * Commits what changed in a checkout and sends it: to a branch of its own with a merge/pull request (the default), or to the branch\n * it is on (`direct`). Without `changeRequest` (a copy made without the host's help) the branch is sent and nothing is opened.\n * Throws a `GitCommandError` when git could not do something; a request that could not be opened is in the result.\n */\nexport async function pushCheckout ({ dir, message, direct, user, helper, onProgress, changeRequest }: {\n dir: string\n message: string\n direct?: boolean\n user: string\n helper: string\n onProgress?: Progress\n /** the host's API, to open the request with */\n changeRequest?: { provider: GitProvider, token: string }\n}): Promise<PushResult> {\n const before = repoState(dir)\n const origin = readOrigin(dir)\n const defaultBranch = origin?.defaultBranch ?? 'main'\n let branch = before.branch\n if (!direct && branch === defaultBranch) {\n branch = reviewBranch(user, message)\n gitOk(dir, ['checkout', '-b', branch])\n }\n if (changedCount(before)) {\n gitOk(dir, ['add', '-A'])\n gitOk(dir, ['commit', '--quiet', '-m', message])\n }\n await gitOkAsync(dir, [...credentialOptions(origin?.webUrl ?? '', helper), 'push', '--progress', '-u', 'origin', `HEAD:refs/heads/${branch}`], { ...(onProgress ? { onProgress } : {}) })\n const toDefault = Boolean(direct) || branch === defaultBranch\n if (toDefault || !origin || !changeRequest) return { branch, toDefault }\n try {\n const request = await changeRequest.provider.createOrRenameChangeRequest({\n token: changeRequest.token, id: origin.projectId, title: message, sourceBranch: branch, targetBranch: defaultBranch\n })\n return { branch, toDefault, changeRequest: { url: request.webUrl } }\n } catch (e) {\n return { branch, toDefault, changeRequest: { error: (e as Error).message } }\n }\n}\n\n/** Whether a checkout has something to send: changes, or commits the host does not have. */\nexport const hasUnsent = (state: RepoState): boolean => Boolean(changedCount(state) || state.ahead)\n\n// ---------------------------------------------------------------- adopt\n\nconst copyTree = (from: string, to: string, skip: (name: string) => boolean): number => {\n let copied = 0\n for (const entry of fs.readdirSync(from, { withFileTypes: true })) {\n if (skip(entry.name)) continue\n const source = path.join(from, entry.name)\n const target = path.join(to, entry.name)\n if (entry.isDirectory()) {\n fs.mkdirSync(target, { recursive: true })\n copied += copyTree(source, target, (n) => n === 'node_modules' || n === '.git')\n } else if (entry.isFile()) {\n fs.mkdirSync(path.dirname(target), { recursive: true })\n fs.copyFileSync(source, target)\n copied++\n }\n }\n return copied\n}\n\n/**\n * Local files that are not part of an SPL when it is uploaded: a repository's own, caches, installed packages, and products (they\n * are repositories of their own).\n */\nconst notUploaded = (lineDir: string, name: string): boolean =>\n name === '.git' || name === '.linea' || name === 'node_modules' || fs.existsSync(path.join(lineDir, name, '.linea', 'spec.json'))\n\n/**\n * A folder made here becomes the checkout of a repository the host just made for it (with the scaffold of an SPL): what is here goes\n * on top of the scaffold, is committed and sent to the default branch, and the folder takes the repository over. Returns how many files\n * were sent and the default branch.\n */\nexport async function adoptFolder ({ dir, url, name, helper, onProgress }: { dir: string, url: string, name: string, helper: string, onProgress?: (what: 'getting' | 'uploading', line: string) => void }): Promise<{ copied: number, defaultBranch: string }> {\n const staging = fs.mkdtempSync(path.join(path.dirname(dir), `.${name}-link-`))\n try {\n const defaultBranch = await cloneRepository({ url, dest: staging, helper, ...(onProgress ? { onProgress: (l: string) => onProgress('getting', l) } : {}) })\n const copied = copyTree(dir, staging, (n) => notUploaded(dir, n))\n gitOk(staging, ['add', '-A'])\n if (git(staging, ['status', '--porcelain']).stdout.trim()) {\n gitOk(staging, ['commit', '--quiet', '-m', `Upload ${name} from the command line`])\n await gitOkAsync(staging, [...credentialOptions(url, helper), 'push', '--progress', 'origin', `HEAD:refs/heads/${defaultBranch}`], { ...(onProgress ? { onProgress: (l: string) => onProgress('uploading', l) } : {}) })\n }\n // the folder becomes the checkout: it takes the repository; its files are the ones just committed, plus what the scaffold had\n // that was not here (the README the host makes), which are brought into the folder\n fs.renameSync(path.join(staging, '.git'), path.join(dir, '.git'))\n gitOk(dir, ['checkout', '--quiet', '--', '.'])\n configureCredentials(dir, url, helper)\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n if (entry.isDirectory() && fs.existsSync(path.join(dir, entry.name, '.linea', 'spec.json'))) excludeFromGit(dir, `/${entry.name}/`)\n }\n return { copied, defaultBranch }\n } finally {\n fs.rmSync(staging, { recursive: true, force: true })\n }\n}\n\n// ---------------------------------------------------------------- packages\n\n/**\n * Gets a module or metamodel of the git host into a workspace to change it: a clone that remembers where it came from, and where\n * `publish` puts it back (the group on GitLab, the owner on GitHub). `repoPath` is `group/project` as the host knows it. Throws when\n * the host does not know it, or it is not a package of that kind.\n */\nexport async function clonePackage ({ provider, token, kind, repoPath, workdir, dest, helper, onProgress }: {\n provider: GitProvider\n token: string\n kind: PackageKind\n repoPath: string\n /** the workspace: the package goes to `<workdir>/modules/<name>` or `<workdir>/metamodels/<name>` unless `dest` says */\n workdir: string\n dest?: string\n helper: string\n onProgress?: Progress\n}): Promise<{ status: 'cloned' | 'present', name: string, dir: string, publishRoot?: string }> {\n const definition = KIND_DEFINITIONS[kind]\n const repository = await provider.findRepository({ token, path: repoPath })\n if (!repository) throw new Error(`No repository ${repoPath} on ${hostDescriptor(provider.kind).label} (or you cannot see it).`)\n if (!repository.topics.includes(definition.topic)) {\n throw new Error(`${repoPath} is not a ${kind} (its topics are ${repository.topics.join(', ') || 'none'}; a ${kind} has \"${definition.topic}\").`)\n }\n const dir = dest ?? path.join(workdir, definition.dir, repository.name)\n if (isRepo(dir) && readOrigin(dir)) return { status: 'present', name: repository.name, dir }\n if (fs.existsSync(dir) && fs.readdirSync(dir).length) throw new Error(`${dir} exists and is not empty.`)\n await cloneRepository({ url: cloneUrlOf(repository.webUrl), dest: dir, helper, ...(onProgress ? { onProgress } : {}) })\n\n // where to publish it again: GitLab keeps them under <group>/modules and <group>/metamodels, GitHub as repositories of an owner\n const parts = repository.path.split('/')\n const publishRoot = provider.kind === 'github' ? parts[0] : parts.at(-2) === definition.dir ? parts.slice(0, -2).join('/') : undefined\n writeOrigin(dir, {\n kind, name: repository.name, provider: provider.kind === 'github' ? 'github' : 'gitlab', projectId: repository.id, webUrl: repository.webUrl,\n defaultBranch: repository.defaultBranch ?? 'main', ...(publishRoot ? { publishRoot } : {})\n })\n return { status: 'cloned', name: repository.name, dir, ...(publishRoot ? { publishRoot } : {}) }\n}\n"]}
@@ -0,0 +1 @@
1
+ export declare const closingIssueNumbers: (...texts: (string | null | undefined)[]) => number[];
@@ -0,0 +1,14 @@
1
+ const REFERENCES = /\b(?:clos(?:e[sd]?|ing)|fix(?:e[sd]|ing)?|resolv(?:e[sd]?|ing)|implement(?:s|ed|ing)?)\b:?[ \t]+(#\d+(?:[ \t]*(?:,|and|&)[ \t]*#\d+)*)/gi;
2
+ export const closingIssueNumbers = (...texts) => {
3
+ const found = new Set();
4
+ for (const text of texts) {
5
+ if (!text)
6
+ continue;
7
+ for (const match of text.matchAll(REFERENCES)) {
8
+ for (const number of (match[1] ?? '').matchAll(/#(\d+)/g))
9
+ found.add(Number(number[1]));
10
+ }
11
+ }
12
+ return [...found];
13
+ };
14
+ //# sourceMappingURL=closing.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"closing.js","sourceRoot":"","sources":["../src/closing.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,0IAA0I,CAAA;AAE7J,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,KAAoC,EAAY,EAAE;IACvF,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAA;IAC/B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI;YAAE,SAAQ;QACnB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9C,KAAK,MAAM,MAAM,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,CAAC,SAAS,CAAC;gBAAE,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;QACzF,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,KAAK,CAAC,CAAA;AACnB,CAAC,CAAA","sourcesContent":["const REFERENCES = /\\b(?:clos(?:e[sd]?|ing)|fix(?:e[sd]|ing)?|resolv(?:e[sd]?|ing)|implement(?:s|ed|ing)?)\\b:?[ \\t]+(#\\d+(?:[ \\t]*(?:,|and|&)[ \\t]*#\\d+)*)/gi\n\nexport const closingIssueNumbers = (...texts: (string | null | undefined)[]): number[] => {\n const found = new Set<number>()\n for (const text of texts) {\n if (!text) continue\n for (const match of text.matchAll(REFERENCES)) {\n for (const number of (match[1] ?? '').matchAll(/#(\\d+)/g)) found.add(Number(number[1]))\n }\n }\n return [...found]\n}\n"]}
@@ -0,0 +1,53 @@
1
+ import type { GitHostKind } from './provider.js';
2
+ import type { GitHubConfig } from './github/config.js';
3
+ import type { GitLabConfig } from './gitlab/provider.js';
4
+ /**
5
+ * Which git host a deployment (or a command line) works on, and how to reach it. The server builds it from its environment
6
+ * (`gitConfigFromEnv`), the CLI from its own settings; nothing else in this library reads `process.env`.
7
+ */
8
+ export interface LocalConfig {
9
+ /** The folder the repositories live in. */
10
+ dataDir?: string | undefined;
11
+ /** Where the repositories are served (`<baseUrl>/<group>/<name>.git`). */
12
+ baseUrl?: string | undefined;
13
+ /** Top-level groups only their owner and the administrators write in (the registry); everybody else reads. */
14
+ readOnlyGroups?: string[] | undefined;
15
+ /** Whose token it is: the server's accounts (without it every token is the one user `local`). */
16
+ resolveUser?: ((token: string) => {
17
+ username: string;
18
+ avatarUrl?: string | undefined;
19
+ admin?: boolean | undefined;
20
+ } | null | Promise<{
21
+ username: string;
22
+ avatarUrl?: string | undefined;
23
+ admin?: boolean | undefined;
24
+ } | null>) | undefined;
25
+ }
26
+ export interface GitConfig {
27
+ /** The host the user's repositories live on. */
28
+ provider: GitHostKind;
29
+ gitlab?: GitLabConfig | undefined;
30
+ github?: GitHubConfig | undefined;
31
+ /** The repositories kept on the machine LINEA runs on (the `local` host). */
32
+ local?: LocalConfig | undefined;
33
+ /**
34
+ * Packages carry scripts that run in the process that checks them, so it can be limited to where they may come from: paths of
35
+ * GitLab groups or projects (`registry`, `team/modules`), and `github:<owner>` for GitHub. Empty: anywhere. Set, but with nothing for a
36
+ * host: nothing is read from that host.
37
+ */
38
+ trustedNamespaces?: string[] | undefined;
39
+ /** GitHub users or organisations whose packages (found by topic) are listed even when the deployment is not on GitHub. */
40
+ githubOwners?: string[] | undefined;
41
+ /** Where the catalog of registered packages is kept: a repository, such as `gitlab:linea/registry`. Unset: every package found by topic is listed. */
42
+ registry?: string | undefined;
43
+ }
44
+ /**
45
+ * The configuration the LINEA server has always been given:
46
+ * GIT_PROVIDER (gitlab by default | github | local)
47
+ * Local: LINEA_REPOS_DIR, LINEA_GIT_URL (where the repositories are served)
48
+ * GitLab: GITLAB_HOSTNAME, GITLAB_CLIENT_ID, GITLAB_SECRET_ID
49
+ * GitHub: GITHUB_URL, GITHUB_API_URL (or LINEA_GITHUB_API), GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, GITHUB_WEB_IDE_URL, GITHUB_TOKEN
50
+ * both: REDIRECT_URI (the address of the client; `/login` is added), LINEA_TRUSTED_NAMESPACES, LINEA_GITHUB_OWNERS,
51
+ * LINEA_REGISTRY (the repository that holds the catalog of registered packages, e.g. `gitlab:linea/registry`)
52
+ */
53
+ export declare const gitConfigFromEnv: (env?: Record<string, string | undefined>) => GitConfig;
package/dist/config.js ADDED
@@ -0,0 +1,40 @@
1
+ const list = (value) => (value ?? '').split(',').map((entry) => entry.trim()).filter(Boolean);
2
+ /**
3
+ * The configuration the LINEA server has always been given:
4
+ * GIT_PROVIDER (gitlab by default | github | local)
5
+ * Local: LINEA_REPOS_DIR, LINEA_GIT_URL (where the repositories are served)
6
+ * GitLab: GITLAB_HOSTNAME, GITLAB_CLIENT_ID, GITLAB_SECRET_ID
7
+ * GitHub: GITHUB_URL, GITHUB_API_URL (or LINEA_GITHUB_API), GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, GITHUB_WEB_IDE_URL, GITHUB_TOKEN
8
+ * both: REDIRECT_URI (the address of the client; `/login` is added), LINEA_TRUSTED_NAMESPACES, LINEA_GITHUB_OWNERS,
9
+ * LINEA_REGISTRY (the repository that holds the catalog of registered packages, e.g. `gitlab:linea/registry`)
10
+ */
11
+ export const gitConfigFromEnv = (env = process.env) => {
12
+ const provider = (env['GIT_PROVIDER'] ?? 'gitlab').toLowerCase();
13
+ if (provider !== 'gitlab' && provider !== 'github' && provider !== 'local') {
14
+ throw new Error(`GIT_PROVIDER=${provider} is not a git host this server knows (local, gitlab, github).`);
15
+ }
16
+ const redirectUri = `${env['REDIRECT_URI']}/login`;
17
+ return {
18
+ provider,
19
+ gitlab: {
20
+ url: env['GITLAB_HOSTNAME'] ?? '',
21
+ clientId: env['GITLAB_CLIENT_ID'],
22
+ clientSecret: env['GITLAB_SECRET_ID'],
23
+ redirectUri
24
+ },
25
+ github: {
26
+ webUrl: env['GITHUB_URL'],
27
+ apiUrl: env['GITHUB_API_URL'] ?? env['LINEA_GITHUB_API'],
28
+ clientId: env['GITHUB_CLIENT_ID'],
29
+ clientSecret: env['GITHUB_CLIENT_SECRET'],
30
+ redirectUri,
31
+ webIdeUrl: env['GITHUB_WEB_IDE_URL'],
32
+ token: env['GITHUB_TOKEN']
33
+ },
34
+ local: { dataDir: env['LINEA_REPOS_DIR'], baseUrl: env['LINEA_GIT_URL'] },
35
+ trustedNamespaces: list(env['LINEA_TRUSTED_NAMESPACES']),
36
+ githubOwners: list(env['LINEA_GITHUB_OWNERS']),
37
+ registry: env['LINEA_REGISTRY']?.trim() || undefined
38
+ };
39
+ };
40
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAsCA,MAAM,IAAI,GAAG,CAAC,KAAyB,EAAY,EAAE,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAA;AAE3H;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAA0C,OAAO,CAAC,GAAG,EAAa,EAAE;IACnG,MAAM,QAAQ,GAAG,CAAC,GAAG,CAAC,cAAc,CAAC,IAAI,QAAQ,CAAC,CAAC,WAAW,EAAE,CAAA;IAChE,IAAI,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,OAAO,EAAE,CAAC;QAC3E,MAAM,IAAI,KAAK,CAAC,gBAAgB,QAAQ,+DAA+D,CAAC,CAAA;IAC1G,CAAC;IACD,MAAM,WAAW,GAAG,GAAG,GAAG,CAAC,cAAc,CAAC,QAAQ,CAAA;IAClD,OAAO;QACL,QAAQ;QACR,MAAM,EAAE;YACN,GAAG,EAAE,GAAG,CAAC,iBAAiB,CAAC,IAAI,EAAE;YACjC,QAAQ,EAAE,GAAG,CAAC,kBAAkB,CAAC;YACjC,YAAY,EAAE,GAAG,CAAC,kBAAkB,CAAC;YACrC,WAAW;SACZ;QACD,MAAM,EAAE;YACN,MAAM,EAAE,GAAG,CAAC,YAAY,CAAC;YACzB,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAC,IAAI,GAAG,CAAC,kBAAkB,CAAC;YACxD,QAAQ,EAAE,GAAG,CAAC,kBAAkB,CAAC;YACjC,YAAY,EAAE,GAAG,CAAC,sBAAsB,CAAC;YACzC,WAAW;YACX,SAAS,EAAE,GAAG,CAAC,oBAAoB,CAAC;YACpC,KAAK,EAAE,GAAG,CAAC,cAAc,CAAC;SAC3B;QACD,KAAK,EAAE,EAAE,OAAO,EAAE,GAAG,CAAC,iBAAiB,CAAC,EAAE,OAAO,EAAE,GAAG,CAAC,eAAe,CAAC,EAAE;QACzE,iBAAiB,EAAE,IAAI,CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;QACxD,YAAY,EAAE,IAAI,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;QAC9C,QAAQ,EAAE,GAAG,CAAC,gBAAgB,CAAC,EAAE,IAAI,EAAE,IAAI,SAAS;KACrD,CAAA;AACH,CAAC,CAAA","sourcesContent":["import type { GitHostKind } from './provider.js'\nimport type { GitHubConfig } from './github/config.js'\nimport type { GitLabConfig } from './gitlab/provider.js'\n\n/**\n * Which git host a deployment (or a command line) works on, and how to reach it. The server builds it from its environment\n * (`gitConfigFromEnv`), the CLI from its own settings; nothing else in this library reads `process.env`.\n */\nexport interface LocalConfig {\n /** The folder the repositories live in. */\n dataDir?: string | undefined\n /** Where the repositories are served (`<baseUrl>/<group>/<name>.git`). */\n baseUrl?: string | undefined\n /** Top-level groups only their owner and the administrators write in (the registry); everybody else reads. */\n readOnlyGroups?: string[] | undefined\n /** Whose token it is: the server's accounts (without it every token is the one user `local`). */\n resolveUser?: ((token: string) => { username: string, avatarUrl?: string | undefined, admin?: boolean | undefined } | null | Promise<{ username: string, avatarUrl?: string | undefined, admin?: boolean | undefined } | null>) | undefined\n}\n\nexport interface GitConfig {\n /** The host the user's repositories live on. */\n provider: GitHostKind\n gitlab?: GitLabConfig | undefined\n github?: GitHubConfig | undefined\n /** The repositories kept on the machine LINEA runs on (the `local` host). */\n local?: LocalConfig | undefined\n /**\n * Packages carry scripts that run in the process that checks them, so it can be limited to where they may come from: paths of\n * GitLab groups or projects (`registry`, `team/modules`), and `github:<owner>` for GitHub. Empty: anywhere. Set, but with nothing for a\n * host: nothing is read from that host.\n */\n trustedNamespaces?: string[] | undefined\n /** GitHub users or organisations whose packages (found by topic) are listed even when the deployment is not on GitHub. */\n githubOwners?: string[] | undefined\n /** Where the catalog of registered packages is kept: a repository, such as `gitlab:linea/registry`. Unset: every package found by topic is listed. */\n registry?: string | undefined\n}\n\nconst list = (value: string | undefined): string[] => (value ?? '').split(',').map((entry) => entry.trim()).filter(Boolean)\n\n/**\n * The configuration the LINEA server has always been given:\n * GIT_PROVIDER (gitlab by default | github | local)\n * Local: LINEA_REPOS_DIR, LINEA_GIT_URL (where the repositories are served)\n * GitLab: GITLAB_HOSTNAME, GITLAB_CLIENT_ID, GITLAB_SECRET_ID\n * GitHub: GITHUB_URL, GITHUB_API_URL (or LINEA_GITHUB_API), GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET, GITHUB_WEB_IDE_URL, GITHUB_TOKEN\n * both: REDIRECT_URI (the address of the client; `/login` is added), LINEA_TRUSTED_NAMESPACES, LINEA_GITHUB_OWNERS,\n * LINEA_REGISTRY (the repository that holds the catalog of registered packages, e.g. `gitlab:linea/registry`)\n */\nexport const gitConfigFromEnv = (env: Record<string, string | undefined> = process.env): GitConfig => {\n const provider = (env['GIT_PROVIDER'] ?? 'gitlab').toLowerCase()\n if (provider !== 'gitlab' && provider !== 'github' && provider !== 'local') {\n throw new Error(`GIT_PROVIDER=${provider} is not a git host this server knows (local, gitlab, github).`)\n }\n const redirectUri = `${env['REDIRECT_URI']}/login`\n return {\n provider,\n gitlab: {\n url: env['GITLAB_HOSTNAME'] ?? '',\n clientId: env['GITLAB_CLIENT_ID'],\n clientSecret: env['GITLAB_SECRET_ID'],\n redirectUri\n },\n github: {\n webUrl: env['GITHUB_URL'],\n apiUrl: env['GITHUB_API_URL'] ?? env['LINEA_GITHUB_API'],\n clientId: env['GITHUB_CLIENT_ID'],\n clientSecret: env['GITHUB_CLIENT_SECRET'],\n redirectUri,\n webIdeUrl: env['GITHUB_WEB_IDE_URL'],\n token: env['GITHUB_TOKEN']\n },\n local: { dataDir: env['LINEA_REPOS_DIR'], baseUrl: env['LINEA_GIT_URL'] },\n trustedNamespaces: list(env['LINEA_TRUSTED_NAMESPACES']),\n githubOwners: list(env['LINEA_GITHUB_OWNERS']),\n registry: env['LINEA_REGISTRY']?.trim() || undefined\n }\n}\n"]}
@@ -0,0 +1,19 @@
1
+ import { type DeletableLine, type DeletableProduct, type LineDeletionPlan } from '@lbdudc/linea-core';
2
+ import type { GitProvider, Id } from './provider.js';
3
+ export declare const deleteLineOnHost: ({ provider, token, line, products, keepProductIds }: {
4
+ provider: GitProvider;
5
+ token: string;
6
+ line: DeletableLine;
7
+ products: DeletableProduct[];
8
+ keepProductIds?: string[];
9
+ }) => Promise<LineDeletionPlan>;
10
+ export declare const deleteProductOnHost: ({ provider, token, product }: {
11
+ provider: GitProvider;
12
+ token: string;
13
+ product: Pick<DeletableProduct, "repositoryId" | "namespaceId">;
14
+ }) => Promise<void>;
15
+ export declare const deleteEmptyLineNamespace: ({ provider, token, namespaceId }: {
16
+ provider: GitProvider;
17
+ token: string;
18
+ namespaceId: Id;
19
+ }) => Promise<void>;
@@ -0,0 +1,27 @@
1
+ import { planLineDeletion, planProductDeletion } from '@lbdudc/linea-core';
2
+ const isAlreadyGone = (error) => {
3
+ const { status, message } = error;
4
+ return status === 404 || (status === 400 && /already (been )?marked for deletion/i.test(message ?? ''));
5
+ };
6
+ const run = async ({ provider, token, steps }) => {
7
+ for (const { kind, id } of steps) {
8
+ try {
9
+ if (kind === 'repository')
10
+ await provider.deleteRepository({ token, id });
11
+ else
12
+ await provider.deleteNamespace({ token, id });
13
+ }
14
+ catch (error) {
15
+ if (!isAlreadyGone(error))
16
+ throw error;
17
+ }
18
+ }
19
+ };
20
+ export const deleteLineOnHost = async ({ provider, token, line, products, keepProductIds }) => {
21
+ const plan = planLineDeletion({ line, products, keepProductIds: keepProductIds ?? [], host: provider.capabilities().deletion });
22
+ await run({ provider, token, steps: plan.steps });
23
+ return plan;
24
+ };
25
+ export const deleteProductOnHost = ({ provider, token, product }) => run({ provider, token, steps: planProductDeletion({ product, host: provider.capabilities().deletion }) });
26
+ export const deleteEmptyLineNamespace = ({ provider, token, namespaceId }) => (run({ provider, token, steps: [{ kind: 'namespace', id: namespaceId }] }));
27
+ //# sourceMappingURL=deletion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deletion.js","sourceRoot":"","sources":["../src/deletion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAAE,mBAAmB,EAEtC,MAAM,oBAAoB,CAAA;AAG3B,MAAM,aAAa,GAAG,CAAC,KAAc,EAAW,EAAE;IAChD,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,KAA8C,CAAA;IAC1E,OAAO,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,KAAK,GAAG,IAAI,sCAAsC,CAAC,IAAI,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAA;AACzG,CAAC,CAAA;AAED,MAAM,GAAG,GAAG,KAAK,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAmE,EAAiB,EAAE;IAC/H,KAAK,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,KA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,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,CAC1E,CAAA","sourcesContent":["import {\n planLineDeletion, planProductDeletion,\n type DeletableLine, type DeletableProduct, type DeletionStep, type LineDeletionPlan\n} from '@lbdudc/linea-core'\nimport type { GitProvider, Id } from './provider.js'\n\nconst isAlreadyGone = (error: unknown): boolean => {\n const { status, message } = error as { status?: number, message?: string }\n return status === 404 || (status === 400 && /already (been )?marked for deletion/i.test(message ?? ''))\n}\n\nconst run = async ({ provider, token, steps }: { provider: GitProvider, token: string, steps: DeletionStep[] }): Promise<void> => {\n for (const { kind, id } of steps) {\n try {\n if (kind === 'repository') await provider.deleteRepository({ token, id })\n else await provider.deleteNamespace({ token, id })\n } catch (error) {\n if (!isAlreadyGone(error)) throw error\n }\n }\n}\n\nexport const deleteLineOnHost = async ({ provider, token, line, products, keepProductIds }: {\n provider: GitProvider\n token: string\n line: DeletableLine\n products: DeletableProduct[]\n keepProductIds?: string[]\n}): Promise<LineDeletionPlan> => {\n const plan = planLineDeletion({ line, products, keepProductIds: keepProductIds ?? [], host: provider.capabilities().deletion })\n await run({ provider, token, steps: plan.steps })\n return plan\n}\n\nexport const deleteProductOnHost = ({ provider, token, product }: {\n provider: GitProvider\n token: string\n product: Pick<DeletableProduct, 'repositoryId' | 'namespaceId'>\n}): Promise<void> => run({ provider, token, steps: planProductDeletion({ product, host: provider.capabilities().deletion }) })\n\nexport const deleteEmptyLineNamespace = ({ provider, token, namespaceId }: { provider: GitProvider, token: string, namespaceId: Id }): Promise<void> => (\n run({ provider, token, steps: [{ kind: 'namespace', id: namespaceId }] })\n)\n"]}
@@ -0,0 +1,26 @@
1
+ /** The token is expired or revoked. Hosts raise their own class (GitLab's, from gitlab-commando); this one is for providers that have none. */
2
+ export declare class GitAuthError extends Error {
3
+ status: number;
4
+ constructor(message?: string);
5
+ }
6
+ /** The host refused or failed a request; `status` is the HTTP status when there was one. */
7
+ export declare class GitError extends Error {
8
+ status?: number;
9
+ constructor(message: string, status?: number);
10
+ }
11
+ /** A package from a place the deployment does not trust (packages carry scripts that run in the server). */
12
+ export declare class PackageNotAllowedError extends Error {
13
+ constructor(message: string);
14
+ }
15
+ /** There is no such package (or it is not a module / metamodel as asked). */
16
+ export declare class PackageNotFoundError extends Error {
17
+ constructor(message?: string);
18
+ }
19
+ /** The version is already published: a tag does not move. */
20
+ export declare class PackageVersionExistsError extends Error {
21
+ constructor(message: string);
22
+ }
23
+ /** The version of a manifest cannot be published: it is not semver, or it is not greater than the last one published. */
24
+ export declare class PackageVersionInvalidError extends Error {
25
+ constructor(message: string);
26
+ }
package/dist/errors.js ADDED
@@ -0,0 +1,47 @@
1
+ /** The token is expired or revoked. Hosts raise their own class (GitLab's, from gitlab-commando); this one is for providers that have none. */
2
+ export class GitAuthError extends Error {
3
+ status = 401;
4
+ constructor(message = 'unauthorized') {
5
+ super(message);
6
+ this.name = 'GitAuthError';
7
+ }
8
+ }
9
+ /** The host refused or failed a request; `status` is the HTTP status when there was one. */
10
+ export class GitError extends Error {
11
+ status;
12
+ constructor(message, status) {
13
+ super(message);
14
+ this.name = 'GitError';
15
+ if (status !== undefined)
16
+ this.status = status;
17
+ }
18
+ }
19
+ /** A package from a place the deployment does not trust (packages carry scripts that run in the server). */
20
+ export class PackageNotAllowedError extends Error {
21
+ constructor(message) {
22
+ super(message);
23
+ this.name = 'PackageNotAllowedError';
24
+ }
25
+ }
26
+ /** There is no such package (or it is not a module / metamodel as asked). */
27
+ export class PackageNotFoundError extends Error {
28
+ constructor(message = 'Package not found') {
29
+ super(message);
30
+ this.name = 'PackageNotFoundError';
31
+ }
32
+ }
33
+ /** The version is already published: a tag does not move. */
34
+ export class PackageVersionExistsError extends Error {
35
+ constructor(message) {
36
+ super(message);
37
+ this.name = 'PackageVersionExistsError';
38
+ }
39
+ }
40
+ /** The version of a manifest cannot be published: it is not semver, or it is not greater than the last one published. */
41
+ export class PackageVersionInvalidError extends Error {
42
+ constructor(message) {
43
+ super(message);
44
+ this.name = 'PackageVersionInvalidError';
45
+ }
46
+ }
47
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,+IAA+I;AAC/I,MAAM,OAAO,YAAa,SAAQ,KAAK;IACrC,MAAM,GAAG,GAAG,CAAA;IAEZ,YAAY,OAAO,GAAG,cAAc;QAClC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,cAAc,CAAA;IAC5B,CAAC;CACF;AAED,4FAA4F;AAC5F,MAAM,OAAO,QAAS,SAAQ,KAAK;IACjC,MAAM,CAAS;IAEf,YAAY,OAAe,EAAE,MAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,UAAU,CAAA;QACtB,IAAI,MAAM,KAAK,SAAS;YAAE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IAChD,CAAC;CACF;AAED,4GAA4G;AAC5G,MAAM,OAAO,sBAAuB,SAAQ,KAAK;IAC/C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,wBAAwB,CAAA;IACtC,CAAC;CACF;AAED,6EAA6E;AAC7E,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,YAAY,OAAO,GAAG,mBAAmB;QACvC,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF;AAED,6DAA6D;AAC7D,MAAM,OAAO,yBAA0B,SAAQ,KAAK;IAClD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAA;IACzC,CAAC;CACF;AAED,yHAAyH;AACzH,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAA;IAC1C,CAAC;CACF","sourcesContent":["/** The token is expired or revoked. Hosts raise their own class (GitLab's, from gitlab-commando); this one is for providers that have none. */\nexport class GitAuthError extends Error {\n status = 401\n\n constructor(message = 'unauthorized') {\n super(message)\n this.name = 'GitAuthError'\n }\n}\n\n/** The host refused or failed a request; `status` is the HTTP status when there was one. */\nexport class GitError extends Error {\n status?: number\n\n constructor(message: string, status?: number) {\n super(message)\n this.name = 'GitError'\n if (status !== undefined) this.status = status\n }\n}\n\n/** A package from a place the deployment does not trust (packages carry scripts that run in the server). */\nexport class PackageNotAllowedError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'PackageNotAllowedError'\n }\n}\n\n/** There is no such package (or it is not a module / metamodel as asked). */\nexport class PackageNotFoundError extends Error {\n constructor(message = 'Package not found') {\n super(message)\n this.name = 'PackageNotFoundError'\n }\n}\n\n/** The version is already published: a tag does not move. */\nexport class PackageVersionExistsError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'PackageVersionExistsError'\n }\n}\n\n/** The version of a manifest cannot be published: it is not semver, or it is not greater than the last one published. */\nexport class PackageVersionInvalidError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'PackageVersionInvalidError'\n }\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import type { GitConfig } from './config.js';
2
+ import type { GitProvider } from './provider.js';
3
+ /** How a host is made: the provider for a configuration, and what its cached reads are keyed by (one cache per host address). */
4
+ export interface GitProviderRegistration {
5
+ create: (config: GitConfig) => GitProvider;
6
+ cacheKey: (config: GitConfig) => string;
7
+ }
8
+ /**
9
+ * Teaches `createGitProvider` a host. GitLab, GitHub and the local host are built in; a program can register another one by name.
10
+ */
11
+ export declare const registerGitProvider: (kind: string, registration: GitProviderRegistration) => void;
12
+ export declare const unregisterGitProvider: (kind: string) => boolean;
13
+ export declare const gitProviderKinds: () => string[];
14
+ /**
15
+ * A provider of the host `config` names. Each call returns a new one, because a provider remembers what it did so that `rollback()` can
16
+ * undo it: take one per operation.
17
+ */
18
+ export declare const createGitProvider: (config: GitConfig) => GitProvider;
19
+ /** `createGitProvider` with the configuration fixed: what a server calls once per operation. */
20
+ export declare const gitProviderFactory: (config: GitConfig | (() => GitConfig)) => (() => GitProvider);
@@ -0,0 +1,46 @@
1
+ import { GitHubProvider } from './github/provider.js';
2
+ import { GitLabProvider } from './gitlab/provider.js';
3
+ import { LocalProvider } from './local/provider.js';
4
+ import { withReadCache } from './read-cache.js';
5
+ const registrations = new Map();
6
+ /**
7
+ * Teaches `createGitProvider` a host. GitLab, GitHub and the local host are built in; a program can register another one by name.
8
+ */
9
+ export const registerGitProvider = (kind, registration) => {
10
+ registrations.set(kind, registration);
11
+ };
12
+ export const unregisterGitProvider = (kind) => registrations.delete(kind);
13
+ export const gitProviderKinds = () => [...registrations.keys()];
14
+ registerGitProvider('local', {
15
+ create: (config) => {
16
+ if (!config.local?.dataDir)
17
+ throw new Error('The local git host needs a folder for the repositories (LINEA_REPOS_DIR).');
18
+ return new LocalProvider({ ...config.local, dataDir: config.local.dataDir, redirectUri: config.gitlab?.redirectUri });
19
+ },
20
+ cacheKey: (config) => `local|${config.local?.dataDir ?? ''}`,
21
+ });
22
+ registerGitProvider('github', {
23
+ create: (config) => new GitHubProvider({ config: config.github ?? {} }),
24
+ cacheKey: (config) => `github|${config.github?.apiUrl ?? ''}`,
25
+ });
26
+ registerGitProvider('gitlab', {
27
+ create: (config) => {
28
+ if (!config.gitlab?.url)
29
+ throw new Error('GitLab is the git host, but no address was given for it (GITLAB_HOSTNAME).');
30
+ return new GitLabProvider(config.gitlab);
31
+ },
32
+ cacheKey: (config) => `gitlab|${config.gitlab?.url ?? ''}`,
33
+ });
34
+ /**
35
+ * A provider of the host `config` names. Each call returns a new one, because a provider remembers what it did so that `rollback()` can
36
+ * undo it: take one per operation.
37
+ */
38
+ export const createGitProvider = (config) => {
39
+ const registration = registrations.get(config.provider);
40
+ if (!registration)
41
+ throw new Error(`${config.provider} is not a git host this program offers (${gitProviderKinds().join(', ') || 'none'}).`);
42
+ return withReadCache(registration.create(config), registration.cacheKey(config));
43
+ };
44
+ /** `createGitProvider` with the configuration fixed: what a server calls once per operation. */
45
+ export const gitProviderFactory = (config) => () => createGitProvider(typeof config === 'function' ? config() : config);
46
+ //# sourceMappingURL=factory.js.map