Skip to content

Commit cb7b41c

Browse files
authored
Clean up preview badge comment to avoid duplicate Binder badge (jupyterlab#137)
1 parent ed4256f commit cb7b41c

1 file changed

Lines changed: 19 additions & 16 deletions

File tree

.github/workflows/preview-badges-on-pr.yml

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: Preview Badges
22
on:
33
pull_request_target:
4-
types: [opened, synchronize, reopened]
4+
types: [opened, reopened]
55

66
jobs:
77
previews:
@@ -23,6 +23,7 @@ jobs:
2323
const jupyterliteNotebookUrl = `https://${docsSlug}--${prNumber}.org.readthedocs.build/en/${prNumber}/lite/tree/`;
2424
const jupyterliteBadge = `[![JupyterLite](https://jupyterlite.rtfd.io/en/latest/_static/badge-launch.svg)](${jupyterliteLabUrl})`;
2525
const jupyterliteNotebookBadge = `[![JupyterLite Notebook v7](https://jupyterlite.rtfd.io/en/latest/_static/badge-launch.svg)](${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,
@@ -50,7 +51,10 @@ jobs:
5051
: `${binderUrl}${binderUrl.includes("?") ? "&" : "?"}urlpath=tree`;
5152
const binderNotebookBadge = `[![Binder Notebook v7](https://mybinder.org/badge_logo.svg)](${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 | [![Binder](https://mybinder.org/badge_logo.svg)](${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

Comments
 (0)