Skip to content

Bump nanoid from 3.3.11 to 3.3.18 #132

Bump nanoid from 3.3.11 to 3.3.18

Bump nanoid from 3.3.11 to 3.3.18 #132

name: Preview Badges
on:
pull_request_target:
types: [opened, reopened]
jobs:
previews:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: jupyterlab/maintainer-tools/.github/actions/binder-link@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
- uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = context.payload.pull_request.number;
const docsSlug =
`${context.repo.owner}-${context.repo.repo}`.toLowerCase();
const jupyterliteLabUrl = `https://${docsSlug}--${prNumber}.org.readthedocs.build/en/${prNumber}/lite/lab/`;
const jupyterliteNotebookUrl = `https://${docsSlug}--${prNumber}.org.readthedocs.build/en/${prNumber}/lite/tree/`;
const jupyterliteBadge = `[![JupyterLite](https://jupyterlite.rtfd.io/en/latest/_static/badge-launch.svg)](${jupyterliteLabUrl})`;
const jupyterliteNotebookBadge = `[![JupyterLite Notebook v7](https://jupyterlite.rtfd.io/en/latest/_static/badge-launch.svg)](${jupyterliteNotebookUrl})`;
const introMessage = "Preview environments for this pull request:";
const marker = " :point_left:";
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const binderComment = comments
.slice()
.reverse()
.find(comment => comment.body.includes("![Binder]("));
if (
!binderComment ||
!binderComment.body.includes(marker)
) {
return;
}
const binderMatch = binderComment.body.match(/\[!\[Binder\]\([^)]+\)\]\(([^)]+)\)/);
if (!binderMatch) {
return;
}
const binderUrl = binderMatch[1];
const binderNotebookUrl = binderUrl.includes("urlpath=")
? binderUrl.replace(/urlpath=[^&)]+/, "urlpath=tree")
: `${binderUrl}${binderUrl.includes("?") ? "&" : "?"}urlpath=tree`;
const binderNotebookBadge = `[![Binder Notebook v7](https://mybinder.org/badge_logo.svg)](${binderNotebookUrl})`;
const tableHeader = "| Preview | Lab | Notebook v7 |";
if (
binderComment.body.includes(tableHeader) &&
binderComment.body.includes(introMessage)
) {
return;
}
const previewTable = [
tableHeader,
"| --- | --- | --- |",
`| Binder | [![Binder](https://mybinder.org/badge_logo.svg)](${binderUrl}) | ${binderNotebookBadge} |`,
`| JupyterLite | ${jupyterliteBadge} | ${jupyterliteNotebookBadge} |`
].join("\n");
const updatedBody = [
introMessage,
"",
previewTable
].join("\n");
if (binderComment.body.trim() !== updatedBody.trim()) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: binderComment.id,
body: updatedBody
});
}