@buildinternet/uploads 0.25.0 → 0.26.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.
- package/dist/commands.js +20 -11
- package/dist/github-gh.d.ts +4 -2
- package/dist/github-gh.js +8 -3
- package/dist/github.js +8 -0
- package/package.json +1 -1
package/dist/commands.js
CHANGED
|
@@ -527,16 +527,16 @@ export async function syncAttachmentsComment(client, target, run, workspace) {
|
|
|
527
527
|
return gallery;
|
|
528
528
|
}
|
|
529
529
|
}));
|
|
530
|
-
if (items.length === 0 && previewGalleries.length === 0)
|
|
531
|
-
return { action: "skipped", count: 0, via: "gh" };
|
|
532
530
|
const marker = attachmentsMarker(workspace);
|
|
533
531
|
const body = attachmentsCommentBody(items, previewGalleries, marker);
|
|
534
|
-
const
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
532
|
+
const count = items.length + previewGalleries.length;
|
|
533
|
+
// Empty (count 0) renders the neutral empty-state body but must not create a
|
|
534
|
+
// comment — it only rewrites one that already exists (`action: "skipped"`
|
|
535
|
+
// when none does).
|
|
536
|
+
const { action } = upsertAttachmentsComment(target, body, run, marker, {
|
|
537
|
+
createIfMissing: count > 0,
|
|
538
|
+
});
|
|
539
|
+
return { action, count, via: "gh" };
|
|
540
540
|
}
|
|
541
541
|
// --- attach ---
|
|
542
542
|
const ATTACH_HELP = `uploads attach <file...> [options]
|
|
@@ -2247,9 +2247,18 @@ export async function runComment(ctx, args, help = false, run = execRunner) {
|
|
|
2247
2247
|
}
|
|
2248
2248
|
else if (!ctx.quiet) {
|
|
2249
2249
|
const via = commentViaSuffix(result.via);
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2250
|
+
let line;
|
|
2251
|
+
if (result.action === "skipped") {
|
|
2252
|
+
line = `no attachments under ${ghKeyPrefix(target)} — nothing to do\n`;
|
|
2253
|
+
}
|
|
2254
|
+
else if (result.count === 0) {
|
|
2255
|
+
// An existing comment rewritten to the empty state (every file removed).
|
|
2256
|
+
line = `cleared attachments comment on ${target.repo}#${target.num} — no files remaining${via}\n`;
|
|
2257
|
+
}
|
|
2258
|
+
else {
|
|
2259
|
+
line = `${result.action} attachments comment on ${target.repo}#${target.num} (${result.count} file${result.count === 1 ? "" : "s"})${via}\n`;
|
|
2260
|
+
}
|
|
2261
|
+
process.stderr.write(line);
|
|
2253
2262
|
}
|
|
2254
2263
|
return 0;
|
|
2255
2264
|
}
|
package/dist/github-gh.d.ts
CHANGED
|
@@ -64,6 +64,8 @@ export declare function ghMetadataFromTargetWithTitle(target: GhTarget, run?: Co
|
|
|
64
64
|
* an adopted legacy comment migrates it to the namespaced marker in place.
|
|
65
65
|
* Defaults to the shared legacy marker for backward compatibility.
|
|
66
66
|
*/
|
|
67
|
-
export declare function upsertAttachmentsComment(target: GhTarget, body: string, run?: CommandRunner, marker?: string
|
|
68
|
-
|
|
67
|
+
export declare function upsertAttachmentsComment(target: GhTarget, body: string, run?: CommandRunner, marker?: string, opts?: {
|
|
68
|
+
createIfMissing?: boolean;
|
|
69
|
+
}): {
|
|
70
|
+
action: "created" | "updated" | "skipped";
|
|
69
71
|
};
|
package/dist/github-gh.js
CHANGED
|
@@ -221,7 +221,8 @@ function findManagedComment(target, run, marker) {
|
|
|
221
221
|
* an adopted legacy comment migrates it to the namespaced marker in place.
|
|
222
222
|
* Defaults to the shared legacy marker for backward compatibility.
|
|
223
223
|
*/
|
|
224
|
-
export function upsertAttachmentsComment(target, body, run = execRunner, marker = ATTACHMENTS_MARKER) {
|
|
224
|
+
export function upsertAttachmentsComment(target, body, run = execRunner, marker = ATTACHMENTS_MARKER, opts = {}) {
|
|
225
|
+
const createIfMissing = opts.createIfMissing ?? true;
|
|
225
226
|
const existing = findManagedComment(target, run, marker);
|
|
226
227
|
if (existing) {
|
|
227
228
|
run("gh", [
|
|
@@ -232,8 +233,12 @@ export function upsertAttachmentsComment(target, body, run = execRunner, marker
|
|
|
232
233
|
"-F",
|
|
233
234
|
"body=@-",
|
|
234
235
|
], body);
|
|
235
|
-
return {
|
|
236
|
+
return { action: "updated" };
|
|
236
237
|
}
|
|
238
|
+
// Patch-only (createIfMissing false, i.e. an empty body) with no existing
|
|
239
|
+
// comment: nothing to do — never create one just to say it's empty.
|
|
240
|
+
if (!createIfMissing)
|
|
241
|
+
return { action: "skipped" };
|
|
237
242
|
run("gh", ["api", `repos/${target.repo}/issues/${target.num}/comments`, "-F", "body=@-"], body);
|
|
238
|
-
return {
|
|
243
|
+
return { action: "created" };
|
|
239
244
|
}
|
package/dist/github.js
CHANGED
|
@@ -482,6 +482,14 @@ export function attachmentsCommentBody(items, galleries = [], marker = ATTACHMEN
|
|
|
482
482
|
}
|
|
483
483
|
lines.push("", "</details>", "");
|
|
484
484
|
}
|
|
485
|
+
// Emptied state: a PR/issue whose attachments and galleries were all removed
|
|
486
|
+
// still keeps its managed comment (a later push can repopulate it) — show a
|
|
487
|
+
// neutral resting state under the heading rather than a bare heading. Only
|
|
488
|
+
// the truly-empty case (no attachments, no galleries); a galleries-only
|
|
489
|
+
// comment has no Attachments heading and must not get this line.
|
|
490
|
+
if (sorted.length === 0 && sortedGalleries.length === 0) {
|
|
491
|
+
lines.push("_No attachments are currently associated with this pull request._", "");
|
|
492
|
+
}
|
|
485
493
|
lines.push('<sub>Maintained by <a href="https://uploads.sh">uploads.sh</a> — re-uploading a file with the same name updates it everywhere it is embedded.</sub>');
|
|
486
494
|
lines.push('<sub>Add media: <code>uploads put <file> --pr <N> --comment</code> (or <code>--issue <N></code>) · <a href="https://uploads.sh/docs/github-app">docs</a></sub>');
|
|
487
495
|
return lines.join("\n");
|