-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.go
More file actions
103 lines (83 loc) · 2.68 KB
/
command.go
File metadata and controls
103 lines (83 loc) · 2.68 KB
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
96
97
98
99
100
101
102
103
package cpgo
import (
"fmt"
"net/url"
"strings"
)
const (
defaultProfileSeconds = 30
defaultHeadBranch = "cpgo"
defaultManagedByMarker = "<!-- managed-by:cpgo -->"
defaultPRTitle = "perf(pgo): refresh pgo profile"
defaultPRBody = "Automated PGO profile refresh."
defaultCommitMessage = "perf(pgo): refresh pgo profile"
)
// RunRequest captures one complete cpgo refresh operation.
type RunRequest struct {
Profile ProfileSettings
Repository RepositorySettings
PullRequest PullRequestSettings
Commit CommitSettings
}
// ProfileSettings describes where and how to collect the CPU profile.
type ProfileSettings struct {
URL *url.URL
Seconds int
Headers map[string]string
}
// RepositorySettings identifies the target repository and branch strategy.
type RepositorySettings struct {
Owner string
Name string
PGOPath string
BaseBranch string
HeadBranch string
}
// PullRequestSettings controls the automation PR identity and metadata.
type PullRequestSettings struct {
Title string
Body string
ManagedByMarker string
}
// CommitSettings defines commit metadata for profile updates.
type CommitSettings struct {
Message string
}
// normalized validates required fields and applies cpgo defaults.
func (req RunRequest) normalized() (RunRequest, error) {
normalized := req
if normalized.Profile.URL == nil {
return RunRequest{}, fmt.Errorf("profile url is required")
}
if normalized.Profile.URL.Scheme == "" || normalized.Profile.URL.Host == "" {
return RunRequest{}, fmt.Errorf("profile url must include scheme and host")
}
if normalized.Profile.Seconds <= 0 {
normalized.Profile.Seconds = defaultProfileSeconds
}
if strings.TrimSpace(normalized.Repository.Owner) == "" {
return RunRequest{}, fmt.Errorf("repository owner is required")
}
if strings.TrimSpace(normalized.Repository.Name) == "" {
return RunRequest{}, fmt.Errorf("repository name is required")
}
if strings.TrimSpace(normalized.Repository.PGOPath) == "" {
return RunRequest{}, fmt.Errorf("repository pgo path is required")
}
if strings.TrimSpace(normalized.Repository.HeadBranch) == "" {
normalized.Repository.HeadBranch = defaultHeadBranch
}
if strings.TrimSpace(normalized.PullRequest.ManagedByMarker) == "" {
normalized.PullRequest.ManagedByMarker = defaultManagedByMarker
}
if strings.TrimSpace(normalized.PullRequest.Title) == "" {
normalized.PullRequest.Title = defaultPRTitle
}
if strings.TrimSpace(normalized.PullRequest.Body) == "" {
normalized.PullRequest.Body = defaultPRBody
}
if strings.TrimSpace(normalized.Commit.Message) == "" {
normalized.Commit.Message = defaultCommitMessage
}
return normalized, nil
}