Skip to content

Commit

Permalink
RELTEC-12316: add required conditions in repository configuration for…
Browse files Browse the repository at this point in the history
… patch repository
  • Loading branch information
KRaffael committed Dec 9, 2024
1 parent 844e03e commit 4b341d6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 2 additions & 0 deletions api/generated_model_repository_configuration_patch_dto.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions api/openapi-v3-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2187,6 +2187,14 @@ components:
- ORGANIZATION
- ENTERPRISE
example: NOT_ACCESSIBLE
requireConditions:
description: Configuration of conditional builds as map of structs (key name e.g. some-key) of target references.
type: object
examples:
- some-key:
refMatcher: main
additionalProperties:
$ref: '#/components/schemas/ConditionReferenceDto'
MergeStrategy:
type: object
properties:
Expand Down
19 changes: 16 additions & 3 deletions internal/service/repositories/repositories.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,10 +458,10 @@ func patchConfiguration(patch *openapi.RepositoryConfigurationPatchDto, original
Watchers: patchStringSlice(patch.Watchers, original.Watchers),
Archived: patchPtr[bool](patch.Archived, original.Archived),
ActionsAccess: patchStringPtr(patch.ActionsAccess, original.ActionsAccess),
RequireConditions: patchRequireConditions(patch.RequireConditions, original.RequireConditions),
// fields not allowed for patching carry over from original
RequireIssue: original.RequireIssue,
RequireConditions: original.RequireConditions,
RefProtections: original.RefProtections,
RequireIssue: original.RequireIssue,
RefProtections: original.RefProtections,
}
} else {
return original
Expand Down Expand Up @@ -549,6 +549,19 @@ func patchAccessKeys(patch []openapi.RepositoryConfigurationAccessKeyDto, origin
}
}

func patchRequireConditions(patch map[string]openapi.ConditionReferenceDto, original map[string]openapi.ConditionReferenceDto) map[string]openapi.ConditionReferenceDto {
if patch != nil {
if len(patch) == 0 {
// remove
return nil
} else {
return patch
}
} else {
return original
}
}

func patchStringSlice(patch []string, original []string) []string {
if patch != nil {
if len(patch) == 0 {
Expand Down
3 changes: 1 addition & 2 deletions test/acceptance/util_dtos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ func tstRepositoryPatchWithIgnoredConfigurationFields() interface{} {
}{
Mainline: ptr("main"),
Configuration: &openapi.RepositoryConfigurationDto{
RequireIssue: ptr(true),
RequireConditions: make(map[string]openapi.ConditionReferenceDto),
RequireIssue: ptr(true),
RefProtections: &openapi.RefProtections{
Branches: &openapi.RefProtectionsBranches{
RequirePR: []openapi.ProtectedRef{
Expand Down

0 comments on commit 4b341d6

Please sign in to comment.