@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/web.js
ADDED
|
@@ -0,0 +1,182 @@
|
|
|
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
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.ah = ah;
|
|
40
|
+
exports.wildcard = wildcard;
|
|
41
|
+
exports.send404 = send404;
|
|
42
|
+
exports.sendBusy = sendBusy;
|
|
43
|
+
exports.urlencodedForm = urlencodedForm;
|
|
44
|
+
exports.field = field;
|
|
45
|
+
exports.fail = fail;
|
|
46
|
+
exports.requireViewerPage = requireViewerPage;
|
|
47
|
+
exports.requireViewerPost = requireViewerPost;
|
|
48
|
+
exports.loadRepo = loadRepo;
|
|
49
|
+
exports.makeCtx = makeCtx;
|
|
50
|
+
exports.baseUrlOf = baseUrlOf;
|
|
51
|
+
const express_1 = __importDefault(require("express"));
|
|
52
|
+
const present_1 = require("./ci/present");
|
|
53
|
+
const forms = __importStar(require("./forms"));
|
|
54
|
+
const issues_1 = require("./issues");
|
|
55
|
+
const limit_1 = require("./limit");
|
|
56
|
+
const pulls_1 = require("./pulls");
|
|
57
|
+
const releases_1 = require("./releases");
|
|
58
|
+
const perms_1 = require("./perms");
|
|
59
|
+
const scan_1 = require("./scan");
|
|
60
|
+
const session_1 = require("./session");
|
|
61
|
+
const site_1 = require("./site");
|
|
62
|
+
const views = __importStar(require("./views"));
|
|
63
|
+
// Helpers shared by the HTML route modules.
|
|
64
|
+
function ah(fn) {
|
|
65
|
+
return (req, res, next) => {
|
|
66
|
+
fn(req, res).catch(next);
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
function wildcard(req) {
|
|
70
|
+
return req.params['0'] ?? '';
|
|
71
|
+
}
|
|
72
|
+
function send404(res, message = 'Not found', viewer = null) {
|
|
73
|
+
res.status(404).type('html').send(views.errorPage(404, message, { viewer }));
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* How a web route refuses when a concurrency gate is full. 503 rather than 429:
|
|
77
|
+
* the condition is server capacity rather than a client quota, and nothing about
|
|
78
|
+
* this request was wrong.
|
|
79
|
+
*/
|
|
80
|
+
function sendBusy(res, viewer = null) {
|
|
81
|
+
res.status(503).setHeader('Retry-After', String(limit_1.BUSY_RETRY_SECONDS));
|
|
82
|
+
res
|
|
83
|
+
.type('html')
|
|
84
|
+
.send(views.errorPage(503, 'The server is busy with other git work. Try again in a moment.', { viewer }));
|
|
85
|
+
}
|
|
86
|
+
// Form posts are read as urlencoded bodies with express's simple parser: the
|
|
87
|
+
// forms here are flat, so the extended syntax would only widen what a body may
|
|
88
|
+
// say. The limit is left to the caller, because what one page may reasonably
|
|
89
|
+
// carry (a file being edited) is not what another should (a release note).
|
|
90
|
+
function urlencodedForm(limit) {
|
|
91
|
+
return express_1.default.urlencoded({ extended: false, limit });
|
|
92
|
+
}
|
|
93
|
+
// A form field as a string. Anything the parser did not give us as a string
|
|
94
|
+
// (a missing field, or a repeated one arriving as an array) reads as empty
|
|
95
|
+
// rather than being passed on as something a handler did not expect.
|
|
96
|
+
function field(req, name) {
|
|
97
|
+
const v = req.body?.[name];
|
|
98
|
+
return typeof v === 'string' ? v : '';
|
|
99
|
+
}
|
|
100
|
+
// How an operation refuses. backUrl, when given, is where the page offers to
|
|
101
|
+
// send the reader back to, which is usually the form they came from.
|
|
102
|
+
function fail(res, status, message, viewer, backUrl) {
|
|
103
|
+
res.status(status).type('html').send(forms.opErrorPage(message, { viewer, backUrl }));
|
|
104
|
+
}
|
|
105
|
+
// For GET form pages: an anonymous visitor is sent to sign in and come back.
|
|
106
|
+
function requireViewerPage(root, req, res) {
|
|
107
|
+
const viewer = (0, session_1.getViewer)(req, root);
|
|
108
|
+
if (!viewer) {
|
|
109
|
+
res.redirect(`/login?next=${encodeURIComponent(req.originalUrl)}`);
|
|
110
|
+
return null;
|
|
111
|
+
}
|
|
112
|
+
return viewer;
|
|
113
|
+
}
|
|
114
|
+
// For POSTs: a missing session or a bad CSRF value is a hard 403.
|
|
115
|
+
function requireViewerPost(root, req, res) {
|
|
116
|
+
const viewer = (0, session_1.getViewer)(req, root);
|
|
117
|
+
if (!viewer) {
|
|
118
|
+
fail(res, 403, 'You must be signed in to do that.', null, '/login');
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
if (!(0, session_1.checkCsrf)(req, viewer)) {
|
|
122
|
+
fail(res, 403, 'The form has expired; go back, reload the page, and try again.', viewer);
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
return viewer;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* The repository named by the route, for a viewer allowed to read it. Every
|
|
129
|
+
* HTML page about a repository is loaded through here, so this is where a
|
|
130
|
+
* private repository disappears: a viewer with no role gets the same 404 an
|
|
131
|
+
* absent repository gets, and a private name proves nothing by existing.
|
|
132
|
+
*/
|
|
133
|
+
async function loadRepo(root, req, res, viewer) {
|
|
134
|
+
const repo = (0, scan_1.findRepo)(root, req.params.collection, req.params.repo);
|
|
135
|
+
const role = repo ? (0, perms_1.repoRole)(root, viewer?.auth ?? null, repo) : null;
|
|
136
|
+
if (!repo || role === null) {
|
|
137
|
+
send404(res, `Repository ${req.params.collection}/${req.params.repo} not found`, viewer);
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
const [branches, tags] = await Promise.all([repo.listRefs('heads'), repo.listRefs('tags')]);
|
|
141
|
+
const defaultBranch = await repo.defaultBranch(branches);
|
|
142
|
+
return {
|
|
143
|
+
repo,
|
|
144
|
+
branches,
|
|
145
|
+
tags,
|
|
146
|
+
defaultBranch,
|
|
147
|
+
refNames: [...branches.map((b) => b.name), ...tags.map((t) => t.name)],
|
|
148
|
+
role,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
async function makeCtx(root, req, loaded, ref, viewer) {
|
|
152
|
+
const cloneUrl = `${req.protocol}://${req.get('host')}/${encodeURIComponent(loaded.repo.collection)}/${encodeURIComponent(loaded.repo.name)}`;
|
|
153
|
+
// Where the Site tab points. A site with an origin of its own is linked there
|
|
154
|
+
// directly rather than through the forge path that would only redirect.
|
|
155
|
+
const siteOrigin = (0, site_1.siteHostUrl)(root, req, loaded.repo.collection, loaded.repo.name);
|
|
156
|
+
return {
|
|
157
|
+
collection: loaded.repo.collection,
|
|
158
|
+
repo: loaded.repo.name,
|
|
159
|
+
ref,
|
|
160
|
+
refIsBranch: loaded.branches.some((b) => b.name === ref),
|
|
161
|
+
defaultBranch: loaded.defaultBranch ?? '',
|
|
162
|
+
branches: loaded.branches,
|
|
163
|
+
tags: loaded.tags,
|
|
164
|
+
cloneUrl,
|
|
165
|
+
hasSite: (0, scan_1.siteDir)(root, loaded.repo.collection, loaded.repo.name) !== null,
|
|
166
|
+
siteUrl: siteOrigin
|
|
167
|
+
? `${siteOrigin}/`
|
|
168
|
+
: `/${encodeURIComponent(loaded.repo.collection)}/${encodeURIComponent(loaded.repo.name)}/site/`,
|
|
169
|
+
releases: (0, releases_1.releaseTags)(root, loaded.repo.collection, loaded.repo.name),
|
|
170
|
+
hasCi: await (0, present_1.hasCiState)(root, loaded.repo, loaded.defaultBranch, loaded.branches),
|
|
171
|
+
openIssues: (0, issues_1.issueCounts)(root, loaded.repo.collection, loaded.repo.name).open,
|
|
172
|
+
openPulls: (0, pulls_1.pullCounts)(root, loaded.repo.collection, loaded.repo.name).open,
|
|
173
|
+
forkedFrom: (0, scan_1.forkParent)(loaded.repo.dir),
|
|
174
|
+
viewer,
|
|
175
|
+
isPrivate: (0, perms_1.repoIsPrivate)(loaded.repo.dir),
|
|
176
|
+
canPush: (0, perms_1.atLeast)(loaded.role, 'write'),
|
|
177
|
+
canAdmin: (0, perms_1.atLeast)(loaded.role, 'admin'),
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
function baseUrlOf(req) {
|
|
181
|
+
return `${req.protocol}://${req.get('host')}`;
|
|
182
|
+
}
|