Skip to content

Commit f6bbf64

Browse files
authored
Merge pull request #252 from wpengine/consolidate-pr-workflow-comments
ci: Improve plugin artifact bot to reuse comments in PRs
2 parents 7b210af + dec7adb commit f6bbf64

File tree

1 file changed

+34
-5
lines changed

1 file changed

+34
-5
lines changed

.github/workflows/plugin-artifact-for-pr.yml

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ name: Plugin Artifact for PR
33
on:
44
pull_request:
55
paths:
6-
- 'plugins/**'
6+
- 'plugins/**.php'
7+
- 'plugins/**.js'
8+
- 'plugins/**.css'
9+
- 'plugins/**.json'
710

811
jobs:
912
create-plugin-artifact:
@@ -39,10 +42,36 @@ jobs:
3942
const runId = context.runId;
4043
const artifactUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${runId}`;
4144
const slug = process.env.PLUGIN_SLUG;
42-
const body = `ℹ️ [Download the ${slug} plugin artifact from this workflow run](${artifactUrl}) (see the 'Artifacts' section at the bottom).`;
43-
await github.rest.issues.createComment({
45+
const body = `ℹ️ [Download the latest ${slug} plugin zip from this PR](${artifactUrl})\n<em>(See the 'Artifacts' section at the bottom)</em>`;
46+
47+
// Find existing comment from this bot
48+
const comments = await github.rest.issues.listComments({
4449
issue_number: pr.number,
4550
owner: context.repo.owner,
46-
repo: context.repo.repo,
47-
body
51+
repo: context.repo.repo
4852
});
53+
54+
const botComment = comments.data.find(comment =>
55+
comment.user.type === 'Bot' &&
56+
comment.user.login === 'github-actions[bot]' &&
57+
comment.body.includes(`ℹ️ [Download the latest ${slug} plugin zip from this PR]`)
58+
);
59+
60+
if (botComment) {
61+
// Update existing comment
62+
core.info(`Updating existing comment with ID: ${botComment.id}`);
63+
await github.rest.issues.updateComment({
64+
comment_id: botComment.id,
65+
owner: context.repo.owner,
66+
repo: context.repo.repo,
67+
body
68+
});
69+
} else {
70+
// Create new comment
71+
await github.rest.issues.createComment({
72+
issue_number: pr.number,
73+
owner: context.repo.owner,
74+
repo: context.repo.repo,
75+
body
76+
});
77+
}

0 commit comments

Comments
 (0)