-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathautofix_config.go
48 lines (41 loc) · 1.15 KB
/
autofix_config.go
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
package orchestrator
import (
"bytes"
"encoding/base64"
"encoding/json"
"github.com/DataDog/zstd"
artifact "github.com/deepcode-ai/artifacts/types"
"github.com/pelletier/go-toml"
)
type AutofixConfig struct {
*artifact.MarvinAutofixConfig
}
func NewAutofixConfig(run *artifact.AutofixRun) (*AutofixConfig, error) {
jsonIssues, err := json.Marshal(run.Autofixer.Autofixes)
if err != nil {
return nil, err
}
return &AutofixConfig{
MarvinAutofixConfig: &artifact.MarvinAutofixConfig{
RunID: run.RunID,
AnalyzerShortcode: run.Autofixer.AutofixMeta.Shortcode,
AutofixerCommand: run.Autofixer.AutofixMeta.Command,
CheckoutOID: run.VCSMeta.CheckoutOID,
AutofixIssues: string(jsonIssues),
},
}, nil
}
func (c *AutofixConfig) Bytes() ([]byte, error) {
var buf bytes.Buffer
if err := toml.NewEncoder(&buf).Encode(c); err != nil {
return nil, err
}
var compressed []byte
compressed, err := zstd.CompressLevel(compressed, buf.Bytes(), 15)
if err != nil {
return nil, err
}
encoded := make([]byte, base64.StdEncoding.EncodedLen(len(compressed)))
base64.StdEncoding.Encode(encoded, compressed)
return encoded, nil
}