Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support gitea as a SCM provider #128

Merged
merged 6 commits into from
Jul 15, 2021
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
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ test:

.PHONY: codegen
codegen: $(GOBIN)/mockery
rm -f docs/commands/*
go generate ./...

.PHONY: pre-commit
Expand Down
3 changes: 2 additions & 1 deletion docs/Getting-Started.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export GIT_REPO=https://github.com/owner/name?ref=gitops_branch
```

#### Using a Specific git Provider
You can add the `--provider` flag to the `repo bootstrap` command, to enforce using a specific provider when creating a new repository. If the value is not supplied, the code will attempt to infer it from the clone URL.
You can add the `--provider` flag to the `repo bootstrap` command, to enforce using a specific provider when creating a new repository. If the value is not supplied, the code will attempt to infer it from the clone URL.
Autopilot currently support github and gitea as SCM providers.

All the following commands will use the variables you supplied in order to manage your GitOps repository.

Expand Down
2 changes: 0 additions & 2 deletions docs/Roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@

### Repo Upgrade and Uninstall
* Support a clear flow to [upgrade](https://github.com/argoproj-labs/argocd-autopilot/issues/45) Argo CD
* Support a clear flow to [uninstall](https://github.com/argoproj-labs/argocd-autopilot/issues/42) Argo CD

### App Upgrade and Delete
* Support a clear flow to [upgrade](https://github.com/argoproj-labs/argocd-autopilot/issues/44) an app
* Support a clear flow to delete an app

### Working with and Storing Secrets
* [Git token should also be maintained in a GitOps approach](https://github.com/argoproj-labs/argocd-autopilot/issues/25)
Expand Down
2 changes: 1 addition & 1 deletion docs/commands/argocd-autopilot_repo_bootstrap.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ argocd-autopilot repo bootstrap [flags]
--kubeconfig string Path to the kubeconfig file to use for CLI requests.
-n, --namespace string If present, the namespace scope for this CLI request
--namespaced If true, install a namespaced version of argo-cd (no need for cluster-role)
--provider string The git provider, one of: github
--provider string The git provider, one of: github|gitea
--repo string Repository URL [GIT_REPO]
--request-timeout string The length of time to wait before giving up on a single server request. Non-zero values should contain a corresponding time unit (e.g. 1s, 2m, 3h). A value of zero means don't timeout requests. (default "0")
```
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/argoproj-labs/argocd-autopilot
go 1.16

require (
code.gitea.io/sdk/gitea v0.14.1
github.com/argoproj-labs/applicationset v0.1.0
github.com/argoproj/argo-cd v1.8.7
github.com/argoproj/argo-cd/v2 v2.0.3
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ cloud.google.com/go/storage v1.5.0/go.mod h1:tpKbwo567HUNpVclU5sGELwQWBDZ8gh0Zeo
cloud.google.com/go/storage v1.6.0/go.mod h1:N7U0C8pVQ/+NIKOBQyamJIeKQKkZ+mxpohlUTyfDhBk=
cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RXyy7KQOVs=
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
code.gitea.io/sdk/gitea v0.14.1 h1:NaRluse+dAxVM5RmHC7Xktfas5a8WWmcnUBlJLhJycA=
code.gitea.io/sdk/gitea v0.14.1/go.mod h1:89WiyOX1KEcvjP66sRHdu0RafojGo60bT9UqW17VbWs=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20201218220906-28db891af037/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/Azure/azure-sdk-for-go v43.0.0+incompatible/go.mod h1:9XXNKU+eRnpl9moKnB4QOLf1HestfXbmab5FXxiDBjc=
Expand Down Expand Up @@ -489,6 +491,8 @@ github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerX
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.2.1 h1:zEfKbn2+PDgroKdiOzqiE8rsmLqU2uwi5PB5pBJ3TkI=
github.com/hashicorp/go-version v1.2.1/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
Expand Down
109 changes: 109 additions & 0 deletions pkg/git/gitea/mocks/client.go

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

1 change: 1 addition & 0 deletions pkg/git/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ var (

var supportedProviders = map[string]func(*ProviderOptions) (Provider, error){
"github": newGithub,
"gitea": newGitea,
}

// New creates a new git provider
Expand Down
68 changes: 68 additions & 0 deletions pkg/git/provider_gitea.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package git

import (
"context"
"fmt"

gt "code.gitea.io/sdk/gitea"
)

//go:generate mockery --name Client --output gitea/mocks --case snake

type (
Client interface {
CreateOrgRepo(org string, opt gt.CreateRepoOption) (*gt.Repository, *gt.Response, error)
CreateRepo(opt gt.CreateRepoOption) (*gt.Repository, *gt.Response, error)
GetMyUserInfo() (*gt.User, *gt.Response, error)
}

gitea struct {
client Client
}
)

func newGitea(opts *ProviderOptions) (Provider, error) {
c, err := gt.NewClient(opts.Host, gt.SetToken(opts.Auth.Password))
if err != nil {
return nil, err
}

g := &gitea{
client: c,
}

return g, nil
}

func (g *gitea) CreateRepository(ctx context.Context, opts *CreateRepoOptions) (string, error) {
authUser, res, err := g.client.GetMyUserInfo()
if err != nil {
if res.StatusCode == 401 {
return "", ErrAuthenticationFailed(err)
}

return "", err
}

createOpts := gt.CreateRepoOption{
Name: opts.Name,
Private: opts.Private,
}

var r *gt.Repository
if authUser.UserName != opts.Owner {
r, res, err = g.client.CreateOrgRepo(opts.Owner, createOpts)
} else {
r, res, err = g.client.CreateRepo(createOpts)
}

if err != nil {
if res.StatusCode == 404 {
return "", fmt.Errorf("owner %s not found: %w", opts.Owner, err)
}

return "", err
}

return r.CloneURL, nil
}
Loading