Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add threshold option #16

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions action.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,24 +163,29 @@ async function run(octokit, context) {

// no previous or edit failed
if (!commentId) {
console.log('Creating new comment');
try {
await octokit.issues.createComment(comment);
} catch (e) {
console.log(`Error creating comment: ${e.message}`);
console.log(`Submitting a PR review comment instead...`);
const threshold = Number(getInput('delta-threshold'));
if (!isNaN(threshold) && Math.abs(diff.delta) < threshold) {
console.log(`Skipping comment creation because size delta ${Math.abs(diff.delta)} is less than configured threshold ${threshold}`);
} else {
console.log('Creating new comment');
try {
const issue = context.issue || pr;
await octokit.pulls.createReview({
owner: issue.owner,
repo: issue.repo,
pull_number: issue.number,
event: 'COMMENT',
body: comment.body
});
await octokit.issues.createComment(comment);
} catch (e) {
console.log('Error creating PR review.');
outputRawMarkdown = true;
console.log(`Error creating comment: ${e.message}`);
console.log(`Submitting a PR review comment instead...`);
try {
const issue = context.issue || pr;
await octokit.pulls.createReview({
owner: issue.owner,
repo: issue.repo,
pull_number: issue.number,
event: 'COMMENT',
body: comment.body
});
} catch (e) {
console.log('Error creating PR review.');
outputRawMarkdown = true;
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ inputs:
default: 'true'
omit-unchanged:
description: 'Exclude unchanged files from the sizes table entirely'
delta-threshold:
description: 'Minimum absolute size change required as condition to report'
runs:
using: 'node12'
main: 'index.js'