11name : Preview Badges
22on :
33 pull_request_target :
4- types : [opened, synchronize, reopened]
4+ types : [opened, reopened]
55
66jobs :
77 previews :
2323 const jupyterliteNotebookUrl = `https://${docsSlug}--${prNumber}.org.readthedocs.build/en/${prNumber}/lite/tree/`;
2424 const jupyterliteBadge = `[](${jupyterliteLabUrl})`;
2525 const jupyterliteNotebookBadge = `[](${jupyterliteNotebookUrl})`;
26+ const introMessage = "Preview environments for this pull request:";
2627 const marker = " :point_left:";
2728 const { data: comments } = await github.rest.issues.listComments({
2829 owner: context.repo.owner,
5051 : `${binderUrl}${binderUrl.includes("?") ? "&" : "?"}urlpath=tree`;
5152 const binderNotebookBadge = `[](${binderNotebookUrl})`;
5253 const tableHeader = "| Preview | Lab | Notebook v7 |";
53- if (binderComment.body.includes(tableHeader)) {
54+ if (
55+ binderComment.body.includes(tableHeader) &&
56+ binderComment.body.includes(introMessage)
57+ ) {
5458 return;
5559 }
5660
@@ -60,17 +64,16 @@ jobs:
6064 `| Binder | [](${binderUrl}) | ${binderNotebookBadge} |`,
6165 `| JupyterLite | ${jupyterliteBadge} | ${jupyterliteNotebookBadge} |`
6266 ].join("\n");
63- const cleanedBody = binderComment.body
64- .replace(/\s*\[!\[Binder Notebook v7\]\([^)]+\)\]\([^)]+\)/g, "")
65- .replace(/\s*\[!\[JupyterLite\]\([^)]+\)\]\([^)]+\)/g, "")
66- .replace(/\s*\[!\[JupyterLite Notebook v7\]\([^)]+\)\]\([^)]+\)/g, "");
67- const updatedBody = cleanedBody.replace(
68- marker,
69- `\n\n${previewTable}\n${marker}`
70- );
71- await github.rest.issues.updateComment({
72- owner: context.repo.owner,
73- repo: context.repo.repo,
74- comment_id: binderComment.id,
75- body: updatedBody
76- });
67+ const updatedBody = [
68+ introMessage,
69+ "",
70+ previewTable
71+ ].join("\n");
72+ if (binderComment.body.trim() !== updatedBody.trim()) {
73+ await github.rest.issues.updateComment({
74+ owner: context.repo.owner,
75+ repo: context.repo.repo,
76+ comment_id: binderComment.id,
77+ body: updatedBody
78+ });
79+ }
0 commit comments