MCPcopy Create free account
hub / github.com/bufbuild/buf / printFileAnnotationAsGithubActions

Function printFileAnnotationAsGithubActions

private/bufpkg/bufanalysis/print.go:240–294  ·  view source on GitHub ↗
(buffer *bytes.Buffer, f FileAnnotation)

Source from the content-addressed store, hash-verified

238}
239
240func printFileAnnotationAsGithubActions(buffer *bytes.Buffer, f FileAnnotation) error {
241 if f == nil {
242 return nil
243 }
244 _, _ = buffer.WriteString("::error ")
245
246 // file= is required for GitHub Actions, however it is possible to not have
247 // a path for a FileAnnotation. We still print something, however we need
248 // to test what happens in GitHub Actions if no valid path is printed out.
249 path := "<input>"
250 if f.FileInfo() != nil {
251 path = f.FileInfo().ExternalPath()
252 }
253 _, _ = buffer.WriteString("file=")
254 _, _ = buffer.WriteString(path)
255
256 // Everything else is optional.
257 if startLine := f.StartLine(); startLine > 0 {
258 _, _ = buffer.WriteString(",line=")
259 _, _ = buffer.WriteString(strconv.Itoa(startLine))
260 // We only print column information if we have line information.
261 if startColumn := f.StartColumn(); startColumn > 0 {
262 _, _ = buffer.WriteString(",col=")
263 _, _ = buffer.WriteString(strconv.Itoa(startColumn))
264 }
265 // We only do any ending line information if we have starting line information
266 if endLine := f.EndLine(); endLine > 0 {
267 _, _ = buffer.WriteString(",endLine=")
268 _, _ = buffer.WriteString(strconv.Itoa(endLine))
269 // We only print column information if we have line information.
270 if endColumn := f.EndColumn(); endColumn > 0 {
271 // Yes, the spec has "col" for start and "endColumn" for end.
272 _, _ = buffer.WriteString(",endColumn=")
273 _, _ = buffer.WriteString(strconv.Itoa(endColumn))
274 }
275 }
276 }
277
278 _, _ = buffer.WriteString("::")
279 _, _ = buffer.WriteString(f.Message())
280 if pluginName, policyName := f.PluginName(), f.PolicyName(); pluginName != "" || policyName != "" {
281 _, _ = buffer.WriteString(" (")
282 if pluginName != "" {
283 _, _ = buffer.WriteString(pluginName)
284 }
285 if pluginName != "" && policyName != "" {
286 _, _ = buffer.WriteString(", ")
287 }
288 if policyName != "" {
289 _, _ = buffer.WriteString(policyName)
290 }
291 _, _ = buffer.WriteRune(')')
292 }
293 return nil
294}
295
296type externalFileAnnotation struct {
297 Path string `json:"path,omitempty" yaml:"path,omitempty"`

Callers

nothing calls this directly

Calls 9

FileInfoMethod · 0.65
ExternalPathMethod · 0.65
StartLineMethod · 0.65
StartColumnMethod · 0.65
EndLineMethod · 0.65
EndColumnMethod · 0.65
MessageMethod · 0.65
PluginNameMethod · 0.65
PolicyNameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…