Skip to content

Commit

Permalink
Minor changes (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
yahavi authored Mar 31, 2022
1 parent 188ecd5 commit cdaf4a0
Show file tree
Hide file tree
Showing 17 changed files with 55 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/frogbot.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Frogbot"
on:
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot" label if needed.
# After "🐸 frogbot" label was added to a pull request, Frogbot scans the pull request.
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot scan pr" label if needed.
# After "🐸 frogbot scan pr" label was added to a pull request, Frogbot scans the pull request.
pull_request_target:
types: [labeled, opened]
jobs:
Expand Down
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ Frogbot is a Git bot that scans your pull requests with JFrog Xray for security

After a new pull request is created, one of the maintainers can add the "Frogbot scan" label to the pull request. Frogbot will then be triggered and the pull request will be scanned. The scan output will include only new vulnerabilities added by the pull request. Vulnerabilities that existed in the code prior to the pull request created will not be added to the report.

After the pull request scanning completed, Frogbot will automatically add a comment to the pull request.
If no vulnerabilities were added in the pull request:
[![No Vuln](./resources/noVulnerabilityBanner.png)](#-how-does-it-work)

If one or more vulnerabilities were added in the pull request:
[![Vuln found](./resources/vulnExample.png)](#-how-does-it-work)

## 🖥️ Usage

- [Using Frogbot with GitHub Actions](#using-frogbot-with-github-actions)
Expand All @@ -22,13 +29,20 @@ After a new pull request is created, one of the maintainers can add the "Frogbot

For a super quick start, we created [GitHub Actions templates](templates/github-actions/README.md#github-actions-templates) under [templates/github-action](templates/github-actions/).

#### How does it work?

1. User opens a pull request
1. If missing, Frogbot creates a label `🐸 frogbot scan pr` in the repository
1. Maintainer reviewes the pull request and assigns `🐸 frogbot scan pr`
1. Frogbot gets triggered by the label, unlabels it, and executes the pull request scanning

Here's a recommanded structure of a `frogbot.yml` workflow file:

```yml
name: "Frogbot"
on:
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot" label if needed.
# After "🐸 frogbot" label was added to a pull request, Frogbot scans the pull request.
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot scan pr" label if needed.
# After "🐸 frogbot scan pr" label was added to a pull request, Frogbot scans the pull request.
pull_request_target:
types: [opened, labeled]
jobs:
Expand Down
10 changes: 4 additions & 6 deletions commands/scanpullrequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ func GetScanPullRequestFlags() []clitool.Flag {
return []clitool.Flag{
&clitool.BoolFlag{
Name: "use-labels",
Usage: "Set to true if scan-pull-request is triggered by adding '🐸 frogbot' label to a pull request.",
Usage: "Set to true if scan-pull-request is triggered by adding '🐸 frogbot scan pr' label to a pull request.",
EnvVars: []string{"JF_USE_LABELS"},
},
}
}

// Run before scan, to make sure the Xray scan will be run only after adding the frogbot label.
// Run before scan, to make sure the Xray scan will be run only after adding the 'frogbot scan pr' label.
// If label is missing - create the label and do nothing
// If pr isn't labeled - do nothing
// If pr is labeled - remove label and allow running Xray scan (return nil)
Expand Down Expand Up @@ -237,10 +237,8 @@ func getUniqueID(vulnerability xrayutils.VulnerabilityRow) string {

func createPullRequestMessage(vulnerabilitiesRows []xrayutils.VulnerabilityRow) string {
if len(vulnerabilitiesRows) == 0 {
return utils.GetNoVulnerabilitiesBanner()
return utils.GetBanner(utils.NoVulnerabilityBannerSource) + utils.WhatIsFrogbotMd
}
tableHeder := "\n| SEVERITY | IMPACTED PACKAGE | IMPACTED PACKAGE VERSION | FIXED VERSIONS | COMPONENT | COMPONENT VERSION | CVE\n" +
":--: | -- | -- | -- | -- | :--: | --"
var tableContent string
for _, vulnerability := range vulnerabilitiesRows {
var componentName, componentVersion, cve string
Expand All @@ -254,5 +252,5 @@ func createPullRequestMessage(vulnerabilitiesRows []xrayutils.VulnerabilityRow)
tableContent += fmt.Sprintf("\n| %s | %s | %s | %s | %s | %s | %s ", utils.GetSeverityTag(vulnerability.Severity)+" "+vulnerability.Severity, vulnerability.ImpactedPackageName,
vulnerability.ImpactedPackageVersion, vulnerability.FixedVersions, componentName, componentVersion, cve)
}
return utils.GetVulnerabilitiesBanner() + tableHeder + tableContent
return utils.GetBanner(utils.VulnerabilitiesBannerSource) + utils.WhatIsFrogbotMd + utils.TableHeder + tableContent
}
6 changes: 4 additions & 2 deletions commands/testdata/messages/dummyvulnerabilities.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/vulnerabilitiesBanner.png)
| SEVERITY | IMPACTED PACKAGE | IMPACTED PACKAGE VERSION | FIXED VERSIONS | COMPONENT | COMPONENT VERSION | CVE
[![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/vulnerabilitiesBanner.png)](https://github.com/jfrog/frogbot#frogbot)

[What is Frogbot?](https://github.com/jfrog/frogbot#frogbot)
| SEVERITY | IMPACTED PACKAGE | VERSION | FIXED VERSIONS | COMPONENT | COMPONENT VERSION | CVE
:--: | -- | -- | -- | -- | :--: | --
| ![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/highSeverity.png) High | github.com/nats-io/nats-streaming-server | v0.21.0 | [0.24.1] | github.com/nats-io/nats-streaming-server | v0.21.0 | CVE-2022-24450
| ![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/highSeverity.png) High | github.com/mholt/archiver/v3 | v3.5.1 | | github.com/mholt/archiver/v3 | v3.5.1 |
Expand Down
4 changes: 3 additions & 1 deletion commands/testdata/messages/novulnerabilities.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/noVulnerabilityBanner.png)
[![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/noVulnerabilityBanner.png)](https://github.com/jfrog/frogbot#frogbot)

[What is Frogbot?](https://github.com/jfrog/frogbot#frogbot)
7 changes: 6 additions & 1 deletion commands/utils/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const (
gitLab vcsProvider = "gitlab"

// Frogbot label
LabelName frogbotLabel = "🐸 frogbot"
LabelName frogbotLabel = "🐸 frogbot scan pr"
LabelDescription frogbotLabel = "triggers frogbot scan"
LabelColor frogbotLabel = "4AB548"

Expand All @@ -45,4 +45,9 @@ const (
gitBaseBranchEnv = "JF_GIT_BASE_BRANCH"
gitPullRequestIDEnv = "JF_GIT_PULL_REQUEST_ID"
WatchesDelimiter = ","

// Comment
TableHeder = "\n| SEVERITY | IMPACTED PACKAGE | VERSION | FIXED VERSIONS | COMPONENT | COMPONENT VERSION | CVE\n" +
":--: | -- | -- | -- | -- | :--: | --"
WhatIsFrogbotMd = "\n\n[What is Frogbot?](https://github.com/jfrog/frogbot#frogbot)"
)
8 changes: 2 additions & 6 deletions commands/utils/icons.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,8 @@ func GetSeverityTag(iconName string) string {
return ""
}

func GetNoVulnerabilitiesBanner() string {
return getIconTag(NoVulnerabilityBannerSource)
}

func GetVulnerabilitiesBanner() string {
return getIconTag(VulnerabilitiesBannerSource)
func GetBanner(banner imageSource) string {
return "[" + getIconTag(banner) + "](https://github.com/jfrog/frogbot#frogbot)"
}

func getIconTag(imageSource imageSource) string {
Expand Down
4 changes: 2 additions & 2 deletions commands/utils/icons_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ func TestGetSeverityTag(t *testing.T) {
}

func TestGetVulnerabilitiesBanners(t *testing.T) {
assert.Equal(t, "![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/noVulnerabilityBanner.png)", GetNoVulnerabilitiesBanner())
assert.Equal(t, "![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/vulnerabilitiesBanner.png)", GetVulnerabilitiesBanner())
assert.Equal(t, "[![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/noVulnerabilityBanner.png)](https://github.com/jfrog/frogbot#frogbot)", GetBanner(NoVulnerabilityBannerSource))
assert.Equal(t, "[![](https://raw.githubusercontent.com/jfrog/frogbot/master/resources/vulnerabilitiesBanner.png)](https://github.com/jfrog/frogbot#frogbot)", GetBanner(VulnerabilitiesBannerSource))
}
Binary file added resources/vulnExample.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions templates/github-actions/frogbot-dotnet.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Frogbot"
on:
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot" label if needed.
# After "🐸 frogbot" label was added to a pull request, Frogbot scans the pull request.
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot scan pr" label if needed.
# After "🐸 frogbot scan pr" label was added to a pull request, Frogbot scans the pull request.
pull_request_target:
types: [labeled, opened]
jobs:
Expand Down
4 changes: 2 additions & 2 deletions templates/github-actions/frogbot-go.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Frogbot"
on:
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot" label if needed.
# After "🐸 frogbot" label was added to a pull request, Frogbot scans the pull request.
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot scan pr" label if needed.
# After "🐸 frogbot scan pr" label was added to a pull request, Frogbot scans the pull request.
pull_request_target:
types: [labeled, opened]
jobs:
Expand Down
4 changes: 2 additions & 2 deletions templates/github-actions/frogbot-gradle.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Frogbot"
on:
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot" label if needed.
# After "🐸 frogbot" label was added to a pull request, Frogbot scans the pull request.
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot scan pr" label if needed.
# After "🐸 frogbot scan pr" label was added to a pull request, Frogbot scans the pull request.
pull_request_target:
types: [labeled, opened]
jobs:
Expand Down
4 changes: 2 additions & 2 deletions templates/github-actions/frogbot-maven.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Frogbot"
on:
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot" label if needed.
# After "🐸 frogbot" label was added to a pull request, Frogbot scans the pull request.
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot scan pr" label if needed.
# After "🐸 frogbot scan pr" label was added to a pull request, Frogbot scans the pull request.
pull_request_target:
types: [labeled, opened]
jobs:
Expand Down
4 changes: 2 additions & 2 deletions templates/github-actions/frogbot-npm.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Frogbot"
on:
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot" label if needed.
# After "🐸 frogbot" label was added to a pull request, Frogbot scans the pull request.
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot scan pr" label if needed.
# After "🐸 frogbot scan pr" label was added to a pull request, Frogbot scans the pull request.
pull_request_target:
types: [labeled, opened]
jobs:
Expand Down
4 changes: 2 additions & 2 deletions templates/github-actions/frogbot-nuget.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Frogbot"
on:
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot" label if needed.
# After "🐸 frogbot" label was added to a pull request, Frogbot scans the pull request.
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot scan pr" label if needed.
# After "🐸 frogbot scan pr" label was added to a pull request, Frogbot scans the pull request.
pull_request_target:
types: [labeled, opened]
jobs:
Expand Down
4 changes: 2 additions & 2 deletions templates/github-actions/frogbot-pip.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Frogbot"
on:
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot" label if needed.
# After "🐸 frogbot" label was added to a pull request, Frogbot scans the pull request.
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot scan pr" label if needed.
# After "🐸 frogbot scan pr" label was added to a pull request, Frogbot scans the pull request.
pull_request_target:
types: [labeled, opened]
jobs:
Expand Down
4 changes: 2 additions & 2 deletions templates/github-actions/frogbot-pipenv.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: "Frogbot"
on:
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot" label if needed.
# After "🐸 frogbot" label was added to a pull request, Frogbot scans the pull request.
# After a pull request opened, Frogbot automatically creates the "🐸 frogbot scan pr" label if needed.
# After "🐸 frogbot scan pr" label was added to a pull request, Frogbot scans the pull request.
pull_request_target:
types: [labeled, opened]
jobs:
Expand Down

0 comments on commit cdaf4a0

Please sign in to comment.