-
Notifications
You must be signed in to change notification settings - Fork 69
Expand file tree
/
Copy pathjob.go
More file actions
269 lines (231 loc) · 12.1 KB
/
job.go
File metadata and controls
269 lines (231 loc) · 12.1 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package model
import (
"encoding/json"
"fmt"
"time"
)
/*
Updating Models
If you are adding a new attribute to any of the models, a good rule of thumb is to add it was `yaml:"my-attribute,omitempty"`
initially _before_ you make any changes to core.
That will allow the CLI and our smoke tests to work with version of core before and after the change. Once you've released
the change, consider revisiting to remove `omitempty`, but be aware you will need to update all smoke tests to expect the
new key in their results.
When removing an attribute, the opposite is true:
- make it `omitempty` if it isn't already
- update Core
- update the smoke tests
- finally, remove it from the CLI
Finally, if you need to add a key for experimental features, please ensure:
- it is omitempty
- it is not added to payloads in core if the experiment is disabled
This will avoid churn where the experimental key makes it into other, unrelated smoke-tests as they are updated for other
reasons.
*/
// Job is the data that is passed to the updater.
type Job struct {
Command string `json:"command" yaml:"command,omitempty"`
PackageManager string `json:"package-manager" yaml:"package-manager"`
AllowedUpdates []Allowed `json:"allowed-updates" yaml:"allowed-updates,omitempty"`
Debug bool `json:"debug" yaml:"debug,omitempty"`
DependencyGroups []Group `json:"dependency-groups" yaml:"dependency-groups,omitempty"`
Dependencies []string `json:"dependencies" yaml:"dependencies,omitempty"`
DependencyGroupToRefresh *string `json:"dependency-group-to-refresh" yaml:"dependency-group-to-refresh,omitempty"`
ExistingPullRequests ExistingPullRequests `json:"existing-pull-requests" yaml:"existing-pull-requests,omitempty"`
ExistingGroupPullRequests []ExistingGroupPR `json:"existing-group-pull-requests" yaml:"existing-group-pull-requests,omitempty"`
Experiments Experiment `json:"experiments" yaml:"experiments,omitempty"`
IgnoreConditions []Condition `json:"ignore-conditions" yaml:"ignore-conditions,omitempty"`
LockfileOnly bool `json:"lockfile-only" yaml:"lockfile-only,omitempty"`
RequirementsUpdateStrategy *string `json:"requirements-update-strategy" yaml:"requirements-update-strategy,omitempty"`
SecurityAdvisories []Advisory `json:"security-advisories" yaml:"security-advisories,omitempty"`
SecurityUpdatesOnly bool `json:"security-updates-only" yaml:"security-updates-only,omitempty"`
Source Source `json:"source" yaml:"source"`
UpdateSubdependencies bool `json:"update-subdependencies" yaml:"update-subdependencies,omitempty"`
UpdatingAPullRequest bool `json:"updating-a-pull-request" yaml:"updating-a-pull-request,omitempty"`
VendorDependencies bool `json:"vendor-dependencies" yaml:"vendor-dependencies,omitempty"`
RejectExternalCode bool `json:"reject-external-code" yaml:"reject-external-code,omitempty"`
RepoPrivate bool `json:"repo-private" yaml:"repo-private,omitempty"`
CommitMessageOptions *CommitOptions `json:"commit-message-options" yaml:"commit-message-options,omitempty"`
CredentialsMetadata []Credential `json:"credentials-metadata" yaml:"-"`
MaxUpdaterRunTime int `json:"max-updater-run-time" yaml:"max-updater-run-time,omitempty"`
UpdateCooldown *UpdateCooldown `json:"cooldown,omitempty" yaml:"cooldown,omitempty"`
ExcludePaths []string `json:"exclude-paths" yaml:"exclude-paths,omitempty"`
MultiEcosystemUpdate bool `json:"multi-ecosystem-update" yaml:"multi-ecosystem-update,omitempty"`
}
func (j *Job) UseCaseInsensitiveFileSystem() bool {
if experimentValue, isBoolean := j.Experiments["use_case_insensitive_filesystem"].(bool); isBoolean && experimentValue {
return true
}
return false
}
// Source is a reference to some source code
type Source struct {
Provider string `json:"provider" yaml:"provider,omitempty"`
Repo string `json:"repo" yaml:"repo,omitempty"`
Directory string `json:"directory,omitempty" yaml:"directory,omitempty"`
Directories []string `json:"directories,omitempty" yaml:"directories,omitempty"`
Branch string `json:"branch,omitempty" yaml:"branch,omitempty"`
Commit string `json:"commit,omitempty" yaml:"commit,omitempty"`
Hostname *string `json:"hostname" yaml:"hostname,omitempty"` // Must be provided if APIEndpoint is
APIEndpoint *string `json:"api-endpoint" yaml:"api-endpoint,omitempty"` // Must be provided if Hostname is
}
type ExistingPR struct {
DependencyName string `json:"dependency-name,omitempty" yaml:"dependency-name,omitempty"`
DependencyVersion string `json:"dependency-version,omitempty" yaml:"dependency-version,omitempty"`
Directory *string `json:"directory,omitempty" yaml:"directory,omitempty"`
PRNumber *int `json:"pr-number,omitempty" yaml:"pr-number,omitempty"`
Dependencies *[]ExistingPRDependency `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`
}
type ExistingPRDependency struct {
DependencyName string `json:"dependency-name" yaml:"dependency-name"`
DependencyVersion string `json:"dependency-version" yaml:"dependency-version"`
Directory *string `json:"directory,omitempty" yaml:"directory,omitempty"`
}
type ExistingPullRequests []ExistingPR
func (e *ExistingPullRequests) UnmarshalYAML(unmarshal func(interface{}) error) error {
// First try the new format (array of ExistingPR objects)
var newFormat []ExistingPR
if err := unmarshal(&newFormat); err == nil {
*e = newFormat
return nil
}
// Fallback: try old format (array of arrays of ExistingPR)
// Each inner array represents a separate PR
var oldFormat [][]ExistingPR
if err := unmarshal(&oldFormat); err == nil {
for _, prArray := range oldFormat {
// Each inner array is a separate PR entry
// For backward compatibility, we take each dependency from the inner array
// as a separate PR entry in the flattened list
for _, pr := range prArray {
*e = append(*e, pr)
}
}
return nil
}
return fmt.Errorf("ExistingPullRequests: unrecognized YAML format")
}
func (e *ExistingPullRequests) UnmarshalJSON(data []byte) error {
// First try the new format (array of ExistingPR objects)
var newFormat []ExistingPR
if err := json.Unmarshal(data, &newFormat); err == nil {
*e = newFormat
return nil
}
// Fallback: try old format (array of arrays of ExistingPR)
// Each inner array represents a separate PR
var oldFormat [][]ExistingPR
if err := json.Unmarshal(data, &oldFormat); err == nil {
for _, prArray := range oldFormat {
// Each inner array is a separate PR entry
// For backward compatibility, we take each dependency from the inner array
// as a separate PR entry in the flattened list
for _, pr := range prArray {
*e = append(*e, pr)
}
}
return nil
}
return fmt.Errorf("ExistingPullRequests: unrecognized JSON format")
}
func (e ExistingPullRequests) MarshalJSON() ([]byte, error) {
// Check if this is using the new grouped format (has pr-number or dependencies)
hasNewFormat := false
for _, pr := range e {
if pr.PRNumber != nil || pr.Dependencies != nil {
hasNewFormat = true
break
}
}
if hasNewFormat {
// Send new format as-is (array of ExistingPR objects)
return json.Marshal([]ExistingPR(e))
}
// For old flat format, wrap in arrays for backward compatibility
oldFormat := make([][]ExistingPR, 0, len(e))
for _, pr := range e {
oldFormat = append(oldFormat, []ExistingPR{pr})
}
return json.Marshal(oldFormat)
}
func (e ExistingPullRequests) MarshalYAML() (interface{}, error) {
// Check if this is using the new grouped format (has pr-number or dependencies)
hasNewFormat := false
for _, pr := range e {
if pr.PRNumber != nil || pr.Dependencies != nil {
hasNewFormat = true
break
}
}
if hasNewFormat {
// Send new format as-is (array of ExistingPR objects)
return []ExistingPR(e), nil
}
// For old flat format, wrap in arrays for backward compatibility
oldFormat := make([][]ExistingPR, 0, len(e))
for _, pr := range e {
oldFormat = append(oldFormat, []ExistingPR{pr})
}
return oldFormat, nil
}
type ExistingGroupPR struct {
DependencyGroupName string `json:"dependency-group-name" yaml:"dependency-group-name"`
Dependencies []ExistingPR `json:"dependencies" yaml:"dependencies"`
}
type Allowed struct {
DependencyType string `json:"dependency-type,omitempty" yaml:"dependency-type,omitempty"`
DependencyName string `json:"dependency-name,omitempty" yaml:"dependency-name,omitempty"`
UpdateType string `json:"update-type,omitempty" yaml:"update-type,omitempty"`
}
type Group struct {
GroupName string `json:"name,omitempty" yaml:"name,omitempty"`
AppliesTo *string `json:"applies-to,omitempty" yaml:"applies-to,omitempty"`
Rules map[string]any `json:"rules,omitempty" yaml:"rules,omitempty"`
}
type Condition struct {
DependencyName string `json:"dependency-name" yaml:"dependency-name"`
Source string `json:"source,omitempty" yaml:"source,omitempty"`
UpdateTypes []string `json:"update-types,omitempty" yaml:"update-types,omitempty"`
UpdatedAt *time.Time `json:"updated-at,omitempty" yaml:"updated-at,omitempty"`
VersionRequirement string `json:"version-requirement,omitempty" yaml:"version-requirement,omitempty"`
}
type Advisory struct {
DependencyName string `json:"dependency-name" yaml:"dependency-name"`
AffectedVersions []string `json:"affected-versions" yaml:"affected-versions"`
PatchedVersions []string `json:"patched-versions" yaml:"patched-versions"`
UnaffectedVersions []string `json:"unaffected-versions" yaml:"unaffected-versions"`
}
type Dependency struct {
Name string `json:"name"`
PreviousRequirements *[]Requirement `json:"previous-requirements,omitempty" yaml:"previous-requirements,omitempty"`
PreviousVersion string `json:"previous-version,omitempty" yaml:"previous-version,omitempty"`
Requirements []Requirement `json:"requirements"`
Version *string `json:"version" yaml:"version"`
Removed bool `json:"removed,omitempty" yaml:"removed,omitempty"`
Directory *string `json:"directory,omitempty" yaml:"directory,omitempty"`
}
type Requirement struct {
File string `json:"file" yaml:"file"`
Groups []any `json:"groups" yaml:"groups"`
Metadata *map[string]any `json:"metadata,omitempty" yaml:"metadata,omitempty"`
Requirement *string `json:"requirement" yaml:"requirement"`
Source *RequirementSource `json:"source" yaml:"source"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
PreviousVersion string `json:"previous-version,omitempty" yaml:"previous-version,omitempty"`
}
type RequirementSource map[string]any
type Experiment map[string]any
type CommitOptions struct {
Prefix string `json:"prefix,omitempty" yaml:"prefix,omitempty"`
PrefixDevelopment string `json:"prefix-development,omitempty" yaml:"prefix-development,omitempty"`
IncludeScope bool `json:"include-scope,omitempty" yaml:"include-scope,omitempty"`
}
type Credential map[string]any
type UpdateCooldown struct {
DefaultDays int `json:"default-days,omitempty" yaml:"default-days,omitempty"`
SemverMajorDays int `json:"semver-major-days,omitempty" yaml:"semver-major-days,omitempty"`
SemverMinorDays int `json:"semver-minor-days,omitempty" yaml:"semver-minor-days,omitempty"`
SemverPatchDays int `json:"semver-patch-days,omitempty" yaml:"semver-patch-days,omitempty"`
Include []string `json:"include,omitempty" yaml:"include,omitempty"`
Exclude []string `json:"exclude,omitempty" yaml:"exclude,omitempty"`
}