Skip to content
New issue

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

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

Already on GitHub? # to your account

*: export clients and related types #77

Merged
merged 1 commit into from
Aug 2, 2019
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 .agola/config.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ local task_build_go(version, arch) = {
{ type: 'run', command: 'golangci-lint run --deadline 5m' },
{ type: 'run', name: 'build docker/k8s drivers tests binary', command: 'CGO_ENABLED=0 go test -c ./internal/services/executor/driver -o ./bin/docker-tests' },
{ type: 'run', name: 'build integration tests binary', command: 'go test -tags "sqlite_unlock_notify" -c ./tests -o ./bin/integration-tests' },
{ type: 'run', name: 'run tests', command: 'SKIP_DOCKER_TESTS=1 SKIP_K8S_TESTS=1 go test -v -count 1 ./cmd/... ./internal/...' },
{ type: 'run', name: 'run tests', command: 'SKIP_DOCKER_TESTS=1 SKIP_K8S_TESTS=1 go test -v -count 1 $(go list ./... | grep -v /tests)' },
{ type: 'run', name: 'fetch gitea binary for integration tests', command: 'curl -L https://github.com/go-gitea/gitea/releases/download/v1.8.3/gitea-1.8.3-linux-amd64 -o ./bin/gitea && chmod +x ./bin/gitea' },
{ type: 'save_to_workspace', contents: [{ source_dir: './bin', dest_dir: '/bin/', paths: ['*'] }] },
],
Expand Down
7 changes: 4 additions & 3 deletions cmd/agola/cmd/directrunstart.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import (
"path"

gitsave "agola.io/agola/internal/git-save"
"agola.io/agola/internal/services/gateway/api"
"agola.io/agola/internal/util"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"

uuid "github.com/satori/go.uuid"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -62,7 +63,7 @@ func init() {
}

func directRunStart(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

user, _, err := gwclient.GetCurrentUser(context.TODO())
if err != nil {
Expand Down Expand Up @@ -102,7 +103,7 @@ func directRunStart(cmd *cobra.Command, args []string) error {
}

log.Infof("starting direct run")
req := &api.UserCreateRunRequest{
req := &gwapitypes.UserCreateRunRequest{
RepoUUID: repoUUID,
RepoPath: repoPath,
Branch: branch,
Expand Down
12 changes: 6 additions & 6 deletions cmd/agola/cmd/orgcreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package cmd
import (
"context"

cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"

"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
Expand Down Expand Up @@ -55,16 +55,16 @@ func init() {
}

func orgCreate(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

// TODO(sgotti) make this a custom pflag Value?
if !cstypes.IsValidVisibility(cstypes.Visibility(orgCreateOpts.visibility)) {
if !IsValidVisibility(orgCreateOpts.visibility) {
return errors.Errorf("invalid visibility %q", orgCreateOpts.visibility)
}

req := &api.CreateOrgRequest{
req := &gwapitypes.CreateOrgRequest{
Name: orgCreateOpts.name,
Visibility: cstypes.Visibility(orgCreateOpts.visibility),
Visibility: gwapitypes.Visibility(orgCreateOpts.visibility),
}

log.Infof("creating org")
Expand Down
4 changes: 2 additions & 2 deletions cmd/agola/cmd/orgdelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package cmd
import (
"context"

"agola.io/agola/internal/services/gateway/api"
gwclient "agola.io/agola/services/gateway/client"

"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
Expand Down Expand Up @@ -52,7 +52,7 @@ func init() {
}

func orgDelete(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

log.Infof("deleting organization %q", orgDeleteOpts.name)
if _, err := gwclient.DeleteOrg(context.TODO(), orgDeleteOpts.name); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions cmd/agola/cmd/orgmemberadd.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package cmd
import (
"context"

cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"

"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
Expand Down Expand Up @@ -60,10 +60,10 @@ func init() {
}

func orgMemberAdd(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

log.Infof("adding/updating member %q to organization %q with role %q", orgMemberAddOpts.username, orgMemberAddOpts.orgname, orgMemberAddOpts.role)
_, _, err := gwclient.AddOrgMember(context.TODO(), orgMemberAddOpts.orgname, orgMemberAddOpts.username, cstypes.MemberRole(orgMemberAddOpts.role))
_, _, err := gwclient.AddOrgMember(context.TODO(), orgMemberAddOpts.orgname, orgMemberAddOpts.username, gwapitypes.MemberRole(orgMemberAddOpts.role))
if err != nil {
return errors.Errorf("failed to add/update organization member: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/agola/cmd/orgmemberlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"encoding/json"
"os"

"agola.io/agola/internal/services/gateway/api"
gwclient "agola.io/agola/services/gateway/client"

"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
Expand Down Expand Up @@ -54,7 +54,7 @@ func init() {
}

func orgMemberList(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

orgMembers, _, err := gwclient.GetOrgMembers(context.TODO(), orgMemberListOpts.orgname)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/agola/cmd/orgmemberremove.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package cmd
import (
"context"

"agola.io/agola/internal/services/gateway/api"
gwclient "agola.io/agola/services/gateway/client"

"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
Expand Down Expand Up @@ -57,7 +57,7 @@ func init() {
}

func orgMemberRemove(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

log.Infof("removing member %q from organization %q", orgMemberRemoveOpts.username, orgMemberRemoveOpts.orgname)
_, err := gwclient.RemoveOrgMember(context.TODO(), orgMemberRemoveOpts.orgname, orgMemberRemoveOpts.username)
Expand Down
22 changes: 16 additions & 6 deletions cmd/agola/cmd/projectcreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package cmd
import (
"context"

cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"

"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
Expand Down Expand Up @@ -71,18 +71,28 @@ func init() {
cmdProject.AddCommand(cmdProjectCreate)
}

func IsValidVisibility(v string) bool {
switch gwapitypes.Visibility(v) {
case gwapitypes.VisibilityPublic:
case gwapitypes.VisibilityPrivate:
default:
return false
}
return true
}

func projectCreate(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

// TODO(sgotti) make this a custom pflag Value?
if !cstypes.IsValidVisibility(cstypes.Visibility(projectCreateOpts.visibility)) {
if !IsValidVisibility(projectCreateOpts.visibility) {
return errors.Errorf("invalid visibility %q", projectCreateOpts.visibility)
}

req := &api.CreateProjectRequest{
req := &gwapitypes.CreateProjectRequest{
Name: projectCreateOpts.name,
ParentRef: projectCreateOpts.parentPath,
Visibility: cstypes.Visibility(projectCreateOpts.visibility),
Visibility: gwapitypes.Visibility(projectCreateOpts.visibility),
RepoPath: projectCreateOpts.repoPath,
RemoteSourceName: projectCreateOpts.remoteSourceName,
SkipSSHHostKeyCheck: projectCreateOpts.skipSSHHostKeyCheck,
Expand Down
4 changes: 2 additions & 2 deletions cmd/agola/cmd/projectdelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package cmd
import (
"context"

"agola.io/agola/internal/services/gateway/api"
gwclient "agola.io/agola/services/gateway/client"

"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
Expand Down Expand Up @@ -52,7 +52,7 @@ func init() {
}

func projectDelete(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

log.Infof("deleting project")

Expand Down
14 changes: 7 additions & 7 deletions cmd/agola/cmd/projectgroupcreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package cmd
import (
"context"

cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"

"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
Expand Down Expand Up @@ -60,17 +60,17 @@ func init() {
}

func projectGroupCreate(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

// TODO(sgotti) make this a custom pflag Value?
if !cstypes.IsValidVisibility(cstypes.Visibility(projectCreateOpts.visibility)) {
return errors.Errorf("invalid visibility %q", projectCreateOpts.visibility)
if !IsValidVisibility(projectGroupCreateOpts.visibility) {
return errors.Errorf("invalid visibility %q", projectGroupCreateOpts.visibility)
}

req := &api.CreateProjectGroupRequest{
req := &gwapitypes.CreateProjectGroupRequest{
Name: projectGroupCreateOpts.name,
ParentRef: projectGroupCreateOpts.parentPath,
Visibility: cstypes.Visibility(projectCreateOpts.visibility),
Visibility: gwapitypes.Visibility(projectGroupCreateOpts.visibility),
}

log.Infof("creating project group")
Expand Down
8 changes: 5 additions & 3 deletions cmd/agola/cmd/projectlist.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import (
"context"
"fmt"

"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -50,14 +52,14 @@ func init() {
cmdProject.AddCommand(cmdProjectList)
}

func printProjects(projects []*api.ProjectResponse) {
func printProjects(projects []*gwapitypes.ProjectResponse) {
for _, project := range projects {
fmt.Printf("%s: Name: %s\n", project.ID, project.Name)
}
}

func projectList(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

projects, _, err := gwclient.GetProjectGroupProjects(context.TODO(), projectListOpts.parentPath)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cmd/agola/cmd/projectreconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package cmd
import (
"context"

"agola.io/agola/internal/services/gateway/api"
gwclient "agola.io/agola/services/gateway/client"

"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
Expand Down Expand Up @@ -52,7 +52,7 @@ func init() {
}

func projectReconfig(cmd *cobra.Command, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

log.Infof("reconfiguring remote project")
if _, err := gwclient.ReconfigProject(context.TODO(), projectReconfigOpts.name); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions cmd/agola/cmd/projectsecretcreate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"io/ioutil"
"os"

cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"

"github.com/ghodss/yaml"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -73,7 +73,7 @@ func init() {
}

func secretCreate(cmd *cobra.Command, ownertype string, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

// "github.com/ghodss/yaml" doesn't provide a streaming decoder
var data []byte
Expand All @@ -94,9 +94,9 @@ func secretCreate(cmd *cobra.Command, ownertype string, args []string) error {
if err := yaml.Unmarshal(data, &secretData); err != nil {
log.Fatalf("failed to unmarshal secret: %v", err)
}
req := &api.CreateSecretRequest{
req := &gwapitypes.CreateSecretRequest{
Name: secretCreateOpts.name,
Type: cstypes.SecretTypeInternal,
Type: gwapitypes.SecretTypeInternal,
Data: secretData,
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/agola/cmd/projectsecretdelete.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package cmd
import (
"context"

"agola.io/agola/internal/services/gateway/api"
gwclient "agola.io/agola/services/gateway/client"

"github.com/spf13/cobra"
errors "golang.org/x/xerrors"
Expand Down Expand Up @@ -57,7 +57,7 @@ func init() {
}

func secretDelete(cmd *cobra.Command, ownertype string, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

switch ownertype {
case "project":
Expand Down
10 changes: 5 additions & 5 deletions cmd/agola/cmd/projectsecretupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import (
"io/ioutil"
"os"

cstypes "agola.io/agola/internal/services/configstore/types"
"agola.io/agola/internal/services/gateway/api"
gwapitypes "agola.io/agola/services/gateway/api/types"
gwclient "agola.io/agola/services/gateway/client"

"github.com/ghodss/yaml"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -75,7 +75,7 @@ func init() {
}

func secretUpdate(cmd *cobra.Command, ownertype string, args []string) error {
gwclient := api.NewClient(gatewayURL, token)
gwclient := gwclient.NewClient(gatewayURL, token)

// "github.com/ghodss/yaml" doesn't provide a streaming decoder
var data []byte
Expand All @@ -96,9 +96,9 @@ func secretUpdate(cmd *cobra.Command, ownertype string, args []string) error {
if err := yaml.Unmarshal(data, &secretData); err != nil {
log.Fatalf("failed to unmarshal secret: %v", err)
}
req := &api.UpdateSecretRequest{
req := &gwapitypes.UpdateSecretRequest{
Name: secretUpdateOpts.name,
Type: cstypes.SecretTypeInternal,
Type: gwapitypes.SecretTypeInternal,
Data: secretData,
}

Expand Down
Loading