@@ -241,11 +241,16 @@ jobs:
241241 ALL_CHANGED_FILES : ${{ steps.check-files.outputs.all_changed_files }}
242242 with :
243243 script : |
244+ const title = '### Preview links for changed docs'
244245 const changedMdFiles = process.env.ALL_CHANGED_FILES
245246 .split(/\s+/)
246247 .filter(i => i.endsWith('.md'))
247248 .filter(i => !i.includes('/_snippets/'));
248249
250+ if (changedMdFiles.length === 0) {
251+ return;
252+ }
253+
249254 const toLink = (file) => {
250255 const path = file
251256 .replace('docs/', '')
@@ -256,14 +261,42 @@ jobs:
256261
257262 const links = changedMdFiles.map(toLink)
258263
259- if (changedMdFiles.length > 0) {
264+ const body = [
265+ title,
266+ ...links.slice(0, 20).map(i => `- ${i}`),
267+ '<sub>This comment is only showing the first 20 links.</sub>',
268+ ]
269+
270+ if (links.length > 20) {
271+ body.push('');
272+ body.push(`<sub>There are ${links.length - 20} more links...</sub>`);
273+ }
274+
275+ const owner = context.repo.owner;
276+ const repo = context.repo.repo;
277+ const issue_number = context.payload.pull_request.number;
278+
279+ // Post or update a single bot comment
280+ const { data: comments } = await github.rest.issues.listComments({
281+ owner, repo, issue_number
282+ });
283+ const existing = comments.find(c =>
284+ c.user.type === 'Bot' &&
285+ c.body.startsWith(title)
286+ );
287+ if (existing) {
288+ await github.rest.issues.updateComment({
289+ owner, repo,
290+ comment_id: existing.id,
291+ body: body.join('\n'),
292+ });
293+ } else {
260294 await github.rest.issues.createComment({
261- owner: context.repo.owner,
262- repo: context.repo.repo,
263- issue_number: context.payload.pull_request.number,
264- body: `**${changedMdFiles.length} markdown files changed:**\n\n - ${links.join('\n -')}`
295+ owner, repo,
296+ issue_number,
297+ body:body.join('\n'),
265298 });
266- }
299+ }
267300
268301 - name : Update Link Index
269302 if : |
0 commit comments