@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.
Files changed (116) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +108 -0
  3. package/dist/ansi.js +174 -0
  4. package/dist/api/admin.js +416 -0
  5. package/dist/api/auth.js +166 -0
  6. package/dist/api/backup.js +598 -0
  7. package/dist/api/ci.js +336 -0
  8. package/dist/api/contents.js +339 -0
  9. package/dist/api/issues.js +165 -0
  10. package/dist/api/pulls.js +244 -0
  11. package/dist/api/releases.js +83 -0
  12. package/dist/api/repos.js +156 -0
  13. package/dist/api/write.js +518 -0
  14. package/dist/api.js +326 -0
  15. package/dist/assets.js +29 -0
  16. package/dist/atom.js +32 -0
  17. package/dist/atomic.js +171 -0
  18. package/dist/avatar.js +81 -0
  19. package/dist/browse.js +630 -0
  20. package/dist/build-info.json +4 -0
  21. package/dist/ci/actionref.js +86 -0
  22. package/dist/ci/api.js +829 -0
  23. package/dist/ci/artifacts.js +201 -0
  24. package/dist/ci/dispatch.js +30 -0
  25. package/dist/ci/engine.js +1321 -0
  26. package/dist/ci/expr.js +526 -0
  27. package/dist/ci/manual.js +199 -0
  28. package/dist/ci/present.js +82 -0
  29. package/dist/ci/protocol.js +6 -0
  30. package/dist/ci/runners.js +256 -0
  31. package/dist/ci/runs.js +208 -0
  32. package/dist/ci/trigger.js +28 -0
  33. package/dist/ci/views.js +441 -0
  34. package/dist/ci/wake.js +194 -0
  35. package/dist/ci/web.js +617 -0
  36. package/dist/ci/workflow.js +436 -0
  37. package/dist/cli/admin-cmd.js +324 -0
  38. package/dist/cli/api-cmd.js +128 -0
  39. package/dist/cli/backup-cmd.js +1500 -0
  40. package/dist/cli/exit.js +69 -0
  41. package/dist/cli/input.js +64 -0
  42. package/dist/cli/issue-cmd.js +243 -0
  43. package/dist/cli/output.js +93 -0
  44. package/dist/cli/parse.js +317 -0
  45. package/dist/cli/pr-cmd.js +289 -0
  46. package/dist/cli/release-cmd.js +171 -0
  47. package/dist/cli/repo-cmd.js +763 -0
  48. package/dist/cli/repo.js +101 -0
  49. package/dist/cli/run-cmd.js +438 -0
  50. package/dist/cli/target.js +54 -0
  51. package/dist/cli-api.js +84 -0
  52. package/dist/compare.js +111 -0
  53. package/dist/config.js +212 -0
  54. package/dist/credentials.js +235 -0
  55. package/dist/deploy-cli.js +859 -0
  56. package/dist/deploy-runner-cli.js +592 -0
  57. package/dist/diff.js +171 -0
  58. package/dist/discussion.js +253 -0
  59. package/dist/egress.js +559 -0
  60. package/dist/filecache.js +68 -0
  61. package/dist/find.js +162 -0
  62. package/dist/forms.js +737 -0
  63. package/dist/git.js +547 -0
  64. package/dist/githttp.js +428 -0
  65. package/dist/html.js +87 -0
  66. package/dist/icons.js +101 -0
  67. package/dist/import-cli.js +316 -0
  68. package/dist/index.js +752 -0
  69. package/dist/issues.js +308 -0
  70. package/dist/issueweb.js +447 -0
  71. package/dist/job-cli.js +197 -0
  72. package/dist/jobtoken.js +96 -0
  73. package/dist/languages.js +383 -0
  74. package/dist/layout.js +100 -0
  75. package/dist/lfs.js +438 -0
  76. package/dist/lfsstore.js +425 -0
  77. package/dist/limit.js +259 -0
  78. package/dist/logo.js +61 -0
  79. package/dist/markdown.js +382 -0
  80. package/dist/migrate.js +334 -0
  81. package/dist/multipart.js +90 -0
  82. package/dist/ops.js +869 -0
  83. package/dist/pagescript.js +465 -0
  84. package/dist/perms.js +370 -0
  85. package/dist/pointer.js +55 -0
  86. package/dist/profile.js +106 -0
  87. package/dist/pulls.js +320 -0
  88. package/dist/pullweb.js +461 -0
  89. package/dist/redirects.js +455 -0
  90. package/dist/releases.js +435 -0
  91. package/dist/render.js +233 -0
  92. package/dist/runner/actions.js +448 -0
  93. package/dist/runner/client.js +428 -0
  94. package/dist/runner/context.js +247 -0
  95. package/dist/runner/docker.js +197 -0
  96. package/dist/runner/externals.js +175 -0
  97. package/dist/runner/job.js +290 -0
  98. package/dist/runner/manual-run.js +272 -0
  99. package/dist/runner/overrides.js +554 -0
  100. package/dist/runner/steps.js +571 -0
  101. package/dist/runner/wake.js +84 -0
  102. package/dist/runner-cli.js +405 -0
  103. package/dist/scan.js +231 -0
  104. package/dist/server.js +424 -0
  105. package/dist/session.js +267 -0
  106. package/dist/site.js +259 -0
  107. package/dist/siteshost.js +94 -0
  108. package/dist/source.js +90 -0
  109. package/dist/style.js +1295 -0
  110. package/dist/themes.js +369 -0
  111. package/dist/vault.js +442 -0
  112. package/dist/version.js +88 -0
  113. package/dist/views.js +1007 -0
  114. package/dist/web.js +182 -0
  115. package/dist/webops.js +1402 -0
  116. package/package.json +71 -0
@@ -0,0 +1,171 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.releaseCommands = void 0;
4
+ const cli_api_1 = require("../cli-api");
5
+ const exit_1 = require("./exit");
6
+ const input_1 = require("./input");
7
+ const output_1 = require("./output");
8
+ const repo_1 = require("./repo");
9
+ const target_1 = require("./target");
10
+ // Releases: notes attached to a tag that already exists.
11
+ //
12
+ // There is no `release upload`, because a release's downloads are the archive
13
+ // routes and there is nothing to upload. Anyone who knows `gh release upload`
14
+ // will look for one, so docs/agents.md says plainly that it is not here.
15
+ const COMMON = [repo_1.REPO_OPTION, ...target_1.TARGET_OPTIONS];
16
+ const NOTES_OPTIONS = [
17
+ { name: 'title', type: 'string', value: '<t>', summary: 'Release title; the tag names itself otherwise' },
18
+ { name: 'notes', type: 'string', value: '<n>', summary: 'Release notes' },
19
+ { name: 'notes-file', type: 'string', value: '<f>', summary: "Read the notes from a file, or '-' for stdin" },
20
+ { name: 'prerelease', type: 'boolean', summary: 'Mark it a prerelease' },
21
+ ];
22
+ async function notesOf(inv) {
23
+ const inline = inv.str('notes');
24
+ const file = inv.str('notes-file');
25
+ if (inline !== null && file !== null)
26
+ throw new exit_1.CliError('Pass either --notes or --notes-file, not both.', exit_1.EXIT_USAGE);
27
+ if (file !== null)
28
+ return await (0, input_1.readFileArg)(file);
29
+ return inline ?? undefined;
30
+ }
31
+ /** A tag may contain slashes, so it is encoded as one path segment. */
32
+ function tagPath(tag) {
33
+ return encodeURIComponent(tag);
34
+ }
35
+ async function put(inv, tag, prereleaseGiven) {
36
+ const target = await (0, target_1.targetFrom)(inv);
37
+ const repo = await (0, repo_1.resolveRepo)(inv, target);
38
+ const data = await (0, cli_api_1.api)(target, 'PUT', `${(0, repo_1.repoPath)(repo)}/releases/${tagPath(tag)}`, {
39
+ name: inv.str('title') ?? undefined,
40
+ body: await notesOf(inv),
41
+ // Absent means "leave it as it is", which is what makes create and edit the
42
+ // same call; only a flag that was actually given changes anything.
43
+ prerelease: prereleaseGiven ? true : undefined,
44
+ });
45
+ const json = (0, output_1.jsonMode)(inv);
46
+ if (json.enabled) {
47
+ (0, output_1.printJson)((0, output_1.pickObject)(data, json.fields));
48
+ return;
49
+ }
50
+ console.log(`${target.host}/${repo.collection}/${repo.repo}/releases/${tag}`);
51
+ }
52
+ exports.releaseCommands = [
53
+ {
54
+ path: ['release', 'list'],
55
+ summary: 'List releases, newest first',
56
+ options: [output_1.JSON_OPTION, ...COMMON],
57
+ async run(inv) {
58
+ const target = await (0, target_1.targetFrom)(inv);
59
+ const repo = await (0, repo_1.resolveRepo)(inv, target);
60
+ const data = await (0, cli_api_1.api)(target, 'GET', `${(0, repo_1.repoPath)(repo)}/releases`);
61
+ const releases = (data.releases ?? []);
62
+ const json = (0, output_1.jsonMode)(inv);
63
+ if (json.enabled) {
64
+ (0, output_1.printJson)({ releases: (0, output_1.pickFields)(releases, json.fields) });
65
+ return;
66
+ }
67
+ if (releases.length === 0) {
68
+ console.log('No releases');
69
+ return;
70
+ }
71
+ (0, output_1.printTable)(releases.map((r) => [
72
+ String(r.tag),
73
+ r.prerelease ? 'prerelease' : '',
74
+ String(r.name || r.tag),
75
+ String(r.author),
76
+ (0, output_1.shortDate)(r.created),
77
+ ]));
78
+ },
79
+ },
80
+ {
81
+ path: ['release', 'view'],
82
+ summary: 'Show one release',
83
+ args: [{ name: 'tag', required: true }],
84
+ options: [output_1.JSON_OPTION, ...COMMON],
85
+ async run(inv) {
86
+ const target = await (0, target_1.targetFrom)(inv);
87
+ const repo = await (0, repo_1.resolveRepo)(inv, target);
88
+ const data = await (0, cli_api_1.api)(target, 'GET', `${(0, repo_1.repoPath)(repo)}/releases/${tagPath(inv.args[0])}`);
89
+ const json = (0, output_1.jsonMode)(inv);
90
+ if (json.enabled) {
91
+ (0, output_1.printJson)((0, output_1.pickObject)(data, json.fields));
92
+ return;
93
+ }
94
+ console.log(`${data.tag}${data.prerelease ? ' (prerelease)' : ''}`);
95
+ if (data.name)
96
+ console.log(String(data.name));
97
+ console.log(`published by ${data.author} on ${(0, output_1.shortDate)(data.created)}`);
98
+ console.log('');
99
+ console.log(String(data.body ?? '').trimEnd());
100
+ },
101
+ },
102
+ {
103
+ path: ['release', 'create'],
104
+ summary: 'Publish notes for a tag that already exists',
105
+ description: `The tag has to be in the repository first: notes for a tag nobody can check out
106
+ are notes about nothing. 'mochi tag create' makes one.
107
+
108
+ Creating and editing are the same call underneath, since a release is keyed by its
109
+ tag, so 'release create' on an existing release edits it rather than refusing.`,
110
+ args: [{ name: 'tag', required: true }],
111
+ options: [...NOTES_OPTIONS, output_1.JSON_OPTION, ...COMMON],
112
+ run: (inv) => put(inv, inv.args[0], inv.bool('prerelease')),
113
+ },
114
+ {
115
+ path: ['release', 'edit'],
116
+ summary: 'Change a release title, notes, or prerelease flag',
117
+ args: [{ name: 'tag', required: true }],
118
+ options: [
119
+ ...NOTES_OPTIONS,
120
+ { name: 'latest', type: 'boolean', summary: 'Clear the prerelease flag' },
121
+ output_1.JSON_OPTION,
122
+ ...COMMON,
123
+ ],
124
+ async run(inv) {
125
+ if (inv.bool('prerelease') && inv.bool('latest')) {
126
+ throw new exit_1.CliError('Pass either --prerelease or --latest, not both.', exit_1.EXIT_USAGE);
127
+ }
128
+ if (inv.bool('latest')) {
129
+ const target = await (0, target_1.targetFrom)(inv);
130
+ const repo = await (0, repo_1.resolveRepo)(inv, target);
131
+ const data = await (0, cli_api_1.api)(target, 'PUT', `${(0, repo_1.repoPath)(repo)}/releases/${tagPath(inv.args[0])}`, {
132
+ name: inv.str('title') ?? undefined,
133
+ body: await notesOf(inv),
134
+ prerelease: false,
135
+ });
136
+ const json = (0, output_1.jsonMode)(inv);
137
+ if (json.enabled)
138
+ (0, output_1.printJson)((0, output_1.pickObject)(data, json.fields));
139
+ else
140
+ console.log(`${inv.args[0]} is no longer a prerelease`);
141
+ return;
142
+ }
143
+ await put(inv, inv.args[0], inv.bool('prerelease'));
144
+ },
145
+ },
146
+ {
147
+ path: ['release', 'delete'],
148
+ summary: "Delete a release's notes, keeping the tag",
149
+ args: [{ name: 'tag', required: true }],
150
+ options: [
151
+ { name: 'yes', type: 'boolean', summary: 'Required: confirm that this cannot be undone' },
152
+ output_1.JSON_OPTION,
153
+ ...COMMON,
154
+ ],
155
+ async run(inv) {
156
+ if (!inv.bool('yes'))
157
+ throw new exit_1.CliError('Deleting a release cannot be undone. Pass --yes.', exit_1.EXIT_USAGE);
158
+ const target = await (0, target_1.targetFrom)(inv);
159
+ const repo = await (0, repo_1.resolveRepo)(inv, target);
160
+ const data = await (0, cli_api_1.api)(target, 'DELETE', `${(0, repo_1.repoPath)(repo)}/releases/${tagPath(inv.args[0])}`);
161
+ const json = (0, output_1.jsonMode)(inv);
162
+ if (json.enabled) {
163
+ (0, output_1.printJson)((0, output_1.pickObject)(data, json.fields));
164
+ return;
165
+ }
166
+ // Worth saying, because the two are separate operations and a caller
167
+ // expecting the tag to go with the notes would be surprised.
168
+ console.log(`Deleted the release notes for ${data.deleted}; the tag itself is still there.`);
169
+ },
170
+ },
171
+ ];