From 6943c10dc9df74e16559b991129bb02c039e9fee Mon Sep 17 00:00:00 2001 From: Simone Gotti Date: Fri, 3 May 2019 09:55:37 +0200 Subject: [PATCH] types: add RemoteSourceID to Project In future we may support specifying a remote source for a project without a linked account and thus use a user provided token (saved in the project) or other ways to define a remote repo (like standard git repos over ssh). --- internal/services/gateway/command/project.go | 8 +++++++- internal/services/types/types.go | 6 ++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/services/gateway/command/project.go b/internal/services/gateway/command/project.go index 19d6b44..ec52dec 100644 --- a/internal/services/gateway/command/project.go +++ b/internal/services/gateway/command/project.go @@ -41,6 +41,12 @@ func (c *CommandHandler) CreateProject(ctx context.Context, req *CreateProjectRe if !util.ValidateName(req.Name) { return nil, util.NewErrBadRequest(errors.Errorf("invalid project name %q", req.Name)) } + if req.RemoteSourceName == "" { + return nil, util.NewErrBadRequest(errors.Errorf("empty remote source name")) + } + if req.RepoPath == "" { + return nil, util.NewErrBadRequest(errors.Errorf("empty remote repo path name")) + } user, resp, err := c.configstoreClient.GetUser(ctx, req.CurrentUserID) if err != nil { @@ -49,7 +55,6 @@ func (c *CommandHandler) CreateProject(ctx context.Context, req *CreateProjectRe rs, resp, err := c.configstoreClient.GetRemoteSourceByName(ctx, req.RemoteSourceName) if err != nil { - c.log.Errorf("err: %+v", err) return nil, ErrFromRemote(resp, errors.Wrapf(err, "failed to get remote source %q", req.RemoteSourceName)) } c.log.Infof("rs: %s", util.Dump(rs)) @@ -94,6 +99,7 @@ func (c *CommandHandler) CreateProject(ctx context.Context, req *CreateProjectRe ID: parentID, }, Visibility: req.Visibility, + RemoteSourceID: rs.ID, LinkedAccountID: la.ID, RepositoryID: repo.ID, RepositoryPath: req.RepoPath, diff --git a/internal/services/types/types.go b/internal/services/types/types.go index 47980a9..0e4962f 100644 --- a/internal/services/types/types.go +++ b/internal/services/types/types.go @@ -160,6 +160,10 @@ type Project struct { Visibility Visibility `json:"visibility,omitempty"` + // Remote Repository fields + RemoteSourceID string `json:"remote_source_id,omitempty"` + LinkedAccountID string `json:"linked_account_id,omitempty"` + // The remote repository id RepositoryID string `json:"repository_id,omitempty"` @@ -171,8 +175,6 @@ type Project struct { // do this but gitlab can and github has an hidden api to do this) RepositoryPath string `json:"repository_path,omitempty"` - LinkedAccountID string `json:"linked_account_id,omitempty"` - SSHPrivateKey string `json:"ssh_private_key,omitempty"` // PEM Encoded private key SkipSSHHostKeyCheck bool `json:"skip_ssh_host_key_check,omitempty"`