@magland/mochi 0.3.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.
- package/LICENSE +201 -0
- package/README.md +108 -0
- package/dist/ansi.js +174 -0
- package/dist/api/admin.js +416 -0
- package/dist/api/auth.js +166 -0
- package/dist/api/backup.js +598 -0
- package/dist/api/ci.js +336 -0
- package/dist/api/contents.js +339 -0
- package/dist/api/issues.js +165 -0
- package/dist/api/pulls.js +244 -0
- package/dist/api/releases.js +83 -0
- package/dist/api/repos.js +156 -0
- package/dist/api/write.js +518 -0
- package/dist/api.js +326 -0
- package/dist/assets.js +29 -0
- package/dist/atom.js +32 -0
- package/dist/atomic.js +171 -0
- package/dist/avatar.js +81 -0
- package/dist/browse.js +630 -0
- package/dist/build-info.json +4 -0
- package/dist/ci/actionref.js +86 -0
- package/dist/ci/api.js +829 -0
- package/dist/ci/artifacts.js +201 -0
- package/dist/ci/dispatch.js +30 -0
- package/dist/ci/engine.js +1321 -0
- package/dist/ci/expr.js +526 -0
- package/dist/ci/manual.js +199 -0
- package/dist/ci/present.js +82 -0
- package/dist/ci/protocol.js +6 -0
- package/dist/ci/runners.js +256 -0
- package/dist/ci/runs.js +208 -0
- package/dist/ci/trigger.js +28 -0
- package/dist/ci/views.js +441 -0
- package/dist/ci/wake.js +194 -0
- package/dist/ci/web.js +617 -0
- package/dist/ci/workflow.js +436 -0
- package/dist/cli/admin-cmd.js +324 -0
- package/dist/cli/api-cmd.js +128 -0
- package/dist/cli/backup-cmd.js +1500 -0
- package/dist/cli/exit.js +69 -0
- package/dist/cli/input.js +64 -0
- package/dist/cli/issue-cmd.js +243 -0
- package/dist/cli/output.js +93 -0
- package/dist/cli/parse.js +317 -0
- package/dist/cli/pr-cmd.js +289 -0
- package/dist/cli/release-cmd.js +171 -0
- package/dist/cli/repo-cmd.js +763 -0
- package/dist/cli/repo.js +101 -0
- package/dist/cli/run-cmd.js +438 -0
- package/dist/cli/target.js +54 -0
- package/dist/cli-api.js +84 -0
- package/dist/compare.js +111 -0
- package/dist/config.js +212 -0
- package/dist/credentials.js +235 -0
- package/dist/deploy-cli.js +859 -0
- package/dist/deploy-runner-cli.js +592 -0
- package/dist/diff.js +171 -0
- package/dist/discussion.js +253 -0
- package/dist/egress.js +559 -0
- package/dist/filecache.js +68 -0
- package/dist/find.js +162 -0
- package/dist/forms.js +737 -0
- package/dist/git.js +547 -0
- package/dist/githttp.js +428 -0
- package/dist/html.js +87 -0
- package/dist/icons.js +101 -0
- package/dist/import-cli.js +316 -0
- package/dist/index.js +752 -0
- package/dist/issues.js +308 -0
- package/dist/issueweb.js +447 -0
- package/dist/job-cli.js +197 -0
- package/dist/jobtoken.js +96 -0
- package/dist/languages.js +383 -0
- package/dist/layout.js +100 -0
- package/dist/lfs.js +438 -0
- package/dist/lfsstore.js +425 -0
- package/dist/limit.js +259 -0
- package/dist/logo.js +61 -0
- package/dist/markdown.js +382 -0
- package/dist/migrate.js +334 -0
- package/dist/multipart.js +90 -0
- package/dist/ops.js +869 -0
- package/dist/pagescript.js +465 -0
- package/dist/perms.js +370 -0
- package/dist/pointer.js +55 -0
- package/dist/profile.js +106 -0
- package/dist/pulls.js +320 -0
- package/dist/pullweb.js +461 -0
- package/dist/redirects.js +455 -0
- package/dist/releases.js +435 -0
- package/dist/render.js +233 -0
- package/dist/runner/actions.js +448 -0
- package/dist/runner/client.js +428 -0
- package/dist/runner/context.js +247 -0
- package/dist/runner/docker.js +197 -0
- package/dist/runner/externals.js +175 -0
- package/dist/runner/job.js +290 -0
- package/dist/runner/manual-run.js +272 -0
- package/dist/runner/overrides.js +554 -0
- package/dist/runner/steps.js +571 -0
- package/dist/runner/wake.js +84 -0
- package/dist/runner-cli.js +405 -0
- package/dist/scan.js +231 -0
- package/dist/server.js +424 -0
- package/dist/session.js +267 -0
- package/dist/site.js +259 -0
- package/dist/siteshost.js +94 -0
- package/dist/source.js +90 -0
- package/dist/style.js +1295 -0
- package/dist/themes.js +369 -0
- package/dist/vault.js +442 -0
- package/dist/version.js +88 -0
- package/dist/views.js +1007 -0
- package/dist/web.js +182 -0
- package/dist/webops.js +1402 -0
- package/package.json +71 -0
package/dist/find.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.registerFind = registerFind;
|
|
37
|
+
exports.registerSearch = registerSearch;
|
|
38
|
+
const git_1 = require("./git");
|
|
39
|
+
const session_1 = require("./session");
|
|
40
|
+
const views = __importStar(require("./views"));
|
|
41
|
+
const web_1 = require("./web");
|
|
42
|
+
// The two ways of finding something in a repository: by name and by content.
|
|
43
|
+
//
|
|
44
|
+
// The file finder: every path in the tree at one ref, filtered as you type.
|
|
45
|
+
// GitHub reaches it with the "Go to file" button or the t key, and it is how
|
|
46
|
+
// people navigate a repository they already know; clicking down through
|
|
47
|
+
// directories is for a repository they do not.
|
|
48
|
+
//
|
|
49
|
+
// The whole list is rendered into the page and filtered in the browser. That
|
|
50
|
+
// is the trade this design implies: no search endpoint, no index, no state
|
|
51
|
+
// outside the vault, at the cost of a page whose size grows with the tree.
|
|
52
|
+
// The cap below bounds that page; a tree past it is listed as far as the cap
|
|
53
|
+
// and says so.
|
|
54
|
+
const MAX_PATHS = 20000;
|
|
55
|
+
function registerFind(app, root, gates) {
|
|
56
|
+
const handler = (0, web_1.ah)(async (req, res) => {
|
|
57
|
+
const viewer = (0, session_1.getViewer)(req, root);
|
|
58
|
+
const loaded = await (0, web_1.loadRepo)(root, req, res, viewer);
|
|
59
|
+
if (!loaded)
|
|
60
|
+
return;
|
|
61
|
+
const ref = (0, web_1.wildcard)(req) || loaded.defaultBranch || '';
|
|
62
|
+
if (!(0, git_1.isValidRefName)(ref)) {
|
|
63
|
+
(0, web_1.send404)(res, 'Not found', viewer);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
// ls-tree walks the whole tree, and execGit's maxBuffer is 256 MB, so a
|
|
67
|
+
// handful of these at once on a large repository is a memory problem before
|
|
68
|
+
// it is a CPU one. MAX_PATHS bounds one response; the gate bounds how many
|
|
69
|
+
// are in flight.
|
|
70
|
+
const release = await gates.tree.enter();
|
|
71
|
+
if (!release) {
|
|
72
|
+
(0, web_1.sendBusy)(res, viewer);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
let paths;
|
|
76
|
+
try {
|
|
77
|
+
const out = (await (0, git_1.execGit)(loaded.repo.dir, ['ls-tree', '-r', '--name-only', '-z', ref])).toString('utf8');
|
|
78
|
+
paths = out.split('\0').filter((p) => p !== '');
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
(0, web_1.send404)(res, `Ref ${ref} not found`, viewer);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
release();
|
|
86
|
+
}
|
|
87
|
+
const ctx = await (0, web_1.makeCtx)(root, req, loaded, ref, viewer);
|
|
88
|
+
res.type('html').send(views.findFilePage(ctx, paths.slice(0, MAX_PATHS), paths.length));
|
|
89
|
+
});
|
|
90
|
+
app.get('/:collection/:repo/find/*', handler);
|
|
91
|
+
app.get('/:collection/:repo/find', handler);
|
|
92
|
+
}
|
|
93
|
+
// How many files a result page groups, and how many lines it shows from any
|
|
94
|
+
// one of them: a search for something common should still fit on a page.
|
|
95
|
+
const MAX_RESULT_FILES = 40;
|
|
96
|
+
const MAX_LINES_PER_FILE = 10;
|
|
97
|
+
/**
|
|
98
|
+
* Group a flat list of hits by file, keeping git's order and capping both the
|
|
99
|
+
* number of files and the lines shown from each, so that what was left out is
|
|
100
|
+
* reported rather than quietly dropped.
|
|
101
|
+
*/
|
|
102
|
+
function groupHits(hits) {
|
|
103
|
+
const files = [];
|
|
104
|
+
const byPath = new Map();
|
|
105
|
+
let capped = false;
|
|
106
|
+
for (const hit of hits) {
|
|
107
|
+
let file = byPath.get(hit.path);
|
|
108
|
+
if (!file) {
|
|
109
|
+
if (files.length >= MAX_RESULT_FILES) {
|
|
110
|
+
capped = true;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
file = { path: hit.path, hits: [], more: 0 };
|
|
114
|
+
byPath.set(hit.path, file);
|
|
115
|
+
files.push(file);
|
|
116
|
+
}
|
|
117
|
+
if (file.hits.length < MAX_LINES_PER_FILE)
|
|
118
|
+
file.hits.push(hit);
|
|
119
|
+
else
|
|
120
|
+
file.more++;
|
|
121
|
+
}
|
|
122
|
+
return { files, capped };
|
|
123
|
+
}
|
|
124
|
+
function registerSearch(app, root, gates) {
|
|
125
|
+
app.get('/:collection/:repo/search', (0, web_1.ah)(async (req, res) => {
|
|
126
|
+
const viewer = (0, session_1.getViewer)(req, root);
|
|
127
|
+
const loaded = await (0, web_1.loadRepo)(root, req, res, viewer);
|
|
128
|
+
if (!loaded)
|
|
129
|
+
return;
|
|
130
|
+
const asked = String(req.query.ref ?? '');
|
|
131
|
+
const ref = asked !== '' && loaded.refNames.includes(asked) ? asked : loaded.defaultBranch ?? '';
|
|
132
|
+
if (ref !== '' && !(0, git_1.isValidRefName)(ref)) {
|
|
133
|
+
(0, web_1.send404)(res, 'Not found', viewer);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
const ctx = await (0, web_1.makeCtx)(root, req, loaded, ref, viewer);
|
|
137
|
+
// A query is a reader's typing, so it is bounded before it becomes an
|
|
138
|
+
// argument: git grep is fast, but not on a pattern the length of a page.
|
|
139
|
+
const query = String(req.query.q ?? '').slice(0, 256);
|
|
140
|
+
if (query.trim() === '' || ref === '') {
|
|
141
|
+
res.type('html').send(views.searchPage(ctx, query, { files: [], total: 0, truncated: false, capped: false }));
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
// git grep over a whole tree is the most expensive thing an anonymous
|
|
145
|
+
// reader can ask for, so it has the tightest gate of the four.
|
|
146
|
+
const release = await gates.search.enter();
|
|
147
|
+
if (!release) {
|
|
148
|
+
(0, web_1.sendBusy)(res, viewer);
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
let hits;
|
|
152
|
+
let truncated;
|
|
153
|
+
try {
|
|
154
|
+
({ hits, truncated } = await loaded.repo.search(ref, query));
|
|
155
|
+
}
|
|
156
|
+
finally {
|
|
157
|
+
release();
|
|
158
|
+
}
|
|
159
|
+
const { files, capped } = groupHits(hits);
|
|
160
|
+
res.type('html').send(views.searchPage(ctx, query, { files, total: hits.length, truncated, capped }));
|
|
161
|
+
}));
|
|
162
|
+
}
|