11package model
22
3- import "time"
3+ import (
4+ "encoding/json"
5+ "fmt"
6+ "time"
7+ )
48
59/*
610Updating Models
@@ -28,33 +32,33 @@ reasons.
2832
2933// Job is the data that is passed to the updater.
3034type Job struct {
31- Command string `json:"command" yaml:"command,omitempty"`
32- PackageManager string `json:"package-manager" yaml:"package-manager"`
33- AllowedUpdates []Allowed `json:"allowed-updates" yaml:"allowed-updates,omitempty"`
34- Debug bool `json:"debug" yaml:"debug,omitempty"`
35- DependencyGroups []Group `json:"dependency-groups" yaml:"dependency-groups,omitempty"`
36- Dependencies []string `json:"dependencies" yaml:"dependencies,omitempty"`
37- DependencyGroupToRefresh * string `json:"dependency-group-to-refresh" yaml:"dependency-group-to-refresh,omitempty"`
38- ExistingPullRequests [][] ExistingPR `json:"existing-pull-requests" yaml:"existing-pull-requests,omitempty"`
39- ExistingGroupPullRequests []ExistingGroupPR `json:"existing-group-pull-requests" yaml:"existing-group-pull-requests,omitempty"`
40- Experiments Experiment `json:"experiments" yaml:"experiments,omitempty"`
41- IgnoreConditions []Condition `json:"ignore-conditions" yaml:"ignore-conditions,omitempty"`
42- LockfileOnly bool `json:"lockfile-only" yaml:"lockfile-only,omitempty"`
43- RequirementsUpdateStrategy * string `json:"requirements-update-strategy" yaml:"requirements-update-strategy,omitempty"`
44- SecurityAdvisories []Advisory `json:"security-advisories" yaml:"security-advisories,omitempty"`
45- SecurityUpdatesOnly bool `json:"security-updates-only" yaml:"security-updates-only,omitempty"`
46- Source Source `json:"source" yaml:"source"`
47- UpdateSubdependencies bool `json:"update-subdependencies" yaml:"update-subdependencies,omitempty"`
48- UpdatingAPullRequest bool `json:"updating-a-pull-request" yaml:"updating-a-pull-request,omitempty"`
49- VendorDependencies bool `json:"vendor-dependencies" yaml:"vendor-dependencies,omitempty"`
50- RejectExternalCode bool `json:"reject-external-code" yaml:"reject-external-code,omitempty"`
51- RepoPrivate bool `json:"repo-private" yaml:"repo-private,omitempty"`
52- CommitMessageOptions * CommitOptions `json:"commit-message-options" yaml:"commit-message-options,omitempty"`
53- CredentialsMetadata []Credential `json:"credentials-metadata" yaml:"-"`
54- MaxUpdaterRunTime int `json:"max-updater-run-time" yaml:"max-updater-run-time,omitempty"`
55- UpdateCooldown * UpdateCooldown `json:"cooldown,omitempty" yaml:"cooldown,omitempty"`
56- ExcludePaths []string `json:"exclude-paths" yaml:"exclude-paths,omitempty"`
57- MultiEcosystemUpdate bool `json:"multi-ecosystem-update" yaml:"multi-ecosystem-update,omitempty"`
35+ Command string `json:"command" yaml:"command,omitempty"`
36+ PackageManager string `json:"package-manager" yaml:"package-manager"`
37+ AllowedUpdates []Allowed `json:"allowed-updates" yaml:"allowed-updates,omitempty"`
38+ Debug bool `json:"debug" yaml:"debug,omitempty"`
39+ DependencyGroups []Group `json:"dependency-groups" yaml:"dependency-groups,omitempty"`
40+ Dependencies []string `json:"dependencies" yaml:"dependencies,omitempty"`
41+ DependencyGroupToRefresh * string `json:"dependency-group-to-refresh" yaml:"dependency-group-to-refresh,omitempty"`
42+ ExistingPullRequests ExistingPullRequests `json:"existing-pull-requests" yaml:"existing-pull-requests,omitempty"`
43+ ExistingGroupPullRequests []ExistingGroupPR `json:"existing-group-pull-requests" yaml:"existing-group-pull-requests,omitempty"`
44+ Experiments Experiment `json:"experiments" yaml:"experiments,omitempty"`
45+ IgnoreConditions []Condition `json:"ignore-conditions" yaml:"ignore-conditions,omitempty"`
46+ LockfileOnly bool `json:"lockfile-only" yaml:"lockfile-only,omitempty"`
47+ RequirementsUpdateStrategy * string `json:"requirements-update-strategy" yaml:"requirements-update-strategy,omitempty"`
48+ SecurityAdvisories []Advisory `json:"security-advisories" yaml:"security-advisories,omitempty"`
49+ SecurityUpdatesOnly bool `json:"security-updates-only" yaml:"security-updates-only,omitempty"`
50+ Source Source `json:"source" yaml:"source"`
51+ UpdateSubdependencies bool `json:"update-subdependencies" yaml:"update-subdependencies,omitempty"`
52+ UpdatingAPullRequest bool `json:"updating-a-pull-request" yaml:"updating-a-pull-request,omitempty"`
53+ VendorDependencies bool `json:"vendor-dependencies" yaml:"vendor-dependencies,omitempty"`
54+ RejectExternalCode bool `json:"reject-external-code" yaml:"reject-external-code,omitempty"`
55+ RepoPrivate bool `json:"repo-private" yaml:"repo-private,omitempty"`
56+ CommitMessageOptions * CommitOptions `json:"commit-message-options" yaml:"commit-message-options,omitempty"`
57+ CredentialsMetadata []Credential `json:"credentials-metadata" yaml:"-"`
58+ MaxUpdaterRunTime int `json:"max-updater-run-time" yaml:"max-updater-run-time,omitempty"`
59+ UpdateCooldown * UpdateCooldown `json:"cooldown,omitempty" yaml:"cooldown,omitempty"`
60+ ExcludePaths []string `json:"exclude-paths" yaml:"exclude-paths,omitempty"`
61+ MultiEcosystemUpdate bool `json:"multi-ecosystem-update" yaml:"multi-ecosystem-update,omitempty"`
5862}
5963
6064func (j * Job ) UseCaseInsensitiveFileSystem () bool {
@@ -79,10 +83,117 @@ type Source struct {
7983}
8084
8185type ExistingPR struct {
86+ DependencyName string `json:"dependency-name,omitempty" yaml:"dependency-name,omitempty"`
87+ DependencyVersion string `json:"dependency-version,omitempty" yaml:"dependency-version,omitempty"`
88+ Directory * string `json:"directory,omitempty" yaml:"directory,omitempty"`
89+ PRNumber * int `json:"pr-number,omitempty" yaml:"pr-number,omitempty"`
90+ Dependencies * []ExistingPRDependency `json:"dependencies,omitempty" yaml:"dependencies,omitempty"`
91+ }
92+
93+ type ExistingPRDependency struct {
8294 DependencyName string `json:"dependency-name" yaml:"dependency-name"`
8395 DependencyVersion string `json:"dependency-version" yaml:"dependency-version"`
8496 Directory * string `json:"directory,omitempty" yaml:"directory,omitempty"`
85- PRNumber * int `json:"pr-number,omitempty" yaml:"pr-number,omitempty"`
97+ }
98+
99+ type ExistingPullRequests []ExistingPR
100+
101+ func (e * ExistingPullRequests ) UnmarshalYAML (unmarshal func (interface {}) error ) error {
102+ // First try the new format (array of ExistingPR objects)
103+ var newFormat []ExistingPR
104+ if err := unmarshal (& newFormat ); err == nil {
105+ * e = newFormat
106+ return nil
107+ }
108+
109+ // Fallback: try old format (array of arrays of ExistingPR)
110+ // Each inner array represents a separate PR
111+ var oldFormat [][]ExistingPR
112+ if err := unmarshal (& oldFormat ); err == nil {
113+ for _ , prArray := range oldFormat {
114+ // Each inner array is a separate PR entry
115+ // For backward compatibility, we take each dependency from the inner array
116+ // as a separate PR entry in the flattened list
117+ for _ , pr := range prArray {
118+ * e = append (* e , pr )
119+ }
120+ }
121+ return nil
122+ }
123+
124+ return fmt .Errorf ("ExistingPullRequests: unrecognized YAML format" )
125+ }
126+
127+ func (e * ExistingPullRequests ) UnmarshalJSON (data []byte ) error {
128+ // First try the new format (array of ExistingPR objects)
129+ var newFormat []ExistingPR
130+ if err := json .Unmarshal (data , & newFormat ); err == nil {
131+ * e = newFormat
132+ return nil
133+ }
134+
135+ // Fallback: try old format (array of arrays of ExistingPR)
136+ // Each inner array represents a separate PR
137+ var oldFormat [][]ExistingPR
138+ if err := json .Unmarshal (data , & oldFormat ); err == nil {
139+ for _ , prArray := range oldFormat {
140+ // Each inner array is a separate PR entry
141+ // For backward compatibility, we take each dependency from the inner array
142+ // as a separate PR entry in the flattened list
143+ for _ , pr := range prArray {
144+ * e = append (* e , pr )
145+ }
146+ }
147+ return nil
148+ }
149+
150+ return fmt .Errorf ("ExistingPullRequests: unrecognized JSON format" )
151+ }
152+
153+ func (e ExistingPullRequests ) MarshalJSON () ([]byte , error ) {
154+ // Check if this is using the new grouped format (has pr-number or dependencies)
155+ hasNewFormat := false
156+ for _ , pr := range e {
157+ if pr .PRNumber != nil || pr .Dependencies != nil {
158+ hasNewFormat = true
159+ break
160+ }
161+ }
162+
163+ if hasNewFormat {
164+ // Send new format as-is (array of ExistingPR objects)
165+ return json .Marshal ([]ExistingPR (e ))
166+ }
167+
168+ // For old flat format, wrap in arrays for backward compatibility
169+ oldFormat := make ([][]ExistingPR , 0 , len (e ))
170+ for _ , pr := range e {
171+ oldFormat = append (oldFormat , []ExistingPR {pr })
172+ }
173+ return json .Marshal (oldFormat )
174+ }
175+
176+ func (e ExistingPullRequests ) MarshalYAML () (interface {}, error ) {
177+ // Check if this is using the new grouped format (has pr-number or dependencies)
178+ hasNewFormat := false
179+ for _ , pr := range e {
180+ if pr .PRNumber != nil || pr .Dependencies != nil {
181+ hasNewFormat = true
182+ break
183+ }
184+ }
185+
186+ if hasNewFormat {
187+ // Send new format as-is (array of ExistingPR objects)
188+ return []ExistingPR (e ), nil
189+ }
190+
191+ // For old flat format, wrap in arrays for backward compatibility
192+ oldFormat := make ([][]ExistingPR , 0 , len (e ))
193+ for _ , pr := range e {
194+ oldFormat = append (oldFormat , []ExistingPR {pr })
195+ }
196+ return oldFormat , nil
86197}
87198
88199type ExistingGroupPR struct {
0 commit comments