MCPcopy
hub / github.com/softprops/action-gh-release / maybeRestoreAssetLabel

Function maybeRestoreAssetLabel

src/github.ts:377–422  ·  view source on GitHub ↗
(uploadedAsset: {
    id?: number;
    name?: string;
    label?: string | null;
    [key: string]: any;
  })

Source from the content-addressed store, hash-verified

375 };
376
377 const maybeRestoreAssetLabel = async (uploadedAsset: {
378 id?: number;
379 name?: string;
380 label?: string | null;
381 [key: string]: any;
382 }) => {
383 if (!uploadedAsset.name || uploadedAsset.name === name || !uploadedAsset.id) {
384 return uploadedAsset;
385 }
386
387 console.log(`✏️ Restoring asset label to ${name}...`);
388
389 const updateAssetLabel = async (assetId: number) => {
390 const { data } = await releaser.updateReleaseAsset({
391 owner,
392 repo,
393 asset_id: assetId,
394 name: uploadedAsset.name!,
395 label: name,
396 });
397 return data;
398 };
399
400 try {
401 return await updateAssetLabel(uploadedAsset.id);
402 } catch (error: any) {
403 const errorStatus = error?.status ?? error?.response?.status;
404
405 if (errorStatus === 404 && releaseId !== undefined) {
406 try {
407 const latestAsset = await findReleaseAsset(
408 (currentAsset) =>
409 currentAsset.id === uploadedAsset.id || currentAsset.name === uploadedAsset.name,
410 );
411 if (latestAsset) {
412 return await updateAssetLabel(latestAsset.id);
413 }
414 } catch (refreshError) {
415 console.warn(`error refreshing release assets for ${name}: ${refreshError}`);
416 }
417 }
418
419 console.warn(`error updating release asset label for ${name}: ${error}`);
420 return uploadedAsset;
421 }
422 };
423
424 const handleUploadedAsset = async (resp: { status: number; data: any }) => {
425 const json = resp.data;

Callers 1

handleUploadedAssetFunction · 0.85

Calls 2

updateAssetLabelFunction · 0.85
findReleaseAssetFunction · 0.85

Tested by

no test coverage detected