@lbdudc/linea-git 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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,308 @@
1
+ import express from 'express';
2
+ import { spawn } from 'child_process';
3
+ import fs from 'fs';
4
+ import os from 'os';
5
+ import path from 'path';
6
+ /**
7
+ * Git over HTTP for the in-memory hosts, so `git clone`, `git pull` and `git push` work against them as against the real thing.
8
+ *
9
+ * The doubles keep a repository as plain maps (commits with their files, branches, tags). Real git needs a real repository, so each
10
+ * project gets a bare one on disk that is kept in step with the map, lazily and in both directions:
11
+ *
12
+ * - before git is served, whatever the REST API changed since is written into the bare repository (`fromModel`);
13
+ * - after a push, whatever git received is read back into the map (`toModel`), *before* the answer goes to the client, so a call to
14
+ * the REST API that follows (open a merge request for the branch just pushed) sees it.
15
+ *
16
+ * What differs between the doubles is behind an adapter:
17
+ * commits(): [{ id, parents, message, date, authorName, authorEmail, files: Map<path, Buffer> }]
18
+ * heads(): Map<branch, commitId> tags(): Map<tag, commitId> defaultBranch(): string
19
+ * addCommit({ id, parents, message, date, authorName, authorEmail, files }) setHead(name, id | null) setTag(name, id | null)
20
+ *
21
+ * The transport is `git http-backend` (the CGI git ships with), so the protocol is git's own. A request without credentials is
22
+ * asked for them (401), as a host does, so a credential helper gets its chance; what they are is not looked at.
23
+ */
24
+ const run = (cwd, args, { input, env } = {}) => new Promise((resolve, reject) => {
25
+ const child = spawn('git', args, { cwd, env: { ...process.env, ...env, GIT_TERMINAL_PROMPT: '0' }, windowsHide: true });
26
+ const out = [];
27
+ const err = [];
28
+ child.stdout.on('data', (d) => out.push(d));
29
+ child.stderr.on('data', (d) => err.push(d));
30
+ child.on('error', reject);
31
+ child.on('close', (code) => {
32
+ const stdout = Buffer.concat(out);
33
+ if (code !== 0)
34
+ return reject(new Error(`git ${args.join(' ')}: ${Buffer.concat(err).toString('utf8').trim() || `exit ${code}`}`));
35
+ resolve(stdout);
36
+ });
37
+ child.stdin.on('error', () => { });
38
+ child.stdin.end(input);
39
+ });
40
+ const text = async (cwd, args, opts) => (await run(cwd, args, opts)).toString('utf8');
41
+ const quote = (p) => `"${p.replace(/\\/g, '\\\\').replace(/"/g, '\\"').replace(/\n/g, '\\n')}"`;
42
+ class GitMirror {
43
+ constructor({ dir, adapter }) {
44
+ this.dir = dir;
45
+ this.adapter = adapter;
46
+ this.toGit = new Map(); // model commit id → git sha
47
+ this.toModel = new Map(); // git sha → model commit id
48
+ this.ready = false;
49
+ this.queue = Promise.resolve();
50
+ }
51
+ /** One thing at a time per repository: a push and a fetch must not see each other half done. */
52
+ exclusive(fn) {
53
+ const next = this.queue.then(fn, fn);
54
+ this.queue = next.catch(() => { });
55
+ return next;
56
+ }
57
+ async init() {
58
+ if (this.ready)
59
+ return;
60
+ fs.mkdirSync(this.dir, { recursive: true });
61
+ await run(this.dir, ['init', '--bare', '--quiet', '.']);
62
+ await run(this.dir, ['config', 'http.receivepack', 'true']);
63
+ await run(this.dir, ['config', 'receive.denyCurrentBranch', 'ignore']);
64
+ await run(this.dir, ['config', 'uploadpack.allowAnySHA1InWant', 'true']);
65
+ this.ready = true;
66
+ }
67
+ /** The model's commits that are not in git yet, parents first. */
68
+ #pending() {
69
+ const byId = new Map(this.adapter.commits().map((c) => [c.id, c]));
70
+ const ordered = [];
71
+ const seen = new Set();
72
+ const visit = (id) => {
73
+ if (seen.has(id) || this.toGit.has(id) || !byId.has(id))
74
+ return;
75
+ seen.add(id);
76
+ for (const parent of byId.get(id).parents)
77
+ visit(parent);
78
+ ordered.push(byId.get(id));
79
+ };
80
+ for (const id of byId.keys())
81
+ visit(id);
82
+ return ordered;
83
+ }
84
+ async fromModel() {
85
+ await this.init();
86
+ const batch = this.#pending();
87
+ if (batch.length) {
88
+ const marks = new Map();
89
+ const parts = [];
90
+ const ref = (id) => (marks.has(id) ? `:${marks.get(id)}` : this.toGit.get(id));
91
+ batch.forEach((c, i) => {
92
+ marks.set(c.id, i + 1);
93
+ const message = Buffer.from(`${c.message || '(no message)'}\n`);
94
+ const when = Math.floor(new Date(c.date).getTime() / 1000) || 0;
95
+ const who = `${(c.authorName || 'dev').replace(/[<>\n]/g, '')} <${c.authorEmail || 'dev@example.com'}>`;
96
+ parts.push(Buffer.from(`reset refs/linea/import\ncommit refs/linea/import\nmark :${i + 1}\ncommitter ${who} ${when} +0000\ndata ${message.length}\n`), message);
97
+ c.parents.forEach((parent, n) => parts.push(Buffer.from(`${n === 0 ? 'from' : 'merge'} ${ref(parent)}\n`)));
98
+ parts.push(Buffer.from('deleteall\n'));
99
+ for (const [file, content] of c.files) {
100
+ parts.push(Buffer.from(`M 100644 inline ${quote(file)}\ndata ${content.length}\n`), content, Buffer.from('\n'));
101
+ }
102
+ parts.push(Buffer.from('\n'));
103
+ });
104
+ const marksFile = path.join(this.dir, 'linea-marks');
105
+ await run(this.dir, ['fast-import', '--quiet', `--export-marks=${marksFile}`], { input: Buffer.concat(parts) });
106
+ for (const line of fs.readFileSync(marksFile, 'utf8').split('\n').filter(Boolean)) {
107
+ const [mark, sha] = line.split(' ');
108
+ const commit = batch[Number(mark.slice(1)) - 1];
109
+ this.toGit.set(commit.id, sha);
110
+ this.toModel.set(sha, commit.id);
111
+ }
112
+ await run(this.dir, ['update-ref', '-d', 'refs/linea/import']).catch(() => { });
113
+ }
114
+ const updates = [];
115
+ const want = new Set();
116
+ for (const [name, id] of this.adapter.heads()) {
117
+ const sha = this.toGit.get(id);
118
+ if (!sha)
119
+ continue;
120
+ want.add(`refs/heads/${name}`);
121
+ updates.push(`update refs/heads/${name} ${sha}\n`);
122
+ }
123
+ for (const [name, id] of this.adapter.tags()) {
124
+ const sha = this.toGit.get(id);
125
+ if (!sha)
126
+ continue;
127
+ want.add(`refs/tags/${name}`);
128
+ updates.push(`update refs/tags/${name} ${sha}\n`);
129
+ }
130
+ for (const [refname] of await this.refs())
131
+ if (!want.has(refname))
132
+ updates.push(`delete ${refname}\n`);
133
+ if (updates.length)
134
+ await run(this.dir, ['update-ref', '--stdin'], { input: updates.join('') });
135
+ const head = this.adapter.defaultBranch();
136
+ if (head)
137
+ await run(this.dir, ['symbolic-ref', 'HEAD', `refs/heads/${head}`]);
138
+ }
139
+ /** `refs/heads/*` and `refs/tags/*` as they are in git, tags peeled to the commit they point at. */
140
+ async refs() {
141
+ const out = await text(this.dir, ['for-each-ref', '--format=%(refname)\t%(objectname)\t%(*objectname)', 'refs/heads', 'refs/tags']);
142
+ const map = new Map();
143
+ for (const line of out.split('\n').filter(Boolean)) {
144
+ const [name, sha, peeled] = line.split('\t');
145
+ map.set(name, peeled || sha);
146
+ }
147
+ return map;
148
+ }
149
+ /** Reads what a push left in git into the model: the new commits, then the branches and tags. `before` is `refs()` from before the push. */
150
+ async toModelFrom(before) {
151
+ const after = await this.refs();
152
+ const heads = [...after.values()].filter((sha) => !this.toModel.has(sha));
153
+ if (heads.length) {
154
+ const input = [...new Set(heads)].join('\n') + '\n' + [...this.toModel.keys()].map((sha) => `^${sha}`).join('\n') + '\n';
155
+ const shas = (await text(this.dir, ['rev-list', '--reverse', '--topo-order', '--stdin'], { input })).split('\n').filter(Boolean);
156
+ for (const sha of shas) {
157
+ const [parents, name, email, date, message] = (await text(this.dir, ['show', '-s', '--format=%P%x00%an%x00%ae%x00%aI%x00%B', sha])).split('\0');
158
+ const files = new Map();
159
+ const listing = (await run(this.dir, ['ls-tree', '-r', '-z', '--full-tree', sha])).toString('utf8').split('\0').filter(Boolean);
160
+ const entries = listing.map((entry) => {
161
+ const [meta, file] = entry.split('\t');
162
+ const [mode, type, blob] = meta.split(' ');
163
+ return { mode, type, blob, file };
164
+ }).filter((e) => e.type === 'blob');
165
+ if (entries.length) {
166
+ const batch = await run(this.dir, ['cat-file', '--batch'], { input: entries.map((e) => e.blob).join('\n') + '\n' });
167
+ let offset = 0;
168
+ for (const entry of entries) {
169
+ const eol = batch.indexOf(0x0a, offset);
170
+ const [, , size] = batch.subarray(offset, eol).toString('utf8').split(' ');
171
+ files.set(entry.file, Buffer.from(batch.subarray(eol + 1, eol + 1 + Number(size))));
172
+ offset = eol + 1 + Number(size) + 1;
173
+ }
174
+ }
175
+ const id = this.adapter.addCommit({
176
+ id: sha,
177
+ parents: parents.split(' ').filter(Boolean).map((p) => this.toModel.get(p)),
178
+ message: message.replace(/\n+$/, ''),
179
+ date,
180
+ authorName: name,
181
+ authorEmail: email,
182
+ files,
183
+ });
184
+ this.toGit.set(id, sha);
185
+ this.toModel.set(sha, id);
186
+ }
187
+ }
188
+ for (const [refname, sha] of after) {
189
+ if (before.get(refname) === sha)
190
+ continue;
191
+ const id = this.toModel.get(sha);
192
+ if (refname.startsWith('refs/heads/'))
193
+ this.adapter.setHead(refname.slice('refs/heads/'.length), id);
194
+ else if (refname.startsWith('refs/tags/'))
195
+ this.adapter.setTag(refname.slice('refs/tags/'.length), id);
196
+ }
197
+ for (const refname of before.keys()) {
198
+ if (after.has(refname))
199
+ continue;
200
+ if (refname.startsWith('refs/heads/'))
201
+ this.adapter.setHead(refname.slice('refs/heads/'.length), null);
202
+ else if (refname.startsWith('refs/tags/'))
203
+ this.adapter.setTag(refname.slice('refs/tags/'.length), null);
204
+ }
205
+ }
206
+ /** `git http-backend` for this request; the answer, whole (a push is only answered once the model has it). */
207
+ cgi(req, pathInfo, repoDir) {
208
+ return new Promise((resolve, reject) => {
209
+ const env = {
210
+ ...process.env,
211
+ GIT_PROJECT_ROOT: path.dirname(repoDir),
212
+ GIT_HTTP_EXPORT_ALL: '1',
213
+ PATH_INFO: `/${path.basename(repoDir)}${pathInfo}`,
214
+ REQUEST_METHOD: req.method,
215
+ QUERY_STRING: req.url.includes('?') ? req.url.slice(req.url.indexOf('?') + 1) : '',
216
+ CONTENT_TYPE: req.headers['content-type'] ?? '',
217
+ REMOTE_USER: 'dev',
218
+ REMOTE_ADDR: '127.0.0.1',
219
+ ...(req.headers['content-length'] ? { CONTENT_LENGTH: req.headers['content-length'] } : {}),
220
+ ...(req.headers['content-encoding'] ? { HTTP_CONTENT_ENCODING: req.headers['content-encoding'] } : {}),
221
+ ...(req.headers['git-protocol'] ? { GIT_PROTOCOL: req.headers['git-protocol'] } : {}),
222
+ };
223
+ const child = spawn('git', ['http-backend'], { env, windowsHide: true });
224
+ const out = [];
225
+ const err = [];
226
+ child.stdout.on('data', (d) => out.push(d));
227
+ child.stderr.on('data', (d) => err.push(d));
228
+ child.on('error', reject);
229
+ child.stdin.on('error', () => { });
230
+ req.pipe(child.stdin);
231
+ child.on('close', () => {
232
+ const raw = Buffer.concat(out);
233
+ const split = raw.indexOf('\r\n\r\n');
234
+ if (split < 0)
235
+ return reject(new Error(`git http-backend: ${Buffer.concat(err).toString('utf8') || 'no answer'}`));
236
+ const headers = {};
237
+ let status = 200;
238
+ for (const line of raw.subarray(0, split).toString('utf8').split('\r\n')) {
239
+ const i = line.indexOf(':');
240
+ if (i < 0)
241
+ continue;
242
+ const key = line.slice(0, i).trim();
243
+ const value = line.slice(i + 1).trim();
244
+ if (key.toLowerCase() === 'status')
245
+ status = Number.parseInt(value, 10);
246
+ else
247
+ headers[key] = value;
248
+ }
249
+ resolve({ status, headers, body: raw.subarray(split + 4) });
250
+ });
251
+ });
252
+ }
253
+ }
254
+ /**
255
+ * The router that serves `<full path>.git/...` for a double. `find(fullPath)` gives the project (or nothing), `adapterOf(project)` how
256
+ * to read and write its model. Returns the router, and `dispose()` to remove what was written to disk.
257
+ */
258
+ export function createGitHttp({ find, adapterOf }) {
259
+ const root = fs.mkdtempSync(path.join(os.tmpdir(), 'linea-git-double-'));
260
+ const mirrors = new Map();
261
+ let counter = 0;
262
+ const mirrorOf = (project) => {
263
+ let mirror = mirrors.get(project);
264
+ if (!mirror) {
265
+ mirror = new GitMirror({ dir: path.join(root, `repo${++counter}.git`), adapter: adapterOf(project) });
266
+ mirrors.set(project, mirror);
267
+ }
268
+ return mirror;
269
+ };
270
+ const router = express.Router();
271
+ router.use(async (req, res, next) => {
272
+ const m = /^\/(.+?)\.git(\/.*)$/.exec(req.path);
273
+ if (!m)
274
+ return next();
275
+ if (!req.headers.authorization) {
276
+ res.set('WWW-Authenticate', 'Basic realm="git"');
277
+ return res.status(401).send('Authentication required');
278
+ }
279
+ const project = find(decodeURIComponent(m[1]));
280
+ if (!project)
281
+ return res.status(404).send('Repository not found');
282
+ const mirror = mirrorOf(project);
283
+ try {
284
+ const answer = await mirror.exclusive(async () => {
285
+ await mirror.fromModel();
286
+ const pushes = m[2].endsWith('git-receive-pack') && req.method === 'POST';
287
+ const before = pushes ? await mirror.refs() : undefined;
288
+ const result = await mirror.cgi(req, m[2], mirror.dir);
289
+ if (before)
290
+ await mirror.toModelFrom(before);
291
+ return result;
292
+ });
293
+ res.status(answer.status);
294
+ for (const [name, value] of Object.entries(answer.headers))
295
+ res.set(name, value);
296
+ res.send(answer.body);
297
+ }
298
+ catch (error) {
299
+ res.status(500).send(String(error.message ?? error));
300
+ }
301
+ });
302
+ return {
303
+ router,
304
+ reset: () => mirrors.clear(),
305
+ dispose: () => fs.rmSync(root, { recursive: true, force: true }),
306
+ };
307
+ }
308
+ //# sourceMappingURL=git-http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"git-http.js","sourceRoot":"","sources":["../../src/testing/git-http.js"],"names":[],"mappings":"AAAA,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,EAAE,MAAM,IAA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AAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;gBACxD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;gBACvD,IAAI,MAAM;oBAAE,MAAM,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;gBAC7C,OAAO,MAAM,CAAC;YAChB,CAAC,CAAC,CAAC;YACH,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YAC1B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;gBAAE,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YACjF,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QACxB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,IAAI,KAAK,CAAC,CAAC,CAAC;QACvD,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,MAAM;QACN,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE;QAC5B,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;KACjE,CAAC;AACJ,CAAC","sourcesContent":["import express from 'express';\nimport { spawn } from 'child_process';\nimport fs from 'fs';\nimport os from 'os';\nimport path from 'path';\n\n/**\n * Git over HTTP for the in-memory hosts, so `git clone`, `git pull` and `git push` work against them as against the real thing.\n *\n * The doubles keep a repository as plain maps (commits with their files, branches, tags). Real git needs a real repository, so each\n * project gets a bare one on disk that is kept in step with the map, lazily and in both directions:\n *\n * - before git is served, whatever the REST API changed since is written into the bare repository (`fromModel`);\n * - after a push, whatever git received is read back into the map (`toModel`), *before* the answer goes to the client, so a call to\n * the REST API that follows (open a merge request for the branch just pushed) sees it.\n *\n * What differs between the doubles is behind an adapter:\n * commits(): [{ id, parents, message, date, authorName, authorEmail, files: Map<path, Buffer> }]\n * heads(): Map<branch, commitId> tags(): Map<tag, commitId> defaultBranch(): string\n * addCommit({ id, parents, message, date, authorName, authorEmail, files }) setHead(name, id | null) setTag(name, id | null)\n *\n * The transport is `git http-backend` (the CGI git ships with), so the protocol is git's own. A request without credentials is\n * asked for them (401), as a host does, so a credential helper gets its chance; what they are is not looked at.\n */\n\nconst run = (cwd, args, { input, env } = {}) =>\n new Promise((resolve, reject) => {\n const child = spawn('git', args, { cwd, env: { ...process.env, ...env, GIT_TERMINAL_PROMPT: '0' }, windowsHide: true });\n const out = [];\n const err = [];\n child.stdout.on('data', (d) => out.push(d));\n child.stderr.on('data', (d) => err.push(d));\n child.on('error', reject);\n child.on('close', (code) => {\n const stdout = Buffer.concat(out);\n if (code !== 0) return reject(new Error(`git ${args.join(' ')}: ${Buffer.concat(err).toString('utf8').trim() || `exit ${code}`}`));\n resolve(stdout);\n });\n child.stdin.on('error', () => {});\n child.stdin.end(input);\n });\n\nconst text = async (cwd, args, opts) => (await run(cwd, args, opts)).toString('utf8');\n\nconst quote = (p) => `\"${p.replace(/\\\\/g, '\\\\\\\\').replace(/\"/g, '\\\\\"').replace(/\\n/g, '\\\\n')}\"`;\n\nclass GitMirror {\n constructor({ dir, adapter }) {\n this.dir = dir;\n this.adapter = adapter;\n this.toGit = new Map(); // model commit id → git sha\n this.toModel = new Map(); // git sha → model commit id\n this.ready = false;\n this.queue = Promise.resolve();\n }\n\n /** One thing at a time per repository: a push and a fetch must not see each other half done. */\n exclusive(fn) {\n const next = this.queue.then(fn, fn);\n this.queue = next.catch(() => {});\n return next;\n }\n\n async init() {\n if (this.ready) return;\n fs.mkdirSync(this.dir, { recursive: true });\n await run(this.dir, ['init', '--bare', '--quiet', '.']);\n await run(this.dir, ['config', 'http.receivepack', 'true']);\n await run(this.dir, ['config', 'receive.denyCurrentBranch', 'ignore']);\n await run(this.dir, ['config', 'uploadpack.allowAnySHA1InWant', 'true']);\n this.ready = true;\n }\n\n /** The model's commits that are not in git yet, parents first. */\n #pending() {\n const byId = new Map(this.adapter.commits().map((c) => [c.id, c]));\n const ordered = [];\n const seen = new Set();\n const visit = (id) => {\n if (seen.has(id) || this.toGit.has(id) || !byId.has(id)) return;\n seen.add(id);\n for (const parent of byId.get(id).parents) visit(parent);\n ordered.push(byId.get(id));\n };\n for (const id of byId.keys()) visit(id);\n return ordered;\n }\n\n async fromModel() {\n await this.init();\n const batch = this.#pending();\n if (batch.length) {\n const marks = new Map();\n const parts = [];\n const ref = (id) => (marks.has(id) ? `:${marks.get(id)}` : this.toGit.get(id));\n batch.forEach((c, i) => {\n marks.set(c.id, i + 1);\n const message = Buffer.from(`${c.message || '(no message)'}\\n`);\n const when = Math.floor(new Date(c.date).getTime() / 1000) || 0;\n const who = `${(c.authorName || 'dev').replace(/[<>\\n]/g, '')} <${c.authorEmail || 'dev@example.com'}>`;\n parts.push(Buffer.from(`reset refs/linea/import\\ncommit refs/linea/import\\nmark :${i + 1}\\ncommitter ${who} ${when} +0000\\ndata ${message.length}\\n`), message);\n c.parents.forEach((parent, n) => parts.push(Buffer.from(`${n === 0 ? 'from' : 'merge'} ${ref(parent)}\\n`)));\n parts.push(Buffer.from('deleteall\\n'));\n for (const [file, content] of c.files) {\n parts.push(Buffer.from(`M 100644 inline ${quote(file)}\\ndata ${content.length}\\n`), content, Buffer.from('\\n'));\n }\n parts.push(Buffer.from('\\n'));\n });\n const marksFile = path.join(this.dir, 'linea-marks');\n await run(this.dir, ['fast-import', '--quiet', `--export-marks=${marksFile}`], { input: Buffer.concat(parts) });\n for (const line of fs.readFileSync(marksFile, 'utf8').split('\\n').filter(Boolean)) {\n const [mark, sha] = line.split(' ');\n const commit = batch[Number(mark.slice(1)) - 1];\n this.toGit.set(commit.id, sha);\n this.toModel.set(sha, commit.id);\n }\n await run(this.dir, ['update-ref', '-d', 'refs/linea/import']).catch(() => {});\n }\n\n const updates = [];\n const want = new Set();\n for (const [name, id] of this.adapter.heads()) {\n const sha = this.toGit.get(id);\n if (!sha) continue;\n want.add(`refs/heads/${name}`);\n updates.push(`update refs/heads/${name} ${sha}\\n`);\n }\n for (const [name, id] of this.adapter.tags()) {\n const sha = this.toGit.get(id);\n if (!sha) continue;\n want.add(`refs/tags/${name}`);\n updates.push(`update refs/tags/${name} ${sha}\\n`);\n }\n for (const [refname] of await this.refs()) if (!want.has(refname)) updates.push(`delete ${refname}\\n`);\n if (updates.length) await run(this.dir, ['update-ref', '--stdin'], { input: updates.join('') });\n const head = this.adapter.defaultBranch();\n if (head) await run(this.dir, ['symbolic-ref', 'HEAD', `refs/heads/${head}`]);\n }\n\n /** `refs/heads/*` and `refs/tags/*` as they are in git, tags peeled to the commit they point at. */\n async refs() {\n const out = await text(this.dir, ['for-each-ref', '--format=%(refname)\\t%(objectname)\\t%(*objectname)', 'refs/heads', 'refs/tags']);\n const map = new Map();\n for (const line of out.split('\\n').filter(Boolean)) {\n const [name, sha, peeled] = line.split('\\t');\n map.set(name, peeled || sha);\n }\n return map;\n }\n\n /** Reads what a push left in git into the model: the new commits, then the branches and tags. `before` is `refs()` from before the push. */\n async toModelFrom(before) {\n const after = await this.refs();\n const heads = [...after.values()].filter((sha) => !this.toModel.has(sha));\n if (heads.length) {\n const input = [...new Set(heads)].join('\\n') + '\\n' + [...this.toModel.keys()].map((sha) => `^${sha}`).join('\\n') + '\\n';\n const shas = (await text(this.dir, ['rev-list', '--reverse', '--topo-order', '--stdin'], { input })).split('\\n').filter(Boolean);\n for (const sha of shas) {\n const [parents, name, email, date, message] = (await text(this.dir, ['show', '-s', '--format=%P%x00%an%x00%ae%x00%aI%x00%B', sha])).split('\\0');\n const files = new Map();\n const listing = (await run(this.dir, ['ls-tree', '-r', '-z', '--full-tree', sha])).toString('utf8').split('\\0').filter(Boolean);\n const entries = listing.map((entry) => {\n const [meta, file] = entry.split('\\t');\n const [mode, type, blob] = meta.split(' ');\n return { mode, type, blob, file };\n }).filter((e) => e.type === 'blob');\n if (entries.length) {\n const batch = await run(this.dir, ['cat-file', '--batch'], { input: entries.map((e) => e.blob).join('\\n') + '\\n' });\n let offset = 0;\n for (const entry of entries) {\n const eol = batch.indexOf(0x0a, offset);\n const [, , size] = batch.subarray(offset, eol).toString('utf8').split(' ');\n files.set(entry.file, Buffer.from(batch.subarray(eol + 1, eol + 1 + Number(size))));\n offset = eol + 1 + Number(size) + 1;\n }\n }\n const id = this.adapter.addCommit({\n id: sha,\n parents: parents.split(' ').filter(Boolean).map((p) => this.toModel.get(p)),\n message: message.replace(/\\n+$/, ''),\n date,\n authorName: name,\n authorEmail: email,\n files,\n });\n this.toGit.set(id, sha);\n this.toModel.set(sha, id);\n }\n }\n for (const [refname, sha] of after) {\n if (before.get(refname) === sha) continue;\n const id = this.toModel.get(sha);\n if (refname.startsWith('refs/heads/')) this.adapter.setHead(refname.slice('refs/heads/'.length), id);\n else if (refname.startsWith('refs/tags/')) this.adapter.setTag(refname.slice('refs/tags/'.length), id);\n }\n for (const refname of before.keys()) {\n if (after.has(refname)) continue;\n if (refname.startsWith('refs/heads/')) this.adapter.setHead(refname.slice('refs/heads/'.length), null);\n else if (refname.startsWith('refs/tags/')) this.adapter.setTag(refname.slice('refs/tags/'.length), null);\n }\n }\n\n /** `git http-backend` for this request; the answer, whole (a push is only answered once the model has it). */\n cgi(req, pathInfo, repoDir) {\n return new Promise((resolve, reject) => {\n const env = {\n ...process.env,\n GIT_PROJECT_ROOT: path.dirname(repoDir),\n GIT_HTTP_EXPORT_ALL: '1',\n PATH_INFO: `/${path.basename(repoDir)}${pathInfo}`,\n REQUEST_METHOD: req.method,\n QUERY_STRING: req.url.includes('?') ? req.url.slice(req.url.indexOf('?') + 1) : '',\n CONTENT_TYPE: req.headers['content-type'] ?? '',\n REMOTE_USER: 'dev',\n REMOTE_ADDR: '127.0.0.1',\n ...(req.headers['content-length'] ? { CONTENT_LENGTH: req.headers['content-length'] } : {}),\n ...(req.headers['content-encoding'] ? { HTTP_CONTENT_ENCODING: req.headers['content-encoding'] } : {}),\n ...(req.headers['git-protocol'] ? { GIT_PROTOCOL: req.headers['git-protocol'] } : {}),\n };\n const child = spawn('git', ['http-backend'], { env, windowsHide: true });\n const out = [];\n const err = [];\n child.stdout.on('data', (d) => out.push(d));\n child.stderr.on('data', (d) => err.push(d));\n child.on('error', reject);\n child.stdin.on('error', () => {});\n req.pipe(child.stdin);\n child.on('close', () => {\n const raw = Buffer.concat(out);\n const split = raw.indexOf('\\r\\n\\r\\n');\n if (split < 0) return reject(new Error(`git http-backend: ${Buffer.concat(err).toString('utf8') || 'no answer'}`));\n const headers = {};\n let status = 200;\n for (const line of raw.subarray(0, split).toString('utf8').split('\\r\\n')) {\n const i = line.indexOf(':');\n if (i < 0) continue;\n const key = line.slice(0, i).trim();\n const value = line.slice(i + 1).trim();\n if (key.toLowerCase() === 'status') status = Number.parseInt(value, 10);\n else headers[key] = value;\n }\n resolve({ status, headers, body: raw.subarray(split + 4) });\n });\n });\n }\n}\n\n/**\n * The router that serves `<full path>.git/...` for a double. `find(fullPath)` gives the project (or nothing), `adapterOf(project)` how\n * to read and write its model. Returns the router, and `dispose()` to remove what was written to disk.\n */\nexport function createGitHttp({ find, adapterOf }) {\n const root = fs.mkdtempSync(path.join(os.tmpdir(), 'linea-git-double-'));\n const mirrors = new Map();\n let counter = 0;\n\n const mirrorOf = (project) => {\n let mirror = mirrors.get(project);\n if (!mirror) {\n mirror = new GitMirror({ dir: path.join(root, `repo${++counter}.git`), adapter: adapterOf(project) });\n mirrors.set(project, mirror);\n }\n return mirror;\n };\n\n const router = express.Router();\n router.use(async (req, res, next) => {\n const m = /^\\/(.+?)\\.git(\\/.*)$/.exec(req.path);\n if (!m) return next();\n if (!req.headers.authorization) {\n res.set('WWW-Authenticate', 'Basic realm=\"git\"');\n return res.status(401).send('Authentication required');\n }\n const project = find(decodeURIComponent(m[1]));\n if (!project) return res.status(404).send('Repository not found');\n const mirror = mirrorOf(project);\n try {\n const answer = await mirror.exclusive(async () => {\n await mirror.fromModel();\n const pushes = m[2].endsWith('git-receive-pack') && req.method === 'POST';\n const before = pushes ? await mirror.refs() : undefined;\n const result = await mirror.cgi(req, m[2], mirror.dir);\n if (before) await mirror.toModelFrom(before);\n return result;\n });\n res.status(answer.status);\n for (const [name, value] of Object.entries(answer.headers)) res.set(name, value);\n res.send(answer.body);\n } catch (error) {\n res.status(500).send(String(error.message ?? error));\n }\n });\n\n return {\n router,\n reset: () => mirrors.clear(),\n dispose: () => fs.rmSync(root, { recursive: true, force: true }),\n };\n}\n"]}
@@ -0,0 +1,151 @@
1
+ export function createGithubDoubleApp(baseUrl?: string): {
2
+ app: import("express-serve-static-core").Express;
3
+ state: {
4
+ user: {
5
+ login: string;
6
+ id: number;
7
+ type: string;
8
+ };
9
+ orgs: Map<any, any>;
10
+ repos: Map<any, any>;
11
+ nextRepo: number;
12
+ nextAccount: number;
13
+ faults: never[];
14
+ log: never[];
15
+ reset(): void;
16
+ addOrg(login: any, role?: string): {
17
+ login: any;
18
+ id: number;
19
+ type: string;
20
+ role: string;
21
+ };
22
+ ownerOf(login: any): any;
23
+ createRepo({ owner, name, description, topics, defaultBranch, autoInit }: {
24
+ owner: any;
25
+ name: any;
26
+ description: any;
27
+ topics: any;
28
+ defaultBranch: any;
29
+ autoInit: any;
30
+ }): Repo;
31
+ find(fullName: any): any;
32
+ };
33
+ gitHttp: {
34
+ router: import("express-serve-static-core").Router;
35
+ reset: () => void;
36
+ dispose: () => void;
37
+ };
38
+ };
39
+ export function startGithubDouble(): Promise<{
40
+ url: string;
41
+ state: {
42
+ user: {
43
+ login: string;
44
+ id: number;
45
+ type: string;
46
+ };
47
+ orgs: Map<any, any>;
48
+ repos: Map<any, any>;
49
+ nextRepo: number;
50
+ nextAccount: number;
51
+ faults: never[];
52
+ log: never[];
53
+ reset(): void;
54
+ addOrg(login: any, role?: string): {
55
+ login: any;
56
+ id: number;
57
+ type: string;
58
+ role: string;
59
+ };
60
+ ownerOf(login: any): any;
61
+ createRepo({ owner, name, description, topics, defaultBranch, autoInit }: {
62
+ owner: any;
63
+ name: any;
64
+ description: any;
65
+ topics: any;
66
+ defaultBranch: any;
67
+ autoInit: any;
68
+ }): Repo;
69
+ find(fullName: any): any;
70
+ };
71
+ roles: {
72
+ admin: number;
73
+ maintain: number;
74
+ write: number;
75
+ triage: number;
76
+ read: number;
77
+ };
78
+ addOrg: (login: any, role: any) => {
79
+ login: any;
80
+ id: number;
81
+ type: string;
82
+ role: string;
83
+ };
84
+ setCollaborator: (repoId: any, login: any, role: any) => void;
85
+ addRun: (repoId: any, run: any) => any;
86
+ /** The next request (the next one whose path matches `fault.match`, when given) gets this answer instead of being handled: a rate limit, an outage. */
87
+ inject: (fault: any) => number;
88
+ getLog: () => never[];
89
+ reset: () => void;
90
+ close: () => Promise<any>;
91
+ }>;
92
+ declare class Repo {
93
+ constructor({ id, name, owner, description, topics, defaultBranch, autoInit }: {
94
+ id: any;
95
+ name: any;
96
+ owner: any;
97
+ description?: string | undefined;
98
+ topics?: never[] | undefined;
99
+ defaultBranch?: string | undefined;
100
+ autoInit?: boolean | undefined;
101
+ });
102
+ id: any;
103
+ name: any;
104
+ owner: any;
105
+ description: string;
106
+ topics: any[];
107
+ defaultBranch: string;
108
+ blobs: Map<any, any>;
109
+ trees: Map<any, any>;
110
+ commits: Map<any, any>;
111
+ refs: Map<any, any>;
112
+ tagObjects: Map<any, any>;
113
+ pulls: any[];
114
+ issues: any[];
115
+ releases: any[];
116
+ nextRelease: number;
117
+ labels: any[];
118
+ milestones: any[];
119
+ hooks: any[];
120
+ runs: any[];
121
+ collaborators: {
122
+ login: string;
123
+ id: number;
124
+ role: string;
125
+ }[];
126
+ nextPull: number;
127
+ get fullName(): string;
128
+ putBlob(buffer: any): string;
129
+ putTree(entries: any): string;
130
+ makeCommit({ tree, parents, message, date }: {
131
+ tree: any;
132
+ parents: any;
133
+ message: any;
134
+ date?: string | undefined;
135
+ }): string;
136
+ /** The commit a name points at: a branch, a tag (possibly annotated), or a sha. */
137
+ resolve(ref: any): any;
138
+ treeAt(ref: any): any;
139
+ ancestors(sha: any): Set<any>;
140
+ mergeBase(a: any, b: any): any;
141
+ /** Three-way merge of `head` into `base` (both branch names): the merged tree, or `null` when the same file changed on both sides. */
142
+ mergeTrees(base: any, head: any): {
143
+ entries: Map<any, any>;
144
+ target: any;
145
+ source: any;
146
+ } | null;
147
+ mergeable(pull: any): boolean;
148
+ /** Commits `changes` ([{path, sha | null}]) on top of `branch`. */
149
+ commitOn(branch: any, changes: any, message: any): string;
150
+ }
151
+ export {};