From f1187156e7d91b262e083f0fe528a2b236bf18fd Mon Sep 17 00:00:00 2001 From: Gergely Brautigam <182850+Skarlso@users.noreply.github.com> Date: Thu, 19 Oct 2023 13:36:55 +0200 Subject: [PATCH] fix: allowing domain to be added including a scheme --- apis/mpas/v1alpha1/repository_types.go | 5 ++++- config/crd/bases/mpas.ocm.software_repositories.yaml | 3 +++ pkg/providers/github/github.go | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apis/mpas/v1alpha1/repository_types.go b/apis/mpas/v1alpha1/repository_types.go index 398b094..a88d8c4 100644 --- a/apis/mpas/v1alpha1/repository_types.go +++ b/apis/mpas/v1alpha1/repository_types.go @@ -48,7 +48,10 @@ type RepositorySpec struct { Visibility string `json:"visibility,omitempty"` //+kubebuilder:default:=true IsOrganization bool `json:"isOrganization"` + // Domain specifies an optional domain address to be used instead of the defaults like github.com. + // Must NOT contain the scheme. //+optional + //+kubebuilder:validation:Pattern="^\\w+(\\.|:[0-9]).*$" Domain string `json:"domain,omitempty"` //+optional Maintainers []string `json:"maintainers,omitempty"` @@ -102,7 +105,7 @@ func (in Repository) GetRepositoryURL() string { return fmt.Sprintf("%s:%s/%s", in.Spec.Domain, in.Spec.Owner, in.GetName()) } - return fmt.Sprintf("%s/%s/%s", in.Spec.Domain, in.Spec.Owner, in.GetName()) + return fmt.Sprintf("https://%s/%s/%s", in.Spec.Domain, in.Spec.Owner, in.GetName()) } domain := "" diff --git a/config/crd/bases/mpas.ocm.software_repositories.yaml b/config/crd/bases/mpas.ocm.software_repositories.yaml index 84e4917..4d8447b 100644 --- a/config/crd/bases/mpas.ocm.software_repositories.yaml +++ b/config/crd/bases/mpas.ocm.software_repositories.yaml @@ -71,6 +71,9 @@ spec: default: main type: string domain: + description: Domain specifies an optional domain address to be used + instead of the defaults like github.com. Must NOT contain the scheme. + pattern: ^\w+(\.|:[0-9]).*$ type: string existingRepositoryPolicy: default: adopt diff --git a/pkg/providers/github/github.go b/pkg/providers/github/github.go index e36069f..6ee276a 100644 --- a/pkg/providers/github/github.go +++ b/pkg/providers/github/github.go @@ -88,9 +88,9 @@ func (c *Client) CreateBranchProtection(ctx context.Context, obj mpasv1alpha1.Re if err != nil { return fmt.Errorf("failed to retrieve token: %w", err) } + ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: string(token)}) tc := oauth2.NewClient(context.Background(), ts) - g := ggithub.NewClient(tc) if _, _, err := g.Repositories.UpdateBranchProtection(ctx, obj.Spec.Owner, obj.Name, obj.Spec.DefaultBranch, &ggithub.ProtectionRequest{