Skip to content

Commit

Permalink
New variable for adding pull request comment title (#556)
Browse files Browse the repository at this point in the history
  • Loading branch information
omerzi authored Oct 25, 2023
1 parent aa81ad1 commit 5d0e9da
Show file tree
Hide file tree
Showing 27 changed files with 262 additions and 30 deletions.
4 changes: 4 additions & 0 deletions docs/install-azure-pipelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ jobs:
# The full list of licenses can be found in:
# https://github.com/jfrog/frogbot/blob/master/docs/licenses.md
# JF_ALLOWED_LICENSES: "MIT, Apache-2.0"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""

inputs:
script: |
Expand Down
4 changes: 4 additions & 0 deletions docs/install-gitlab.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ frogbot-scan:
# https://github.com/jfrog/frogbot/blob/master/docs/licenses.md
# JF_ALLOWED_LICENSES: "MIT, Apache-2.0"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""

script:
# For Linux / MacOS runner:
- |
Expand Down
8 changes: 8 additions & 0 deletions docs/templates/.frogbot/frogbot-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@
# The template can optionally include the {IMPACTED_PACKAGE} and {FIX_VERSION} variables.
# pullRequestTitleTemplate: "[🐸 Frogbot] Upgrade {IMPACTED_PACKAGE} to {FIX_VERSION}"

# [Optional]
# Avoid adding extra info to pull request comments. that isn't related to the scan findings.
# avoidExtraMessages: false

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# pullRequestCommentTitle: ""

# [Optional, Default: false]
# If true, Frogbot creates a single pull request with all the fixes.
# If false, Frogbot creates a separate pull request for each fix.
Expand Down
4 changes: 4 additions & 0 deletions docs/templates/github-actions/frogbot-scan-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,7 @@ jobs:
# [Optional]
# Avoid adding extra info to pull request comments. that isn't related to the scan findings.
# JF_AVOID_EXTRA_MESSAGES: "TRUE"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""
6 changes: 5 additions & 1 deletion docs/templates/jenkins/scan-pull-request.jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ pipeline {
// List of comma separated email addresses to receive email notifications about secrets
// detected during pull request scanning. The notification is also sent to the email set
// in the committer git profile regardless of whether this variable is set or not.
// JF_EMAIL_RECEIVERS: ""
// JF_EMAIL_RECEIVERS= ""

// [Optional]
// Add a title to pull request comments generated by Frogbot.
// JF_PR_COMMENT_TITLE= ""
}

stages {
Expand Down
4 changes: 4 additions & 0 deletions docs/templates/jfrog-pipelines/pipelines-dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ pipelines:
# https://github.com/jfrog/frogbot/blob/master/docs/licenses.md
# JF_ALLOWED_LICENSES: "MIT, Apache-2.0"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""

execution:
onExecute:
- cd $res_frogbotGitRepo_resourcePath
Expand Down
4 changes: 4 additions & 0 deletions docs/templates/jfrog-pipelines/pipelines-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ pipelines:
# https://github.com/jfrog/frogbot/blob/master/docs/licenses.md
# JF_ALLOWED_LICENSES: "MIT, Apache-2.0"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""

execution:
onExecute:
- cd $res_frogbotGitRepo_resourcePath
Expand Down
4 changes: 4 additions & 0 deletions docs/templates/jfrog-pipelines/pipelines-gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ pipelines:
# https://github.com/jfrog/frogbot/blob/master/docs/licenses.md
# JF_ALLOWED_LICENSES: "MIT, Apache-2.0"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""

execution:
onExecute:
- cd $res_frogbotGitRepo_resourcePath
Expand Down
4 changes: 4 additions & 0 deletions docs/templates/jfrog-pipelines/pipelines-maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,10 @@ pipelines:
# https://github.com/jfrog/frogbot/blob/master/docs/licenses.md
# JF_ALLOWED_LICENSES: "MIT, Apache-2.0"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""

execution:
onExecute:
- cd $res_frogbotGitRepo_resourcePath
Expand Down
4 changes: 4 additions & 0 deletions docs/templates/jfrog-pipelines/pipelines-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ pipelines:
# https://github.com/jfrog/frogbot/blob/master/docs/licenses.md
# JF_ALLOWED_LICENSES: "MIT, Apache-2.0"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""

execution:
onExecute:
- cd $res_frogbotGitRepo_resourcePath
Expand Down
4 changes: 4 additions & 0 deletions docs/templates/jfrog-pipelines/pipelines-pip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,10 @@ pipelines:
# https://github.com/jfrog/frogbot/blob/master/docs/licenses.md
# JF_ALLOWED_LICENSES: "MIT, Apache-2.0"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""

execution:
onExecute:
- cd $res_frogbotGitRepo_resourcePath
Expand Down
4 changes: 4 additions & 0 deletions docs/templates/jfrog-pipelines/pipelines-pipenv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ pipelines:
# https://github.com/jfrog/frogbot/blob/master/docs/licenses.md
# JF_ALLOWED_LICENSES: "MIT, Apache-2.0"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""

execution:
onExecute:
- cd $res_frogbotGitRepo_resourcePath
Expand Down
4 changes: 4 additions & 0 deletions docs/templates/jfrog-pipelines/pipelines-poetry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,10 @@ pipelines:
# https://github.com/jfrog/frogbot/blob/master/docs/licenses.md
# JF_ALLOWED_LICENSES: "MIT, Apache-2.0"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""

execution:
onExecute:
- cd $res_frogbotGitRepo_resourcePath
Expand Down
4 changes: 4 additions & 0 deletions docs/templates/jfrog-pipelines/pipelines-yarn2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ pipelines:
# https://github.com/jfrog/frogbot/blob/master/docs/licenses.md
# JF_ALLOWED_LICENSES: "MIT, Apache-2.0"

# [Optional]
# Add a title to pull request comments generated by Frogbot.
# JF_PR_COMMENT_TITLE: ""

execution:
onExecute:
- cd $res_frogbotGitRepo_resourcePath
Expand Down
14 changes: 14 additions & 0 deletions schema/frogbot-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,26 @@
"pullRequestTitleTemplate": {
"type": "string",
"default": "",
"description": "Add a title to pull request comments generated by Frogbot.",
"examples": [
"[Frogbot]-{IMPACTED_PACKAGE}",
"[Security_Update]-{FIX_VERSION}",
"[Feature]"
]
},
"avoidExtraMessages": {
"type": "boolean",
"default": "false",
"description": "Avoid adding extra info to pull request comments. that isn't related to the scan findings."
},
"pullRequestCommentTitle": {
"type": "string",
"default": "",
"examples": [
"Pipelines 1",
"Build 2321"
]
},
"aggregateFixes": {
"type": "boolean",
"default": "false"
Expand Down
1 change: 1 addition & 0 deletions testdata/config/frogbot-config-test-params.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
commitMessageTemplate: "custom commit title"
pullRequestTitleTemplate: "myPullRequests"
aggregateFixes: true
pullRequestCommentTitle: "build 1323"
scan:
includeAllVulnerabilities: true
failOnSecurityIssues: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div align='center'>

[![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/v2/vulnerabilitiesBannerMR.png)](https://github.com/jfrog/frogbot#readme)

</div>

## Test Build

```
some content
```


---
<div align='center'>

[🐸 JFrog Frogbot](https://github.com/jfrog/frogbot#readme)

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<div align='center'>

[![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/v2/vulnerabilitiesBannerPR.png)](https://github.com/jfrog/frogbot#readme)

</div>

## Test Build

```
some content
```
<details>
<summary>Note</summary>

---
<div align='center'>

**Frogbot** also supports **Contextual Analysis, Secret Detection, IaC and SAST Vulnerabilities Scanning**. This features are included as part of the [JFrog Advanced Security](https://jfrog.com/advanced-security) package, which isn't enabled on your system.

</div>

</details>

---
<div align='center'>

[🐸 JFrog Frogbot](https://github.com/jfrog/frogbot#readme)

</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
**🚨 Frogbot scanned this pull request and found the below:**

**Test Build**

```
some content
```


---
[🐸 JFrog Frogbot](https://github.com/jfrog/frogbot#readme)
1 change: 1 addition & 0 deletions utils/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
BranchNameTemplateEnv = "JF_BRANCH_NAME_TEMPLATE"
CommitMessageTemplateEnv = "JF_COMMIT_MESSAGE_TEMPLATE"
PullRequestTitleTemplateEnv = "JF_PULL_REQUEST_TITLE_TEMPLATE"
PullRequestCommentTitleEnv = "JF_PR_COMMENT_TITLE"

// Repository environment variables - Ignored if the frogbot-config.yml file is used
InstallCommandEnv = "JF_INSTALL_DEPS_CMD"
Expand Down
8 changes: 8 additions & 0 deletions utils/outputwriter/outputcontent.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ var (
func GetPRSummaryContent(content string, issuesExists, isComment bool, writer OutputWriter) string {
comment := strings.Builder{}
comment.WriteString(writer.Image(getPRSummaryBanner(issuesExists, isComment, writer.VcsProvider())))
customCommentTitle := writer.PullRequestCommentTitle()
if customCommentTitle != "" {
comment.WriteString(customCommentTitle)
}
if issuesExists {
WriteContent(&comment, content)
}
Expand Down Expand Up @@ -239,6 +243,10 @@ func LicensesContent(licenses []formats.LicenseRow, writer OutputWriter) string
func GenerateReviewCommentContent(content string, writer OutputWriter) string {
var contentBuilder strings.Builder
contentBuilder.WriteString(MarkdownComment(ReviewCommentId))
customCommentTitle := writer.PullRequestCommentTitle()
if customCommentTitle != "" {
contentBuilder.WriteString(customCommentTitle)
}
WriteContent(&contentBuilder, content, footer(writer))
return contentBuilder.String()
}
Expand Down
35 changes: 31 additions & 4 deletions utils/outputwriter/outputcontent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,11 @@ func TestIsFrogbotSummaryComment(t *testing.T) {

func TestGetPRSummaryContent(t *testing.T) {
testCases := []struct {
name string
cases []OutputTestCase
issuesExists bool
isComment bool
name string
cases []OutputTestCase
issuesExists bool
isComment bool
addPullRequestCommentTitle bool
}{
{
name: "Summary comment No issues found",
Expand Down Expand Up @@ -257,6 +258,29 @@ func TestGetPRSummaryContent(t *testing.T) {
},
},
},
{
name: "Summary comments with issues with pull request title",
issuesExists: true,
isComment: true,
addPullRequestCommentTitle: true,
cases: []OutputTestCase{
{
name: "Merge Request entitled (Standard output)",
writer: &StandardOutput{MarkdownOutput{entitledForJas: true, vcsProvider: vcsutils.GitLab}},
expectedOutputPath: filepath.Join(testSummaryCommentDir, "structure", "summary_comment_mr_issues_entitled_with_title.md"),
},
{
name: "Pull Request not entitled (Standard output)",
writer: &StandardOutput{},
expectedOutputPath: filepath.Join(testSummaryCommentDir, "structure", "summary_comment_pr_issues_not_entitled_with_title.md"),
},
{
name: "Pull request entitled (Simplified output)",
writer: &SimplifiedOutput{MarkdownOutput{entitledForJas: true}},
expectedOutputPath: filepath.Join(testSummaryCommentDir, "structure", "summary_comment_simplified_issues_entitled_with_title.md"),
},
},
},
{
name: "Frogbot Fix issues details content",
issuesExists: true,
Expand Down Expand Up @@ -301,6 +325,9 @@ func TestGetPRSummaryContent(t *testing.T) {
for _, tc := range testCases {
for _, test := range tc.cases {
t.Run(tc.name+"_"+test.name, func(t *testing.T) {
if tc.addPullRequestCommentTitle {
test.writer.SetPullRequestCommentTitle("Test Build")
}
expectedOutput := GetExpectedTestOutput(t, test)
output := GetPRSummaryContent(content, tc.issuesExists, tc.isComment, test.writer)
assert.Equal(t, expectedOutput, output)
Expand Down
11 changes: 7 additions & 4 deletions utils/outputwriter/outputwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ type OutputWriter interface {
IsEntitledForJas() bool
SetAvoidExtraMessages(avoidExtraMessages bool)
AvoidExtraMessages() bool
SetPullRequestCommentTitle(pullRequestCommentTitle string)
PullRequestCommentTitle() string
// VCS info
VcsProvider() vcsutils.VcsProvider
SetVcsProvider(provider vcsutils.VcsProvider)
Expand All @@ -107,10 +109,11 @@ type OutputWriter interface {
}

type MarkdownOutput struct {
avoidExtraMessages bool
showCaColumn bool
entitledForJas bool
vcsProvider vcsutils.VcsProvider
pullRequestCommentTitle string
avoidExtraMessages bool
showCaColumn bool
entitledForJas bool
vcsProvider vcsutils.VcsProvider
}

func (mo *MarkdownOutput) SetVcsProvider(provider vcsutils.VcsProvider) {
Expand Down
11 changes: 11 additions & 0 deletions utils/outputwriter/simplifiedoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,14 @@ func (smo *SimplifiedOutput) MarkAsDetails(summary string, subTitleDepth int, co
func (smo *SimplifiedOutput) MarkAsTitle(title string, subTitleDepth int) string {
return fmt.Sprintf("%s\n%s %s\n%s", SectionDivider(), strings.Repeat("#", subTitleDepth), title, SectionDivider())
}

func (smo *SimplifiedOutput) SetPullRequestCommentTitle(pullRequestCommentTitle string) {
smo.pullRequestCommentTitle = pullRequestCommentTitle
if smo.pullRequestCommentTitle != "" {
smo.pullRequestCommentTitle = "\n\n" + MarkAsBold(pullRequestCommentTitle)
}
}

func (smo *SimplifiedOutput) PullRequestCommentTitle() string {
return smo.pullRequestCommentTitle
}
11 changes: 11 additions & 0 deletions utils/outputwriter/standardoutput.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ func (so *StandardOutput) MarkAsCollapsible(title, content string) string {
return fmt.Sprintf("<details>\n<summary>%s</summary>\n%s\n</details>", title, content)
}

func (so *StandardOutput) SetPullRequestCommentTitle(pullRequestCommentTitle string) {
so.pullRequestCommentTitle = pullRequestCommentTitle
if so.pullRequestCommentTitle != "" {
so.pullRequestCommentTitle = "\n" + so.MarkAsTitle(so.pullRequestCommentTitle, 2)
}
}

func (so *StandardOutput) PullRequestCommentTitle() string {
return so.pullRequestCommentTitle
}

func GetMarkdownCenterTag(content string) string {
return fmt.Sprintf("<div align='center'>\n\n%s\n\n</div>\n", content)
}
Loading

0 comments on commit 5d0e9da

Please sign in to comment.