fix: add summary comment on failure when warn-only: true #827
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #817
Summary
When the parameter
warn-only
is set totrue
, allow a pull request comment to be created whencomment-summary-in-pr
is set toon-failure
.Testing
The action was tested with the following scenarios:
warn-only: true
,comment-summary-in-pr: always
warn-only: true
,comment-summary-in-pr: on-failure
warn-only: true
,comment-summary-in-pr: never
warn-only: true
,comment-summary-in-pr: always
warn-only: true
,comment-summary-in-pr: on-failure
warn-only: true
,comment-summary-in-pr: never
Unit tests have not been added since both
main.ts
andcomment-pr.ts
currently lack unit test files. I looked at adding unit tests forcomment-pr.ts
but the static octokit constructor (new retryingOctokit
) made this extremely difficult due tojest.mock
hoisting. To make the file more testable,retryingOctokit
should be replaced with non-static logic, such as an update tooctokitClient
inutils.ts
that would have an optional parameter to allow retries. This change would have been much larger and far beyond the scope of this pull request.Implementation decisions
config.comment_summary_in_pr === 'on-failure'
test incomment-pr.ts
to no longer rely on a non-zero exit code. To signal a failure, a new parameter was added to thecommentPr
function.failureCount: number
was used instead of a boolean to simplify the logic - it's much easier to incrementally do afailureCount +=
than to try to do boolean logic on the same line as function calls. In addition,failureCount
seemed more useful for future action logging.setFailed
withindeny.ts
was moved out intoprintDeniedDependencies
.failureCount
variable inmain.ts
can be used for other future functionality, such as an implementation of Add option for commit status check #825