Skip to content

Commit

Permalink
feat: separate knip report and deployment comments
Browse files Browse the repository at this point in the history
  • Loading branch information
zugdev committed Oct 14, 2024
1 parent 320cd40 commit a065e22
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 19 deletions.
32 changes: 15 additions & 17 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,23 @@ jobs:
issue_number,
});
// Find the comment to update or create a new one if not found
let existingComment = comments.data.find(comment => comment.user.login === 'github-actions[bot]');
let body = '| Preview Deployment |\n| ------------------ |\n';
// Look for an existing "Preview Deployment" comment
let previewComment = comments.data.find(comment =>
comment.body.startsWith("| Preview Deployment |")
);
// If the comment exists, update its body
if (existingComment) {
// Check if the SHA already exists in the comment body to avoid duplicates
if (!existingComment.body.includes(sha)) {
body = existingComment.body + `| [${sha}](${{ env.CLAIMABLE_URL }}) |\n`;
await github.rest.issues.updateComment({
owner,
repo,
comment_id: existingComment.id,
body
});
}
const body = `| Preview Deployment |\n| ------------------ |\n| [${sha}](${{ env.CLAIMABLE_URL }}) |\n`;
if (previewComment) {
// Update the existing "Preview Deployment" comment
await github.rest.issues.updateComment({
owner,
repo,
comment_id: previewComment.id,
body
});
} else {
// Create a new comment if no existing comment is found
body += `| [${sha}](${{ env.CLAIMABLE_URL }}) |\n`;
// Create a new "Preview Deployment" comment if not found
await github.rest.issues.createComment({
owner,
repo,
Expand Down
32 changes: 30 additions & 2 deletions .github/workflows/knip-reporter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,39 @@ jobs:
path: ./pr-number.txt
trim: true

- name: Report knip results to pull request
- name: Get or create comment ID for Knip Report
id: get-comment
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const issue_number = ${{ steps.pr-number.outputs.content }};
// Fetch all comments on the PR
const comments = await github.rest.issues.listComments({
owner,
repo,
issue_number,
});
// Look for an existing Knip report comment
let knipComment = comments.data.find(comment =>
comment.body.startsWith("| Knip Report |")
);
if (knipComment) {
console.log('Found existing Knip report comment:', knipComment.id);
core.setOutput('comment_id', knipComment.id); // Set the comment ID output
} else {
console.log('No existing Knip report comment found.');
core.setOutput('comment_id', ''); // No existing comment
}
- name: Report Knip results to pull request
uses: gitcoindev/knip-reporter@main
with:
verbose: true
comment_id: ${{ github.workflow }}-reporter
comment_id: ${{ steps.get-comment.outputs.comment_id || github.workflow }}-knip-report
command_script_name: knip-ci
annotations: true
ignore_results: false
Expand Down

0 comments on commit a065e22

Please sign in to comment.