outputwriter

package
v2.20.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FrogbotTitlePrefix      = "[🐸 Frogbot]"
	FrogbotRepoUrl          = "https://github.com/jfrog/frogbot"
	FrogbotDocumentationUrl = "https://docs.jfrog-applications.jfrog.io/jfrog-applications/frogbot"
	ReviewCommentId         = "FrogbotReviewComment"
)
View Source
const (
	SecretsEmailCSS = `` /* 876-byte string literal not displayed */

	//#nosec G101 -- full secrets would not be hard coded
	SecretsEmailHTMLTemplate = `` /* 873-byte string literal not displayed */

	//#nosec G101 -- full secrets would not be hard coded
	SecretsEmailTableRow = `
				<tr>
					<td> %s </td>
					<td> %d:%d </td>
					<td> %s </td>
				</tr>`
)

Variables

View Source
var (
	// Used for tests that are outside the outputwriter package.
	TestMessagesDir       = filepath.Join("..", "testdata", "messages")
	TestSummaryCommentDir = filepath.Join(TestMessagesDir, "summarycomment")
)
View Source
var (
	CommentGeneratedByFrogbot = MarkAsLink("🐸 JFrog Frogbot", FrogbotDocumentationUrl)
)

Functions

func ApplicableCveReviewContent

func ApplicableCveReviewContent(severity, finding, fullDetails, cve, cveDetails, impactedDependency, remediation string, writer OutputWriter) string

func ConvertContentToComments added in v2.20.0

func ConvertContentToComments(content []string, writer OutputWriter, commentDecorators ...CommentDecorator) (comments []string)

ConvertContentToComments converts the given content to comments, and returns the comments as a list of strings. The content is split into comments based on the size limit of the output writer. The commentDecorators are applied to each comment.

func GenerateReviewCommentContent

func GenerateReviewCommentContent(content string, writer OutputWriter) string

For review comment Frogbot creates on Scan PR

func GetApplicabilityDescriptionTable

func GetApplicabilityDescriptionTable(severity, cve, impactedDependency, finding string, writer OutputWriter) string

func GetBanner

func GetBanner(banner ImageSource) string

func GetExpectedTestCaseOutput added in v2.20.0

func GetExpectedTestCaseOutput(t *testing.T, testCase OutputTestCase) []string

func GetExpectedTestOutput

func GetExpectedTestOutput(t *testing.T, testCase OutputTestCase) string

func GetFallbackReviewCommentContent

func GetFallbackReviewCommentContent(content string, location formats.Location, writer OutputWriter) string

When can't create review comment, create a fallback comment by adding the location description to the content as a prefix

func GetIconTag

func GetIconTag(imageSource ImageSource) string

func GetJsonBodyOutputFromFile

func GetJsonBodyOutputFromFile(t *testing.T, filePath string) []byte

func GetMarkdownCenterTag

func GetMarkdownCenterTag(content string) string

func GetMarkdownSizeLimit added in v2.20.0

func GetMarkdownSizeLimit(client vcsclient.VcsClient) int

func GetOutputFromFile

func GetOutputFromFile(t *testing.T, filePath string) string

func GetPRSummaryContent

func GetPRSummaryContent(contentForComments []string, issuesExists, isComment bool, writer OutputWriter) (comments []string)

func GetPRSummaryContentNoIssues

func GetPRSummaryContentNoIssues(t *testing.T, summaryTestDir string, entitled, simplified bool) string

func GetSimplifiedTitle

func GetSimplifiedTitle(is ImageSource) string

func IacReviewContent

func IacReviewContent(severity, finding, fullDetails string, writer OutputWriter) string

func IsFrogbotComment added in v2.20.0

func IsFrogbotComment(content string) bool

func IsFrogbotSummaryComment

func IsFrogbotSummaryComment(writer OutputWriter, content string) bool

TODO: remove this at the next release, it's not used anymore and replaced by adding ReviewCommentId comment to the content

func LicensesContent

func LicensesContent(licenses []formats.LicenseRow, writer OutputWriter) string

func MarkAsBold

func MarkAsBold(content string) string

func MarkAsCodeSnippet

func MarkAsCodeSnippet(snippet string) string
func MarkAsLink(content, link string) string

func MarkAsQuote

func MarkAsQuote(content string) string

func MarkdownComment

func MarkdownComment(text string) string

func SastReviewContent

func SastReviewContent(severity, finding, fullDetails string, codeFlows [][]formats.Location, writer OutputWriter) string

func SectionDivider

func SectionDivider() string

func VulnerabilitiesContent

func VulnerabilitiesContent(vulnerabilities []formats.VulnerabilityOrViolationRow, writer OutputWriter) (content []string)

func WriteContent

func WriteContent(builder *strings.Builder, contents ...string)

func WriteNewLine

func WriteNewLine(builder *strings.Builder)

Types

type CellData

type CellData []string

CellData represents the data of a cell in the markdown table. Each cell can contain multiple values.

func NewCellData

func NewCellData(values ...string) CellData

type CommentDecorator added in v2.20.0

type CommentDecorator func(int, string) string

func GetFrogbotCommentBaseDecorator added in v2.20.0

func GetFrogbotCommentBaseDecorator(writer OutputWriter) CommentDecorator

Adding markdown prefix to identify Frogbot comment and a footer with the link to the documentation

func GetPRSummaryMainCommentDecorator added in v2.20.0

func GetPRSummaryMainCommentDecorator(issuesExists, isComment bool, writer OutputWriter) CommentDecorator

Adding a banner, custom title and untitled Jas message to the content

type IconName

type IconName string

type ImageSource

type ImageSource string
const (
	NoVulnerabilityPrBannerSource    ImageSource = "v2/noVulnerabilityBannerPR.png"
	NoVulnerabilityMrBannerSource    ImageSource = "v2/noVulnerabilityBannerMR.png"
	VulnerabilitiesPrBannerSource    ImageSource = "v2/vulnerabilitiesBannerPR.png"
	VulnerabilitiesMrBannerSource    ImageSource = "v2/vulnerabilitiesBannerMR.png"
	VulnerabilitiesFixPrBannerSource ImageSource = "v2/vulnerabilitiesFixBannerPR.png"
	VulnerabilitiesFixMrBannerSource ImageSource = "v2/vulnerabilitiesFixBannerMR.png"
)

func NoIssuesTitleSrc

func NoIssuesTitleSrc(vcsProvider vcsutils.VcsProvider) ImageSource

func PRSummaryCommentTitleSrc

func PRSummaryCommentTitleSrc(vcsProvider vcsutils.VcsProvider) ImageSource

type MarkdownColumn

type MarkdownColumn struct {
	Name         string
	ColumnType   MarkdownColumnType
	DefaultValue string
}

type MarkdownColumnType

type MarkdownColumnType string
const (

	// (Default value for columns) If more than one value exists in a cell, the values will be separated by the delimiter.
	SeparatorDelimited MarkdownColumnType = "single"
	// If more than one value exists in a cell, for each value a new row will be created.
	// The first row will contain the other columns values, and the rest of the rows will contain the values of the multi value column only.
	// Only works if exists up to one MultiRowColumn in the table.
	MultiRowColumn MarkdownColumnType = "multi"
)

type MarkdownOutput

type MarkdownOutput struct {
	// contains filtered or unexported fields
}

func (*MarkdownOutput) AvoidExtraMessages

func (mo *MarkdownOutput) AvoidExtraMessages() bool

func (*MarkdownOutput) HasInternetConnection

func (mo *MarkdownOutput) HasInternetConnection() bool

func (*MarkdownOutput) IsEntitledForJas

func (mo *MarkdownOutput) IsEntitledForJas() bool

func (*MarkdownOutput) IsShowingCaColumn

func (mo *MarkdownOutput) IsShowingCaColumn() bool

func (*MarkdownOutput) PullRequestCommentTitle

func (mo *MarkdownOutput) PullRequestCommentTitle() string

func (*MarkdownOutput) SetAvoidExtraMessages

func (mo *MarkdownOutput) SetAvoidExtraMessages(avoidExtraMessages bool)

func (*MarkdownOutput) SetHasInternetConnection

func (mo *MarkdownOutput) SetHasInternetConnection(connected bool)

func (*MarkdownOutput) SetJasOutputFlags

func (mo *MarkdownOutput) SetJasOutputFlags(entitled, showCaColumn bool)

func (*MarkdownOutput) SetPullRequestCommentTitle

func (mo *MarkdownOutput) SetPullRequestCommentTitle(pullRequestCommentTitle string)

func (*MarkdownOutput) SetSizeLimit added in v2.20.0

func (mo *MarkdownOutput) SetSizeLimit(client vcsclient.VcsClient)

func (*MarkdownOutput) SetVcsProvider

func (mo *MarkdownOutput) SetVcsProvider(provider vcsutils.VcsProvider)

func (*MarkdownOutput) SizeLimit added in v2.20.0

func (mo *MarkdownOutput) SizeLimit(comment bool) int

func (*MarkdownOutput) VcsProvider

func (mo *MarkdownOutput) VcsProvider() vcsutils.VcsProvider

type MarkdownTableBuilder

type MarkdownTableBuilder struct {
	// contains filtered or unexported fields
}

Create a markdown table using the provided columns and rows, and construct a markdown string with the table's content. Each cell in the table can contain no values (represented as column default value), single or multiple values (separated by the table delimiter).

func NewMarkdownTable

func NewMarkdownTable(columns ...string) *MarkdownTableBuilder

Create a markdown table builder with the provided columns.

func (*MarkdownTableBuilder) AddRow

func (t *MarkdownTableBuilder) AddRow(values ...string) *MarkdownTableBuilder

Add a row to the markdown table, each value will be added to the corresponding column. Use to add row with single value columns only.

func (*MarkdownTableBuilder) AddRowWithCellData

func (t *MarkdownTableBuilder) AddRowWithCellData(values ...CellData) *MarkdownTableBuilder

Add a row to the markdown table, each value will be added to the corresponding column. Use to add row with multiple value columns.

func (*MarkdownTableBuilder) Build

func (t *MarkdownTableBuilder) Build() string

func (*MarkdownTableBuilder) GetColumnInfo

func (t *MarkdownTableBuilder) GetColumnInfo(name string) *MarkdownColumn

Get the column information output controller by the provided name.

func (*MarkdownTableBuilder) SetDelimiter

func (t *MarkdownTableBuilder) SetDelimiter(delimiter string) *MarkdownTableBuilder

Set the delimiter that will be used to separate multiple values in a cell.

type OutputTestCase

type OutputTestCase struct {
	// contains filtered or unexported fields
}

type OutputWriter

type OutputWriter interface {
	// Options
	SetJasOutputFlags(entitled, showCaColumn bool)
	IsShowingCaColumn() bool
	IsEntitledForJas() bool
	SetAvoidExtraMessages(avoidExtraMessages bool)
	AvoidExtraMessages() bool
	SetPullRequestCommentTitle(pullRequestCommentTitle string)
	PullRequestCommentTitle() string
	SetHasInternetConnection(connected bool)
	HasInternetConnection() bool
	SizeLimit(comment bool) int
	SetSizeLimit(client vcsclient.VcsClient)
	// VCS info
	VcsProvider() vcsutils.VcsProvider
	SetVcsProvider(provider vcsutils.VcsProvider)
	// Markdown interface
	FormattedSeverity(severity, applicability string) string
	Separator() string
	MarkInCenter(content string) string
	MarkAsDetails(summary string, subTitleDepth int, content string) string
	MarkAsTitle(title string, subTitleDepth int) string
	Image(source ImageSource) string
}

The OutputWriter interface allows Frogbot output to be written in an appropriate way for each git provider. Some git providers support markdown only partially, whereas others support it fully.

func GetCompatibleOutputWriter

func GetCompatibleOutputWriter(provider vcsutils.VcsProvider) OutputWriter

type SimplifiedOutput

type SimplifiedOutput struct {
	MarkdownOutput
}

func (*SimplifiedOutput) FormattedSeverity

func (smo *SimplifiedOutput) FormattedSeverity(severity, _ string) string

func (*SimplifiedOutput) Image

func (smo *SimplifiedOutput) Image(source ImageSource) string

func (*SimplifiedOutput) MarkAsDetails

func (smo *SimplifiedOutput) MarkAsDetails(summary string, subTitleDepth int, content string) string

func (*SimplifiedOutput) MarkAsTitle

func (smo *SimplifiedOutput) MarkAsTitle(title string, subTitleDepth int) string

func (*SimplifiedOutput) MarkInCenter

func (smo *SimplifiedOutput) MarkInCenter(content string) string

func (*SimplifiedOutput) Separator

func (smo *SimplifiedOutput) Separator() string

type StandardOutput

type StandardOutput struct {
	MarkdownOutput
}

func (*StandardOutput) FormattedSeverity

func (so *StandardOutput) FormattedSeverity(severity, applicability string) string

func (*StandardOutput) Image

func (so *StandardOutput) Image(source ImageSource) string

func (*StandardOutput) MarkAsDetails

func (so *StandardOutput) MarkAsDetails(summary string, subTitleDepth int, content string) string

func (*StandardOutput) MarkAsTitle

func (so *StandardOutput) MarkAsTitle(title string, subTitleDepth int) string

func (*StandardOutput) MarkInCenter

func (so *StandardOutput) MarkInCenter(content string) string

func (*StandardOutput) Separator

func (so *StandardOutput) Separator() string

type TestBodyResponse

type TestBodyResponse struct {
	Body string `json:"body"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL