mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
🔄 Add auto-update functionality to playground comments
This commit is contained in:
parent
bd51ff22aa
commit
37a465ca89
2 changed files with 32 additions and 25 deletions
40
.github/scripts/playground-comment.js
vendored
40
.github/scripts/playground-comment.js
vendored
|
@ -78,8 +78,13 @@ async function run({ github, context, core }) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Comments are only added after the first successful build.
|
||||
// The caller should check for existing comments before calling this function.
|
||||
// Check for existing playground comment to update instead of creating duplicate
|
||||
const comments = await github.rest.issues.listComments(commentInfo);
|
||||
|
||||
const existingComment = comments.data.find(comment =>
|
||||
comment.user.type === 'Bot' &&
|
||||
comment.body.includes('Test using WordPress Playground')
|
||||
);
|
||||
|
||||
const defaultSchema = generateWordpressPlaygroundBlueprint(
|
||||
context.runId,
|
||||
|
@ -111,19 +116,36 @@ The changes in this pull request can be previewed and tested using a [WordPress
|
|||
|
||||
> 💡 The demo environment resets each time you refresh. Perfect for testing!
|
||||
>
|
||||
> ⚠️ This URL is valid for 30 days from when this comment was last updated. You can refresh it by pushing a new commit.
|
||||
> 🔄 This link updates automatically with each new commit to the PR.
|
||||
>
|
||||
> ⚠️ This URL is valid for 30 days from when this comment was last updated.
|
||||
|
||||
---
|
||||
<sub>🤖 Auto-generated for commit ${context.payload.pull_request.head.sha}</sub>`;
|
||||
<sub>🤖 Auto-generated for commit ${context.payload.pull_request.head.sha} • Last updated: ${new Date().toISOString()}</sub>`;
|
||||
|
||||
// Create the comment
|
||||
commentInfo.body = body;
|
||||
await github.rest.issues.createComment(commentInfo);
|
||||
if (existingComment) {
|
||||
// Update existing comment
|
||||
await github.rest.issues.updateComment({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
comment_id: existingComment.id,
|
||||
body: body
|
||||
});
|
||||
|
||||
core.info('Successfully created playground comment on PR');
|
||||
core.info(`Successfully updated existing playground comment #${existingComment.id} on PR #${context.issue.number}`);
|
||||
} else {
|
||||
// Create new comment
|
||||
await github.rest.issues.createComment({
|
||||
...commentInfo,
|
||||
body: body
|
||||
});
|
||||
|
||||
core.info(`Successfully created new playground comment on PR #${context.issue.number}`);
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
core.setFailed(`Failed to create playground comment: ${error.message}`);
|
||||
core.setFailed(`Failed to create/update playground comment: ${error.message}`);
|
||||
core.error(`Error details: ${error.stack}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
17
.github/workflows/pr-playground-demo.yml
vendored
17
.github/workflows/pr-playground-demo.yml
vendored
|
@ -109,7 +109,7 @@ jobs:
|
|||
- name: Unzip PR details
|
||||
run: unzip pr-details.zip
|
||||
|
||||
- name: Comment on PR with WordPress Playground link
|
||||
- name: Create or update PR playground comment
|
||||
uses: actions/github-script@v7
|
||||
with:
|
||||
script: |
|
||||
|
@ -118,21 +118,6 @@ jobs:
|
|||
const plugin_version = fs.readFileSync('./VERSION', 'utf8').trim();
|
||||
const artifact_name = fs.readFileSync('./ARTIFACT', 'utf8').trim();
|
||||
|
||||
// Check for existing comment to avoid duplicates
|
||||
const commentInfo = {
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number,
|
||||
};
|
||||
|
||||
const comments = (await github.rest.issues.listComments(commentInfo)).data;
|
||||
|
||||
for (const currentComment of comments) {
|
||||
if (currentComment.user.type === 'Bot' && currentComment.body.includes('Test using WordPress Playground')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Load the comment script
|
||||
const script = require('./.github/scripts/playground-comment.js');
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue