Skip to content

Commit

Permalink
fix: add emailsdisabled for backwards compatibility
Browse files Browse the repository at this point in the history
Signed-off-by: Dario Zachow <[email protected]>
  • Loading branch information
dariozachow committed Aug 21, 2024
1 parent 00cdc13 commit 7f67a17
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
6 changes: 5 additions & 1 deletion apis/groups/v1alpha1/group_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ type GroupParameters struct {
// +optional
SubGroupCreationLevel *SubGroupCreationLevelValue `json:"subgroupCreationLevel,omitempty"`

// Disable email notifications.
// Disable email notifications. Deprecated, use emailsEnabled instead.
// +optional
EmailsDisabled *bool `json:"emailsDisabled,omitempty"`

// Enable email notifications.
// +optional
EmailsEnabled *bool `json:"emailsEnabled,omitempty"`

Expand Down
5 changes: 5 additions & 0 deletions apis/groups/v1alpha1/zz_generated.deepcopy.go

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

6 changes: 5 additions & 1 deletion package/crds/groups.gitlab.crossplane.io_groups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ spec:
description:
description: The group’s description.
type: string
emailsDisabled:
description: Disable email notifications. Deprecated, use emailsEnabled
instead.
type: boolean
emailsEnabled:
description: Disable email notifications.
description: Enable email notifications.
type: boolean
extraSharedRunnersMinutesLimit:
description: Extra pipeline minutes quota for this group (purchased
Expand Down
11 changes: 11 additions & 0 deletions pkg/controller/groups/groups/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ func (e *external) Observe(ctx context.Context, mg resource.Managed) (managed.Ex
return managed.ExternalObservation{}, errors.New(errIDNotInt)
}

cr.Spec.ForProvider.EmailsEnabled = lateInitializeEmailsEnabled(cr.Spec.ForProvider.EmailsEnabled, cr.Spec.ForProvider.EmailsDisabled)

grp, res, err := e.client.GetGroup(groupID, nil)
if err != nil {
if clients.IsResponseNotFound(res) {
Expand Down Expand Up @@ -412,6 +414,15 @@ func lateInitializeSubGroupCreationLevelValue(in *v1alpha1.SubGroupCreationLevel
return in
}

func lateInitializeEmailsEnabled(in *bool, from *bool) *bool {
if in == nil && from != nil {
value := !(*from)
return &value
}

return in
}

// lateInitializeProjectCreationLevelValue returns in if it's non-nil, otherwise returns from
// which is the backup for the cases in is nil.
func lateInitializeProjectCreationLevelValue(in *v1alpha1.ProjectCreationLevelValue, from gitlab.ProjectCreationLevelValue) *v1alpha1.ProjectCreationLevelValue {
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/groups/groups/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func TestObserve(t *testing.T) {
Description: description,
Visibility: gitlabVisibilityNew,
ProjectCreationLevel: *gitlabProjectCreationLevelNew,
SubGroupCreationLevel: *gitlabSubGroupCreationLevelNew,
SubGroupCreationLevel: gitlab.SubGroupCreationLevelValue(*gitlabSubGroupCreationLevelNew),
MembershipLock: false,
ShareWithGroupLock: false,
RequireTwoFactorAuth: false,
Expand Down Expand Up @@ -449,7 +449,7 @@ func TestObserve(t *testing.T) {
"Description": "description v2",
"MembershipLock": true,
"ProjectCreationLevel": *gitlabProjectCreationLevelNew,
"SubGroupCreationLevel": *gitlabSubGroupCreationLevelNew,
"SubGroupCreationLevel": gitlab.SubGroupCreationLevelValue(*gitlabSubGroupCreationLevelNew),
"Visibility": gitlabVisibilityNew,
"ShareWithGroupLock": true,
"RequireTwoFactorAuth": true,
Expand Down

0 comments on commit 7f67a17

Please sign in to comment.