Bump nanoid from 3.3.11 to 3.3.18 #132
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 = `[](${jupyterliteLabUrl})`; | |
| const jupyterliteNotebookBadge = `[](${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("); | |
| 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 = `[](${binderNotebookUrl})`; | |
| const tableHeader = "| Preview | Lab | Notebook v7 |"; | |
| if ( | |
| binderComment.body.includes(tableHeader) && | |
| binderComment.body.includes(introMessage) | |
| ) { | |
| return; | |
| } | |
| const previewTable = [ | |
| tableHeader, | |
| "| --- | --- | --- |", | |
| `| Binder | [](${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 | |
| }); | |
| } |