formatErrorForGitHub formats an error for GitHub annotations.
(err error)
| 181 | |
| 182 | // formatErrorForGitHub formats an error for GitHub annotations. |
| 183 | func formatErrorForGitHub(err error) string { |
| 184 | switch e := err.(type) { |
| 185 | case *checkErr: |
| 186 | // GitHub expects the path to be relative to the repository root. |
| 187 | relativePath, _ := filepath.Rel(".", e.Path) |
| 188 | // Escape the message to prevent command injection. |
| 189 | message := strings.ReplaceAll(e.Reason, "\"", "\\\"") |
| 190 | return fmt.Sprintf("::error file=%s::%s", relativePath, message) |
| 191 | default: |
| 192 | return err.Error() |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | // Check checks that all files contain the required file header. |
| 197 | func (h Headers) Check() error { |