github.com/jfrog/frogbot/v2@v2.21.0/utils/outputwriter/icons.go (about) 1 package outputwriter 2 3 import ( 4 "fmt" 5 "strings" 6 ) 7 8 type ImageSource string 9 type IconName string 10 11 const ( 12 baseResourceUrl = "https://raw.githubusercontent.com/jfrog/frogbot/master/resources/" 13 14 NoVulnerabilityPrBannerSource ImageSource = "v2/noVulnerabilityBannerPR.png" 15 NoVulnerabilityMrBannerSource ImageSource = "v2/noVulnerabilityBannerMR.png" 16 VulnerabilitiesPrBannerSource ImageSource = "v2/vulnerabilitiesBannerPR.png" 17 VulnerabilitiesMrBannerSource ImageSource = "v2/vulnerabilitiesBannerMR.png" 18 VulnerabilitiesFixPrBannerSource ImageSource = "v2/vulnerabilitiesFixBannerPR.png" 19 VulnerabilitiesFixMrBannerSource ImageSource = "v2/vulnerabilitiesFixBannerMR.png" 20 criticalSeveritySource ImageSource = "v2/applicableCriticalSeverity.png" 21 notApplicableCriticalSeveritySource ImageSource = "v2/notApplicableCritical.png" 22 highSeveritySource ImageSource = "v2/applicableHighSeverity.png" 23 notApplicableHighSeveritySource ImageSource = "v2/notApplicableHigh.png" 24 mediumSeveritySource ImageSource = "v2/applicableMediumSeverity.png" 25 notApplicableMediumSeveritySource ImageSource = "v2/notApplicableMedium.png" 26 lowSeveritySource ImageSource = "v2/applicableLowSeverity.png" 27 notApplicableLowSeveritySource ImageSource = "v2/notApplicableLow.png" 28 unknownSeveritySource ImageSource = "v2/applicableUnknownSeverity.png" 29 notApplicableUnknownSeveritySource ImageSource = "v2/notApplicableUnknown.png" 30 ) 31 32 func getSeverityTag(iconName IconName, applicability string) string { 33 if applicability == "Not Applicable" { 34 return getNotApplicableIconTags(iconName) 35 } 36 return getApplicableIconTags(iconName) 37 } 38 39 func getNotApplicableIconTags(iconName IconName) string { 40 switch strings.ToLower(string(iconName)) { 41 case "critical": 42 return GetIconTag(notApplicableCriticalSeveritySource) + "<br>" 43 case "high": 44 return GetIconTag(notApplicableHighSeveritySource) + "<br>" 45 case "medium": 46 return GetIconTag(notApplicableMediumSeveritySource) + "<br>" 47 case "low": 48 return GetIconTag(notApplicableLowSeveritySource) + "<br>" 49 } 50 return GetIconTag(notApplicableUnknownSeveritySource) + "<br>" 51 } 52 53 func getApplicableIconTags(iconName IconName) string { 54 switch strings.ToLower(string(iconName)) { 55 case "critical": 56 return GetIconTag(criticalSeveritySource) + "<br>" 57 case "high": 58 return GetIconTag(highSeveritySource) + "<br>" 59 case "medium": 60 return GetIconTag(mediumSeveritySource) + "<br>" 61 case "low": 62 return GetIconTag(lowSeveritySource) + "<br>" 63 } 64 return GetIconTag(unknownSeveritySource) + "<br>" 65 } 66 67 func GetBanner(banner ImageSource) string { 68 return GetMarkdownCenterTag(MarkAsLink(GetIconTag(banner), FrogbotDocumentationUrl)) 69 } 70 71 func GetIconTag(imageSource ImageSource) string { 72 return fmt.Sprintf("!%s", MarkAsLink(GetSimplifiedTitle(imageSource), fmt.Sprintf("%s%s", baseResourceUrl, imageSource))) 73 } 74 75 func GetSimplifiedTitle(is ImageSource) string { 76 switch is { 77 case NoVulnerabilityPrBannerSource: 78 return "👍 Frogbot scanned this pull request and did not find any new security issues." 79 case VulnerabilitiesPrBannerSource: 80 return "🚨 Frogbot scanned this pull request and found the below:" 81 case VulnerabilitiesFixPrBannerSource: 82 return "🚨 This automated pull request was created by Frogbot and fixes the below:" 83 case NoVulnerabilityMrBannerSource: 84 return "👍 Frogbot scanned this merge request and did not find any new security issues." 85 case VulnerabilitiesMrBannerSource: 86 return "🚨 Frogbot scanned this merge request and found the below:" 87 case VulnerabilitiesFixMrBannerSource: 88 return "🚨 This automated merge request was created by Frogbot and fixes the below:" 89 default: 90 return "" 91 } 92 }