1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package workflow
import (
"net/url"
"strconv"
"strings"
"github.com/johnandersen777/socialweb-computer-kcp/internal/policyengine/models"
)
func parseGitHubActionsOutputs(content string) map[string]string {
outputs := make(map[string]string)
currentKey := ""
currentDelimiter := ""
currentValue := strings.Builder{}
for line := range strings.SplitSeq(content, "\n") {
if currentDelimiter != "" {
if strings.HasPrefix(line, currentDelimiter) {
outputs[currentKey] = strings.TrimSuffix(currentValue.String(), "\n")
currentKey = ""
currentDelimiter = ""
currentValue.Reset()
} else {
currentValue.WriteString(line + "\n")
}
continue
}
if currentKey == "" && strings.Contains(line, "<<") {
parts := strings.SplitN(line, "<<", 2)
currentKey = strings.TrimSpace(parts[0])
currentDelimiter = strings.TrimSpace(parts[1])
continue
}
if currentKey == "" && strings.Contains(line, "=") {
parts := strings.SplitN(line, "=", 2)
key := strings.TrimSpace(parts[0])
value := ""
if len(parts) > 1 {
value = parts[1]
}
outputs[key] = value
}
}
return outputs
}
func (e *Executor) parseAnnotations(output string) {
for line := range strings.SplitSeq(output, "\n") {
if !strings.HasPrefix(line, "::") {
continue
}
line = strings.TrimPrefix(line, "::")
parts := strings.SplitN(line, "::", 2)
levelAndParams := parts[0]
message := ""
if len(parts) > 1 {
message = parts[1]
}
levelParts := strings.SplitN(levelAndParams, " ", 2)
level := levelParts[0]
if level != "error" && level != "warning" && level != "notice" {
continue
}
annotation := models.Annotation{
AnnotationLevel: models.AnnotationLevel(level),
Message: message,
Title: message,
RawDetails: line,
}
if len(levelParts) > 1 {
params, _ := url.ParseQuery(strings.ReplaceAll(levelParts[1], ",", "&"))
if file := params.Get("file"); file != "" {
annotation.Path = file
}
if path := params.Get("path"); path != "" {
annotation.Path = path
}
if title := params.Get("title"); title != "" {
annotation.Title = title
}
if lineValue := params.Get("line"); lineValue != "" {
if number, err := strconv.Atoi(lineValue); err == nil {
annotation.StartLine = number
annotation.EndLine = number
}
}
if endLine := params.Get("endLine"); endLine != "" {
if number, err := strconv.Atoi(endLine); err == nil {
annotation.EndLine = number
}
}
}
e.Context.Annotations[level] = append(e.Context.Annotations[level], annotation)
}
}