Skip to content
This repository was archived by the owner on Jan 26, 2025. It is now read-only.

Commit 4b6a52f

Browse files
authored
feat: add input to control PR comments on success (#11)
1 parent 0159e74 commit 4b6a52f

File tree

7 files changed

+42
-11
lines changed

7 files changed

+42
-11
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.3.0] - 2023-09-19
9+
10+
### Added
11+
12+
- Add `comment-pr-on-success` input to control PR comments on success
13+
814
## [1.2.0] - 2023-09-12
915

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

48-
[Unreleased]: https://github.com/mercedesbenzio/detect-action/compare/v1.2.0...main
54+
[Unreleased]: https://github.com/mercedesbenzio/detect-action/compare/v1.3.0...main
55+
[1.3.0]: https://github.com/mercedesbenzio/detect-action/compare/v1.2.0...v1.3.0
4956
[1.2.0]: https://github.com/mercedesbenzio/detect-action/compare/v1.1.0...v1.2.0
5057
[1.1.0]: https://github.com/mercedesbenzio/detect-action/compare/v1.0.0...v1.1.0
5158
[1.0.0]: https://github.com/mercedesbenzio/detect-action/compare/v0.4.0...v1.0.0

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ inputs:
4747
description: 'Fail the action if detect exits with an error code'
4848
required: false
4949
default: 'false'
50+
comment-pr-on-success:
51+
description: 'Comment pull requests if no violations found'
52+
required: false
53+
default: 'true'
5054
outputs:
5155
detect-exit-code:
5256
description: 'A number indicating Detect exit code'

dist/index.js

Lines changed: 11 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "detect-action",
33
"description": "Richly integrate Synopsys Detect and Black Duck policy into your GitHub Action pipelines",
4-
"version": "1.2.0",
4+
"version": "1.3.0",
55
"author": "Mercedes-Benz.io",
66
"private": true,
77
"homepage": "https://github.com/mercedesbenzio/detect-action",

src/detect/detect-facade.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,12 @@ export class DetectFacade {
160160
}
161161
)
162162

163-
if (this.context.isPullRequest()) {
164-
core.info('This is a pull request, commenting...')
163+
const commentInContext =
164+
(this.inputs.commentPrOnSuccess && !reportResult.failed) ||
165+
reportResult.failed
166+
167+
if (this.context.isPullRequest() && commentInContext) {
168+
core.info('Commenting pull request...')
165169
await this.commentReporter.report(reportResult)
166170
core.info('Successfully commented on PR.')
167171
}

src/input/inputs.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface Inputs {
1010
outputPathOverride: string
1111
detectTrustCertificate: string
1212
failIfDetectFails: boolean
13+
commentPrOnSuccess: boolean
1314
}
1415

1516
export enum Input {
@@ -22,7 +23,8 @@ export enum Input {
2223
FAIL_ON_ALL_POLICY_SEVERITIES = 'fail-on-all-policy-severities',
2324
OUTPUT_PATH_OVERRIDE = 'output-path-override',
2425
DETECT_TRUST_CERTIFICATE = 'detect-trust-cert',
25-
FAIL_IF_DETECT_FAILS = 'fail-if-detect-fails'
26+
FAIL_IF_DETECT_FAILS = 'fail-if-detect-fails',
27+
COMMENT_PR_ON_SUCCESS = 'comment-pr-on-success'
2628
}
2729

2830
export function gatherInputs(): Inputs {
@@ -35,6 +37,7 @@ export function gatherInputs(): Inputs {
3537
const outputPathOverride = getInputOutputPathOverride()
3638
const detectTrustCertificate = getInputDetectTrustCertificate()
3739
const failIfDetectFails = getInputFailIfDetectFails()
40+
const commentPrOnSuccess = getInputCommentPrOnSuccess()
3841
return {
3942
token,
4043
blackDuckUrl,
@@ -44,7 +47,8 @@ export function gatherInputs(): Inputs {
4447
failOnAllPolicySeverities,
4548
outputPathOverride,
4649
detectTrustCertificate,
47-
failIfDetectFails
50+
failIfDetectFails,
51+
commentPrOnSuccess
4852
}
4953
}
5054

@@ -83,3 +87,7 @@ function getInputDetectTrustCertificate(): string {
8387
function getInputFailIfDetectFails(): boolean {
8488
return core.getBooleanInput(Input.FAIL_IF_DETECT_FAILS)
8589
}
90+
91+
function getInputCommentPrOnSuccess(): boolean {
92+
return core.getBooleanInput(Input.COMMENT_PR_ON_SUCCESS)
93+
}

0 commit comments

Comments
 (0)