Skip to content

Commit

Permalink
feat: add input to control PR comments on success (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
tvcsantos authored Sep 19, 2023
1 parent 0159e74 commit 4b6a52f
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.3.0] - 2023-09-19

### Added

- Add `comment-pr-on-success` input to control PR comments on success

## [1.2.0] - 2023-09-12

### Changed
Expand Down Expand Up @@ -45,7 +51,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Improve logging
- Update dependencies and refactor action

[Unreleased]: https://github.com/mercedesbenzio/detect-action/compare/v1.2.0...main
[Unreleased]: https://github.com/mercedesbenzio/detect-action/compare/v1.3.0...main
[1.3.0]: https://github.com/mercedesbenzio/detect-action/compare/v1.2.0...v1.3.0
[1.2.0]: https://github.com/mercedesbenzio/detect-action/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/mercedesbenzio/detect-action/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/mercedesbenzio/detect-action/compare/v0.4.0...v1.0.0
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ inputs:
description: 'Fail the action if detect exits with an error code'
required: false
default: 'false'
comment-pr-on-success:
description: 'Comment pull requests if no violations found'
required: false
default: 'true'
outputs:
detect-exit-code:
description: 'A number indicating Detect exit code'
Expand Down
14 changes: 11 additions & 3 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "detect-action",
"description": "Richly integrate Synopsys Detect and Black Duck policy into your GitHub Action pipelines",
"version": "1.2.0",
"version": "1.3.0",
"author": "Mercedes-Benz.io",
"private": true,
"homepage": "https://github.com/mercedesbenzio/detect-action",
Expand Down
8 changes: 6 additions & 2 deletions src/detect/detect-facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,12 @@ export class DetectFacade {
}
)

if (this.context.isPullRequest()) {
core.info('This is a pull request, commenting...')
const commentInContext =
(this.inputs.commentPrOnSuccess && !reportResult.failed) ||
reportResult.failed

if (this.context.isPullRequest() && commentInContext) {
core.info('Commenting pull request...')
await this.commentReporter.report(reportResult)
core.info('Successfully commented on PR.')
}
Expand Down
12 changes: 10 additions & 2 deletions src/input/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface Inputs {
outputPathOverride: string
detectTrustCertificate: string
failIfDetectFails: boolean
commentPrOnSuccess: boolean
}

export enum Input {
Expand All @@ -22,7 +23,8 @@ export enum Input {
FAIL_ON_ALL_POLICY_SEVERITIES = 'fail-on-all-policy-severities',
OUTPUT_PATH_OVERRIDE = 'output-path-override',
DETECT_TRUST_CERTIFICATE = 'detect-trust-cert',
FAIL_IF_DETECT_FAILS = 'fail-if-detect-fails'
FAIL_IF_DETECT_FAILS = 'fail-if-detect-fails',
COMMENT_PR_ON_SUCCESS = 'comment-pr-on-success'
}

export function gatherInputs(): Inputs {
Expand All @@ -35,6 +37,7 @@ export function gatherInputs(): Inputs {
const outputPathOverride = getInputOutputPathOverride()
const detectTrustCertificate = getInputDetectTrustCertificate()
const failIfDetectFails = getInputFailIfDetectFails()
const commentPrOnSuccess = getInputCommentPrOnSuccess()
return {
token,
blackDuckUrl,
Expand All @@ -44,7 +47,8 @@ export function gatherInputs(): Inputs {
failOnAllPolicySeverities,
outputPathOverride,
detectTrustCertificate,
failIfDetectFails
failIfDetectFails,
commentPrOnSuccess
}
}

Expand Down Expand Up @@ -83,3 +87,7 @@ function getInputDetectTrustCertificate(): string {
function getInputFailIfDetectFails(): boolean {
return core.getBooleanInput(Input.FAIL_IF_DETECT_FAILS)
}

function getInputCommentPrOnSuccess(): boolean {
return core.getBooleanInput(Input.COMMENT_PR_ON_SUCCESS)
}

0 comments on commit 4b6a52f

Please sign in to comment.