Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/dependabot/internal/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func readArguments(cmd *cobra.Command, flags *UpdateFlags) (*model.Input, error)
AllowedUpdates: allowed,
DependencyGroups: nil,
Dependencies: nil,
ExistingPullRequests: [][]model.ExistingPR{},
ExistingPullRequests: model.ExistingPullRequests{},
IgnoreConditions: []model.Condition{},
LockfileOnly: false,
RequirementsUpdateStrategy: nil,
Expand Down Expand Up @@ -308,7 +308,7 @@ func processInput(input *model.Input, flags *UpdateFlags) {
}}
}
if job.ExistingPullRequests == nil {
job.ExistingPullRequests = [][]model.ExistingPR{}
job.ExistingPullRequests = model.ExistingPullRequests{}
}
if job.IgnoreConditions == nil {
job.IgnoreConditions = []model.Condition{}
Expand Down
169 changes: 140 additions & 29 deletions internal/model/job.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package model

import "time"
import (
"encoding/json"
"fmt"
"time"
)

/*
Updating Models
Expand Down Expand Up @@ -28,33 +32,33 @@ 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 [][]ExistingPR `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"`
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 {
Expand All @@ -79,10 +83,117 @@ type Source struct {
}

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"`
PRNumber *int `json:"pr-number,omitempty" yaml:"pr-number,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 {
Expand Down
Loading
Loading