github.com/abayer/test-infra@v0.0.5/prow/plugins/respond.go (about) 1 /* 2 Copyright 2016 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package plugins 18 19 import ( 20 "fmt" 21 "strings" 22 23 "k8s.io/test-infra/prow/github" 24 ) 25 26 const AboutThisBotWithoutCommands = "Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository." 27 const AboutThisBotCommands = "I understand the commands that are listed [here](https://go.k8s.io/bot-commands)." 28 const AboutThisBot = AboutThisBotWithoutCommands + " " + AboutThisBotCommands 29 30 // FormatResponse nicely formats a response to a generic reason. 31 func FormatResponse(to, message, reason string) string { 32 format := `@%s: %s 33 34 <details> 35 36 %s 37 38 %s 39 </details>` 40 41 return fmt.Sprintf(format, to, message, reason, AboutThisBotWithoutCommands) 42 } 43 44 // FormatSimpleResponse formats a response that does not warrant additional explanation in the 45 // details section. 46 func FormatSimpleResponse(to, message string) string { 47 format := `@%s: %s 48 49 <details> 50 51 %s 52 </details>` 53 54 return fmt.Sprintf(format, to, message, AboutThisBotWithoutCommands) 55 } 56 57 // FormatICResponse nicely formats a response to an issue comment. 58 func FormatICResponse(ic github.IssueComment, s string) string { 59 return FormatResponseRaw(ic.Body, ic.HTMLURL, ic.User.Login, s) 60 } 61 62 // FormatResponseRaw nicely formats a response for one does not have an issue comment 63 func FormatResponseRaw(body, bodyURL, login, reply string) string { 64 format := `In response to [this](%s): 65 66 %s 67 ` 68 // Quote the user's comment by prepending ">" to each line. 69 var quoted []string 70 for _, l := range strings.Split(body, "\n") { 71 quoted = append(quoted, ">"+l) 72 } 73 return FormatResponse(login, reply, fmt.Sprintf(format, bodyURL, strings.Join(quoted, "\n"))) 74 }