Skip to content

Commit 2613a77

Browse files
authored
fix(ci): update docs preview to edit PR description instead of comment (#4620)
1 parent e68dd0b commit 2613a77

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

.github/workflows/docs-preview.yml

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -60,30 +60,33 @@ jobs:
6060
PR_NUMBER: ${{ env.PR_NUMBER }}
6161
with:
6262
script: |
63-
const issue_number = process.env.PR_NUMBER
64-
const body = "Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/" + issue_number
63+
const issue_number = parseInt(process.env.PR_NUMBER, 10)
64+
const previewUrl = "https://litestar-org.github.io/litestar-docs-preview/" + issue_number
65+
const marker = "<!-- docs-preview -->"
66+
const section = marker + "\n\n<hr>\n📚 Documentation preview 📚: " + previewUrl + "\n"
6567
66-
const opts = github.rest.issues.listComments.endpoint.merge({
68+
const { data: pr } = await github.rest.pulls.get({
6769
owner: context.repo.owner,
6870
repo: context.repo.repo,
69-
issue_number: issue_number,
70-
});
71+
pull_number: issue_number,
72+
})
7173
72-
const comments = await github.paginate(opts)
74+
let body = pr.body || ""
7375
74-
for (const comment of comments) {
75-
if (comment.user.id === 41898282 && comment.body === body) {
76-
await github.rest.issues.deleteComment({
77-
owner: context.repo.owner,
78-
repo: context.repo.repo,
79-
comment_id: comment.id
80-
})
81-
}
76+
if (body.includes(marker)) {
77+
// Update existing section
78+
body = body.replace(
79+
new RegExp(marker + "[\\s\\S]*$"),
80+
section,
81+
)
82+
} else {
83+
// Append section
84+
body = body + "\n\n" + section
8285
}
8386
84-
await github.rest.issues.createComment({
85-
owner: context.repo.owner,
86-
repo: context.repo.repo,
87-
issue_number: issue_number,
88-
body: body,
87+
await github.rest.pulls.update({
88+
owner: context.repo.owner,
89+
repo: context.repo.repo,
90+
pull_number: issue_number,
91+
body: body,
8992
})

0 commit comments

Comments
 (0)