code-intelligence.com/cifuzz@v0.40.0/pkg/messaging/messaging.go (about) 1 package messaging 2 3 import ( 4 "net/url" 5 "os" 6 7 "code-intelligence.com/cifuzz/pkg/log" 8 ) 9 10 type MessagingContext string 11 12 const ( 13 Run MessagingContext = "Run" 14 Finding MessagingContext = "Finding" 15 ) 16 17 var messagesAndParams = map[MessagingContext][]struct { 18 message string 19 additionalParams url.Values 20 }{ 21 Run: { 22 { 23 message: `Do you want to persist your findings? 24 Authenticate with the CI App server to get more insights.`, 25 additionalParams: url.Values{ 26 "utm_source": []string{"cli"}, 27 "utm_campaign": []string{"run-message"}, 28 "utm_term": []string{"a"}}, 29 }, 30 { 31 message: `Code Intelligence provides you with a full history for all your findings 32 and allows you to postpone work on findings and completely ignore 33 them to keep the output clean and focused. 34 35 With a free authentication you receive detailed information and solution tips 36 for each finding in your console. 37 38 All your finding data stays only with us at Code Intelligence 39 and will never be shared.`, 40 additionalParams: url.Values{ 41 "utm_source": []string{"cli"}, 42 "utm_campaign": []string{"run-message"}, 43 "utm_term": []string{"b"}, 44 }, 45 }, 46 }, 47 Finding: { 48 { 49 message: `Authenticate with CI App to get more insights 50 on your findings and persist them for a full history.`, 51 additionalParams: url.Values{ 52 "utm_source": []string{"cli"}, 53 "utm_campaign": []string{"finding-message"}, 54 "utm_term": []string{"a"}}, 55 }, 56 { 57 message: `With a free authentication you receive detailed information such as severity 58 and solution tips for each finding in your console. 59 60 All your finding data stays only with us at Code Intelligence and will never be shared.`, 61 additionalParams: url.Values{ 62 "utm_source": []string{"cli"}, 63 "utm_campaign": []string{"finding-message"}, 64 "utm_term": []string{"b"}, 65 }, 66 }, 67 }, 68 } 69 70 func ShowServerConnectionMessage(server string, context MessagingContext) *url.Values { 71 messageAndParam, entryPresent := messagesAndParams[context] 72 73 if !entryPresent { 74 return &url.Values{} 75 } 76 77 messageIndex, err := pickNumberForMessagingIndex(len(messagesAndParams)) 78 if err != nil { 79 messageIndex = 0 80 } 81 82 log.Notef(messageAndParam[messageIndex].message) 83 return &messageAndParam[messageIndex].additionalParams 84 } 85 86 // To avoid that a user sees a different message each time 87 // we compute a stable "random" number 88 func pickNumberForMessagingIndex(numberOfMessages int) (int, error) { 89 // Path name for the executable 90 path, err := os.Executable() 91 92 if err != nil { 93 return 0, err 94 } 95 96 file, err := os.Stat(path) 97 if err != nil { 98 return 0, err 99 } 100 101 // We are using minute instead of hour 102 // to avoid a "bias" for people trying 103 // things out late in the evening 104 return file.ModTime().Minute() % numberOfMessages, nil 105 }