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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/Interhyp/git-hubby

go 1.26.3
go 1.27.3

require (
github.com/PuerkitoBio/rehttp v1.4.0
Expand Down
3 changes: 1 addition & 2 deletions internal/controller/inline_presets_crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

githubv1alpha1 "github.com/Interhyp/git-hubby/api/v1alpha1"
)
Expand All @@ -18,7 +17,7 @@ var _ = Describe("Inline autolinks, webhooks and webhook ignores CRD validation"

newRepo := func(name string, mutate func(*githubv1alpha1.RepositorySpec)) *githubv1alpha1.Repository {
repo := &githubv1alpha1.Repository{
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace},
Name: name, Namespace: namespace,
Spec: githubv1alpha1.RepositorySpec{
Name: name,
OrganizationRef: githubv1alpha1.OrganizationRef{Name: "some-org"},
Expand Down
7 changes: 3 additions & 4 deletions internal/controller/inline_rulesets_crd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

githubv1alpha1 "github.com/Interhyp/git-hubby/api/v1alpha1"
)
Expand Down Expand Up @@ -35,7 +34,7 @@ var _ = Describe("Inline rulesets CRD validation", func() {

newOrg := func(name string, rulesets []githubv1alpha1.RulesetSpec) *githubv1alpha1.Organization {
return &githubv1alpha1.Organization{
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace},
Name: name, Namespace: namespace,
Spec: githubv1alpha1.OrganizationSpec{
Name: name,
Description: "test",
Expand All @@ -48,7 +47,7 @@ var _ = Describe("Inline rulesets CRD validation", func() {

newRepo := func(name string, rulesets []githubv1alpha1.RulesetSpec) *githubv1alpha1.Repository {
return &githubv1alpha1.Repository{
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace},
Name: name, Namespace: namespace,
Spec: githubv1alpha1.RepositorySpec{
Name: name,
OrganizationRef: githubv1alpha1.OrganizationRef{Name: "some-org"},
Expand Down Expand Up @@ -101,7 +100,7 @@ var _ = Describe("Inline rulesets CRD validation", func() {

Context("RulesetPreset extends", func() {
newPreset := func(name string, spec githubv1alpha1.RulesetSpec) *githubv1alpha1.RulesetPreset {
return &githubv1alpha1.RulesetPreset{ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace}, Spec: spec}
return &githubv1alpha1.RulesetPreset{Name: name, Namespace: namespace, Spec: spec}
}

It("accepts a preset that only sets extends and name", func() {
Expand Down
7 changes: 2 additions & 5 deletions internal/controller/organization_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"github.com/Interhyp/git-hubby/internal/reconciler/orgrec"
"github.com/Interhyp/git-hubby/internal/reconciler/reconcilerfactory"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/builder"
Expand Down Expand Up @@ -120,10 +119,8 @@ func (r *OrganizationCtl) findOrganizationsForCodeSecurityConfiguration(ctx cont
requests := make([]reconcile.Request, 0, len(orgList.Items))
for _, org := range orgList.Items {
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
Name: org.Name,
Namespace: org.Namespace,
},
Name: org.Name,
Namespace: org.Namespace,
})
}

Expand Down
19 changes: 6 additions & 13 deletions internal/controller/repository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/Interhyp/git-hubby/internal/reconciler/reconcilerfactory"
"github.com/Interhyp/git-hubby/internal/reconciler/reporec"
"github.com/google/go-github/v93/github"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/util/workqueue"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sigs.k8s.io/controller-runtime/pkg/handler"
Expand Down Expand Up @@ -195,10 +194,8 @@ func (r *RepositoryCtl) findRepositoriesForWebhookPreset(ctx context.Context, ob
requests := make([]reconcile.Request, 0, len(repoList.Items))
for _, repo := range repoList.Items {
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
Name: repo.Name,
Namespace: repo.Namespace,
},
Name: repo.Name,
Namespace: repo.Namespace,
})
}

Expand All @@ -217,10 +214,8 @@ func (r *RepositoryCtl) findRepositoriesForWebhookIgnorePreset(ctx context.Conte
requests := make([]reconcile.Request, 0, len(repoList.Items))
for _, repo := range repoList.Items {
requests = append(requests, reconcile.Request{
NamespacedName: client.ObjectKey{
Name: repo.Name,
Namespace: repo.Namespace,
},
Name: repo.Name,
Namespace: repo.Namespace,
})
}

Expand All @@ -239,10 +234,8 @@ func (r *RepositoryCtl) findRepositoriesForAutolinksPreset(ctx context.Context,
requests := make([]reconcile.Request, 0, len(repoList.Items))
for _, repo := range repoList.Items {
requests = append(requests, reconcile.Request{
NamespacedName: types.NamespacedName{
Name: repo.Name,
Namespace: repo.Namespace,
},
Name: repo.Name,
Namespace: repo.Namespace,
})
}

Expand Down
20 changes: 9 additions & 11 deletions internal/controller/rulesetpreset_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"
Expand All @@ -27,8 +25,8 @@ var _ = Describe("RulesetPreset watch mapping", func() {

preset := func(name, extends string) *githubv1alpha1.RulesetPreset {
return &githubv1alpha1.RulesetPreset{
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace},
Spec: githubv1alpha1.RulesetSpec{Name: name, Extends: extends},
Name: name, Namespace: namespace,
Spec: githubv1alpha1.RulesetSpec{Name: name, Extends: extends},
}
}
refs := func(names ...string) []corev1.LocalObjectReference {
Expand All @@ -40,12 +38,12 @@ var _ = Describe("RulesetPreset watch mapping", func() {
}
repo := func(name string, presets []corev1.LocalObjectReference, inline ...githubv1alpha1.RulesetSpec) *githubv1alpha1.Repository {
return &githubv1alpha1.Repository{
ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: namespace},
Spec: githubv1alpha1.RepositorySpec{RulesetPresetList: presets, Rulesets: inline},
Name: name, Namespace: namespace,
Spec: githubv1alpha1.RepositorySpec{RulesetPresetList: presets, Rulesets: inline},
}
}
request := func(name string) reconcile.Request {
return reconcile.Request{NamespacedName: types.NamespacedName{Name: name, Namespace: namespace}}
return reconcile.Request{Name: name, Namespace: namespace}
}

BeforeEach(func() {
Expand All @@ -59,8 +57,8 @@ var _ = Describe("RulesetPreset watch mapping", func() {
preset("cycle-a", "cycle-b"),
preset("cycle-b", "cycle-a"),
&githubv1alpha1.RulesetPreset{
ObjectMeta: metav1.ObjectMeta{Name: "middle-other-ns", Namespace: "other"},
Spec: githubv1alpha1.RulesetSpec{Name: "x", Extends: "base"},
Name: "middle-other-ns", Namespace: "other",
Spec: githubv1alpha1.RulesetSpec{Name: "x", Extends: "base"},
},
}
})
Expand Down Expand Up @@ -107,8 +105,8 @@ var _ = Describe("RulesetPreset watch mapping", func() {
repo("inline-extends-middle", nil, githubv1alpha1.RulesetSpec{Name: "i", Extends: "middle"}),
repo("uses-unrelated", refs("unrelated")),
&githubv1alpha1.Organization{
ObjectMeta: metav1.ObjectMeta{Name: "org", Namespace: namespace},
Spec: githubv1alpha1.OrganizationSpec{RulesetPresetList: refs("leaf-b")},
Name: "org", Namespace: namespace,
Spec: githubv1alpha1.OrganizationSpec{RulesetPresetList: refs("leaf-b")},
},
)
})
Expand Down
51 changes: 15 additions & 36 deletions internal/controller/test_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/managedfields"
"k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

Expand Down Expand Up @@ -83,18 +82,14 @@ func CreateMockGitHubRepository() *ghclientmock.MockGitHubClientWrapper {
func (te *TestEnvironment) SetupTeamTest(_ *testing.T, namespace, teamName string, teamSlug *string, organizationRefs []githubv1alpha1.OrganizationRef) *githubv1alpha1.Team {
// Create namespace first
ns := &corev1.Namespace{
ObjectMeta: ctrl.ObjectMeta{
Name: namespace,
},
Name: namespace,
}
_ = te.Client.Create(te.Context, ns) // Ignore error if namespace already exists

// Create the Team
team := &githubv1alpha1.Team{
ObjectMeta: ctrl.ObjectMeta{
Name: teamName,
Namespace: namespace,
},
Name: teamName,
Namespace: namespace,
Spec: githubv1alpha1.TeamSpec{
Name: teamName,
OrganizationRefs: organizationRefs,
Expand All @@ -112,18 +107,14 @@ func (te *TestEnvironment) SetupTeamTest(_ *testing.T, namespace, teamName strin
func (te *TestEnvironment) SetupTeamWithMembersTest(_ *testing.T, namespace, teamName, orgName string) *githubv1alpha1.Team {
// Create namespace first
ns := &corev1.Namespace{
ObjectMeta: ctrl.ObjectMeta{
Name: namespace,
},
Name: namespace,
}
_ = te.Client.Create(te.Context, ns) // Ignore error if namespace already exists

// Create the Team
team := &githubv1alpha1.Team{
ObjectMeta: ctrl.ObjectMeta{
Name: teamName,
Namespace: namespace,
},
Name: teamName,
Namespace: namespace,
Spec: githubv1alpha1.TeamSpec{
Name: teamName,
OrganizationRefs: []githubv1alpha1.OrganizationRef{
Expand All @@ -144,18 +135,14 @@ func (te *TestEnvironment) SetupTeamWithMembersTest(_ *testing.T, namespace, tea
func (te *TestEnvironment) SetupOrganizationTest(_ *testing.T, namespace, orgName string) *githubv1alpha1.Organization {
// Create namespace first
ns := &corev1.Namespace{
ObjectMeta: ctrl.ObjectMeta{
Name: namespace,
},
Name: namespace,
}
_ = te.Client.Create(te.Context, ns) // Ignore error if namespace already exists

// Create the Organization
org := &githubv1alpha1.Organization{
ObjectMeta: ctrl.ObjectMeta{
Name: orgName,
Namespace: namespace,
},
Name: orgName,
Namespace: namespace,
Spec: githubv1alpha1.OrganizationSpec{
Name: orgName,
Description: "Test organization for unit tests",
Expand All @@ -174,18 +161,14 @@ func (te *TestEnvironment) SetupOrganizationTest(_ *testing.T, namespace, orgNam
func (te *TestEnvironment) SetupRepositoryTest(_ *testing.T, namespace, repoName, orgName string) *githubv1alpha1.Repository {
// Create namespace first
ns := &corev1.Namespace{
ObjectMeta: ctrl.ObjectMeta{
Name: namespace,
},
Name: namespace,
}
_ = te.Client.Create(te.Context, ns) // Ignore error if namespace already exists

// Create the repository
repo := &githubv1alpha1.Repository{
ObjectMeta: ctrl.ObjectMeta{
Name: repoName,
Namespace: namespace,
},
Name: repoName,
Namespace: namespace,
Spec: githubv1alpha1.RepositorySpec{
Name: repoName,
OrganizationRef: githubv1alpha1.OrganizationRef{
Expand Down Expand Up @@ -218,9 +201,7 @@ func (te *TestEnvironment) SetupRepositoryTest(_ *testing.T, namespace, repoName
// CreateTestNamespace creates a namespace for testing
func (te *TestEnvironment) CreateTestNamespace(namespaceName string) {
namespace := &corev1.Namespace{
ObjectMeta: ctrl.ObjectMeta{
Name: namespaceName,
},
Name: namespaceName,
}

_ = te.Client.Create(te.Context, namespace) // Ignore error if namespace already exists
Expand All @@ -236,10 +217,8 @@ func (te *TestEnvironment) CleanupTestResources(resources ...client.Object) {
// CreateSecret creates a test GitHub App credentials secret
func (te *TestEnvironment) CreateSecret(namespace, secretName string) {
secret := &corev1.Secret{
ObjectMeta: ctrl.ObjectMeta{
Name: secretName,
Namespace: namespace,
},
Name: secretName,
Namespace: namespace,
Data: map[string][]byte{
"app-id": []byte("12345"),
"app-installation-id": []byte("67890"),
Expand Down
Loading
Loading