Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[code-infra] Qr code deploy urls #45078

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update dangerFileContent.ts
  • Loading branch information
Janpot committed Jan 21, 2025
commit e52be5dec8adcfe1db0c92424149391af60204cd
22 changes: 11 additions & 11 deletions dangerFileContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type * as dangerModule from 'danger';
import replaceUrl from '@mui-internal/api-docs-builder/utils/replaceUrl';
// eslint-disable-next-line import/no-relative-packages
import QRCode from 'qrcode';
// eslint-disable-next-line import/no-relative-packages
import { loadComparison } from 'size-snapshot';

declare const danger: (typeof dangerModule)['danger'];
Expand Down Expand Up @@ -189,6 +190,8 @@ async function reportBundleSize() {
}

async function addDeployPreviewUrls() {
const netlifyPreview = `https://deploy-preview-${danger.github.pr.number}--material-ui.netlify.app/`;

/**
* The incoming path from danger does not start with `/`
* e.g. ['docs/data/joy/components/button/button.md']
Expand All @@ -213,10 +216,14 @@ async function addDeployPreviewUrls() {
.replace('components/', 'react-');
}

return url;
return new URL(url, netlifyPreview);
}

const netlifyPreview = `https://deploy-preview-${danger.github.pr.number}--material-ui.netlify.app/`;
async function formatMdLinkWithQrCode(path: string) {
const url = String(formatFileToLink(path));
const qrDataUrl = await QRCode.toDataURL(url, {});
return `<details><summary>[${path}](${url})</summary>![${path}](${qrDataUrl})</details>`;
}

const files = [...danger.git.created_files, ...danger.git.modified_files];

Expand All @@ -225,19 +232,12 @@ async function addDeployPreviewUrls() {
.filter((file) => file.startsWith('docs/data') && file.endsWith('.md'))
.slice(0, 5);

const docsMdLines = await Promise.all(
docs.map(async (path) => {
const formattedUrl = formatFileToLink(path);
const url = `${netlifyPreview}${formattedUrl}`;
const qrDataUrl = await QRCode.toDataURL(url, {});
return `<details><summary>[${path}](${url})</summary>![${url}](${qrDataUrl})</details>`;
}),
);
const docsMdLines = await Promise.all(docs.map(formatMdLinkWithQrCode));

markdown(`
## Netlify deploy preview

${docsMdLines.length ? docsMdLines.join('\n') : netlifyPreview}
${docsMdLines.length ? docsMdLines.join('\n') : await formatMdLinkWithQrCode('/')}
`);
}

Expand Down
Loading