Skip to content

Commit

Permalink
Merge branch 'kaessert:main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
iul1an authored Jun 3, 2024
2 parents d312d4a + 936dc6d commit 0aa47cd
Show file tree
Hide file tree
Showing 10 changed files with 695 additions and 5 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ The project is in a prototyping phase but it's already functional and
implements follwing objects with partial functionality:

* Organization
* actions enabled repositories
* actions enabled repositories
* actions and dependabot secrets repository access
* description
* creation and deleteion not supported
* creation and deletion not supported
* Team
* visibility
* description
Expand Down
36 changes: 36 additions & 0 deletions apis/organizations/v1alpha1/organization_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,46 @@ type ActionEnabledRepo struct {
RepoSelector *xpv1.Selector `json:"repoSelector,omitempty"`
}

type SecretSelectedRepo struct {
// Name of the repository
// +crossplane:generate:reference:type=Repository
Repo string `json:"repo,omitempty"`

// RepoRef is a reference to the Repositories
// +optional
RepoRef *xpv1.Reference `json:"repoRef,omitempty"`

// RepoSelector selects a reference to a Repository
// +optional
RepoSelector *xpv1.Selector `json:"repoSelector,omitempty"`
}

type OrgSecret struct {
// Name of the GitHub secret
Name string `json:"name"`

// List of repositories that have access to the secret.
RepositoryAccessList []SecretSelectedRepo `json:"repositoryAccessList,omitempty"`
}

type SecretConfiguration struct {
// List of GitHub Actions secrets
// +optional
ActionsSecrets []OrgSecret `json:"actionsSecrets,omitempty"`

// List of Dependabot secrets
// +optional
DependabotSecrets []OrgSecret `json:"dependabotSecrets,omitempty"`
}

// OrganizationParameters are the configurable fields of a Organization.
type OrganizationParameters struct {
Description string `json:"description"`
Actions ActionsConfiguration `json:"actions,omitempty"`

// Configuration for Organization Secrets.
// +optional
Secrets *SecretConfiguration `json:"secrets,omitempty"`
}

// OrganizationObservation are the observable fields of a Organization.
Expand Down
81 changes: 81 additions & 0 deletions apis/organizations/v1alpha1/zz_generated.deepcopy.go

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

44 changes: 44 additions & 0 deletions apis/organizations/v1alpha1/zz_generated.resolvers.go

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

9 changes: 9 additions & 0 deletions examples/organizations/organization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,12 @@ spec:
deletionPolicy: "Orphan"
forProvider:
description: this is a sample organization
secrets:
actionsSecrets:
- name: foo-secret
repositoryAccessList:
- repo: my-awesome-repo
dependabotSecrets:
- name: dependabot-token
repositoryAccessList:
- repo: my-awesome-repo
11 changes: 11 additions & 0 deletions internal/clients/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

type Client struct {
Actions ActionsClient
Dependabot DependabotClient
Organizations OrganizationsClient
Users UsersClient
Teams TeamsClient
Expand All @@ -39,6 +40,15 @@ type ActionsClient interface {
ListEnabledReposInOrg(ctx context.Context, owner string, opts *github.ListOptions) (*github.ActionsEnabledOnOrgRepos, *github.Response, error)
AddEnabledReposInOrg(ctx context.Context, owner string, repositoryID int64) (*github.Response, error)
RemoveEnabledReposInOrg(ctx context.Context, owner string, repositoryID int64) (*github.Response, error)
GetOrgSecret(ctx context.Context, org, name string) (*github.Secret, *github.Response, error)
ListSelectedReposForOrgSecret(ctx context.Context, org, name string, opts *github.ListOptions) (*github.SelectedReposList, *github.Response, error)
SetSelectedReposForOrgSecret(ctx context.Context, org, name string, ids github.SelectedRepoIDs) (*github.Response, error)
}

type DependabotClient interface {
GetOrgSecret(ctx context.Context, org, name string) (*github.Secret, *github.Response, error)
ListSelectedReposForOrgSecret(ctx context.Context, org, name string, opts *github.ListOptions) (*github.SelectedReposList, *github.Response, error)
SetSelectedReposForOrgSecret(ctx context.Context, org, name string, ids github.DependabotSecretsSelectedRepoIDs) (*github.Response, error)
}

type OrganizationsClient interface {
Expand Down Expand Up @@ -123,6 +133,7 @@ func NewClient(creds string) (*Client, error) {

return &Client{
Actions: ghclient.Actions,
Dependabot: ghclient.Dependabot,
Organizations: ghclient.Organizations,
Users: ghclient.Users,
Teams: ghclient.Teams,
Expand Down
39 changes: 36 additions & 3 deletions internal/clients/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ import (
)

type MockActionsClient struct {
MockListEnabledReposInOrg func(ctx context.Context, owner string, opts *github.ListOptions) (*github.ActionsEnabledOnOrgRepos, *github.Response, error)
MockAddEnabledReposInOrg func(ctx context.Context, owner string, repositoryID int64) (*github.Response, error)
MockRemoveEnabledReposInOrg func(ctx context.Context, owner string, repositoryID int64) (*github.Response, error)
MockListEnabledReposInOrg func(ctx context.Context, owner string, opts *github.ListOptions) (*github.ActionsEnabledOnOrgRepos, *github.Response, error)
MockAddEnabledReposInOrg func(ctx context.Context, owner string, repositoryID int64) (*github.Response, error)
MockRemoveEnabledReposInOrg func(ctx context.Context, owner string, repositoryID int64) (*github.Response, error)
MockGetOrgSecret func(ctx context.Context, org, name string) (*github.Secret, *github.Response, error)
MockListSelectedReposForOrgSecret func(ctx context.Context, org, name string, opts *github.ListOptions) (*github.SelectedReposList, *github.Response, error)
MockSetSelectedReposForOrgSecret func(ctx context.Context, org, name string, ids github.SelectedRepoIDs) (*github.Response, error)
}

func (m *MockActionsClient) ListEnabledReposInOrg(ctx context.Context, owner string, opts *github.ListOptions) (*github.ActionsEnabledOnOrgRepos, *github.Response, error) {
Expand All @@ -25,6 +28,36 @@ func (m *MockActionsClient) RemoveEnabledReposInOrg(ctx context.Context, owner s
return m.MockRemoveEnabledReposInOrg(ctx, owner, repositoryID)
}

func (m *MockActionsClient) GetOrgSecret(ctx context.Context, org, name string) (*github.Secret, *github.Response, error) {
return m.MockGetOrgSecret(ctx, org, name)
}

func (m *MockActionsClient) ListSelectedReposForOrgSecret(ctx context.Context, org, name string, opts *github.ListOptions) (*github.SelectedReposList, *github.Response, error) {
return m.MockListSelectedReposForOrgSecret(ctx, org, name, opts)
}

func (m *MockActionsClient) SetSelectedReposForOrgSecret(ctx context.Context, org, name string, ids github.SelectedRepoIDs) (*github.Response, error) {
return m.MockSetSelectedReposForOrgSecret(ctx, org, name, ids)
}

type MockDependabotClient struct {
MockGetOrgSecret func(ctx context.Context, org, name string) (*github.Secret, *github.Response, error)
MockListSelectedReposForOrgSecret func(ctx context.Context, org, name string, opts *github.ListOptions) (*github.SelectedReposList, *github.Response, error)
MockSetSelectedReposForOrgSecret func(ctx context.Context, org, name string, ids github.DependabotSecretsSelectedRepoIDs) (*github.Response, error)
}

func (m *MockDependabotClient) GetOrgSecret(ctx context.Context, org, name string) (*github.Secret, *github.Response, error) {
return m.MockGetOrgSecret(ctx, org, name)
}

func (m *MockDependabotClient) ListSelectedReposForOrgSecret(ctx context.Context, org, name string, opts *github.ListOptions) (*github.SelectedReposList, *github.Response, error) {
return m.MockListSelectedReposForOrgSecret(ctx, org, name, opts)
}

func (m *MockDependabotClient) SetSelectedReposForOrgSecret(ctx context.Context, org, name string, ids github.DependabotSecretsSelectedRepoIDs) (*github.Response, error) {
return m.MockSetSelectedReposForOrgSecret(ctx, org, name, ids)
}

type MockOrganizationsClient struct {
MockGet func(ctx context.Context, org string) (*github.Organization, *github.Response, error)
MockEdit func(ctx context.Context, name string, org *github.Organization) (*github.Organization, *github.Response, error)
Expand Down
Loading

0 comments on commit 0aa47cd

Please sign in to comment.