Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.
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
7 changes: 7 additions & 0 deletions apis/mpas/v1alpha1/repository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ type RepositorySpec struct {
//+optional
//+kubebuilder:validation:Pattern="^\\w+(\\.|:[0-9]).*$"
Domain string `json:"domain,omitempty"`
// Insecure should be defined if `domain` is not HTTPS.
//+optional
Insecure bool `json:"insecure,omitempty"`
//+optional
Maintainers []string `json:"maintainers,omitempty"`
//+optional
Expand Down Expand Up @@ -105,6 +108,10 @@ func (in Repository) GetRepositoryURL() string {
return fmt.Sprintf("%s:%s/%s", in.Spec.Domain, in.Spec.Owner, in.GetName())
}

if in.Spec.Insecure {
return fmt.Sprintf("http://%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())
}

Expand Down
3 changes: 3 additions & 0 deletions config/crd/bases/mpas.ocm.software_repositories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ spec:
- adopt
- fail
type: string
insecure:
description: Insecure should be defined if `domain` is not HTTPS.
type: boolean
interval:
type: string
isOrganization:
Expand Down
7 changes: 7 additions & 0 deletions docs/release_notes/v0.9.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Release 0.9.0

- feat: add insecure flag to force http on the domain (#73)
- fix: allowing domain to be added including a scheme (#72)
- Remove blackduck PR scans (#71)
- add blackduck scans (#70)
- New PR Template (#66)
36 changes: 24 additions & 12 deletions pkg/providers/gitea/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"encoding/base64"
"errors"
"fmt"
"net/url"

"code.gitea.io/sdk/gitea"
deliveryv1alpha1 "github.com/open-component-model/git-controller/apis/delivery/v1alpha1"
Expand All @@ -22,9 +23,8 @@ import (
)

const (
tokenKey = "password"
providerType = "gitea"
defaultDomain = "gitea.com"
tokenKey = "password"
providerType = "gitea"
)

// Client gitea.
Expand Down Expand Up @@ -65,9 +65,9 @@ func (c *Client) CreateRepository(ctx context.Context, obj mpasv1alpha1.Reposito
return fmt.Errorf("token '%s' not found in secret", tokenKey)
}

domain := defaultDomain
if obj.Spec.Domain != "" {
domain = obj.Spec.Domain
domain, err := c.getDomain(obj)
if err != nil {
return fmt.Errorf("failed to generate domain url: %w", err)
}

client, err := gitea.NewClient(domain, gitea.SetToken(string(token)))
Expand Down Expand Up @@ -167,9 +167,9 @@ func (c *Client) CreatePullRequest(ctx context.Context, branch string, sync deli
return -1, fmt.Errorf("token '%s' not found in secret", tokenKey)
}

domain := defaultDomain
if repository.Spec.Domain != "" {
domain = repository.Spec.Domain
domain, err := c.getDomain(repository)
if err != nil {
return -1, fmt.Errorf("failed to generate domain url: %w", err)
}

gclient, err := gitea.NewClient(domain, gitea.SetToken(string(token)))
Expand Down Expand Up @@ -237,9 +237,9 @@ func (c *Client) CreateBranchProtection(ctx context.Context, repository mpasv1al

logger.Info("got secret")

domain := defaultDomain
if repository.Spec.Domain != "" {
domain = repository.Spec.Domain
domain, err := c.getDomain(repository)
if err != nil {
return fmt.Errorf("failed to generate domain url: %w", err)
}

logger.Info("default domain set", "domain", domain)
Expand Down Expand Up @@ -267,3 +267,15 @@ func (c *Client) CreateBranchProtection(ctx context.Context, repository mpasv1al

return nil
}

func (c *Client) getDomain(obj mpasv1alpha1.Repository) (string, error) {
u, err := url.Parse(obj.GetRepositoryURL())
if err != nil {
return "", fmt.Errorf("failed to parse repository url: %w", err)
}

// construct the domain including the scheme and host but without the path
// gitea requires a host and a scheme
domain := fmt.Sprintf("%s://%s", u.Scheme, u.Host)
return domain, nil
}
2 changes: 1 addition & 1 deletion pkg/version/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package version

// ReleaseVersion is the version number in semver format "vX.Y.Z", prefixed with "v".
var ReleaseVersion = "v0.8.0"
var ReleaseVersion = "v0.9.0"

// ReleaseCandidate is the release candidate ID in format "rc.X", which will be appended to the release version.
var ReleaseCandidate = "rc.1"